forked from loafle/openapi-generator-original
[Go] replace go generator with go-experimental generator (#7337)
* replace go with go-experimental * update samples * extends with abstract go class * rearrange * remove deprecated * minor fix * remove go deprecated samples * update pom, clean up samples * mark generator as deprecated
This commit is contained in:
@@ -11,16 +11,16 @@ import (
|
||||
|
||||
func TestCreateUser(t *testing.T) {
|
||||
newUser := sw.User{
|
||||
Id: 1000,
|
||||
FirstName: "gopher",
|
||||
LastName: "lang",
|
||||
Username: "gopher",
|
||||
Password: "lang",
|
||||
Email: "lang@test.com",
|
||||
Phone: "5101112222",
|
||||
UserStatus: 1}
|
||||
Id: sw.PtrInt64(1000),
|
||||
FirstName: sw.PtrString("gopher"),
|
||||
LastName: sw.PtrString("lang"),
|
||||
Username: sw.PtrString("gopher"),
|
||||
Password: sw.PtrString("lang"),
|
||||
Email: sw.PtrString("lang@test.com"),
|
||||
Phone: sw.PtrString("5101112222"),
|
||||
UserStatus: sw.PtrInt32(1)}
|
||||
|
||||
apiResponse, err := client.UserApi.CreateUser(context.Background(), newUser)
|
||||
apiResponse, err := client.UserApi.CreateUser(context.Background()).Body(newUser).Execute()
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error while adding user: %v", err)
|
||||
@@ -34,44 +34,43 @@ func TestCreateUser(t *testing.T) {
|
||||
func TestCreateUsersWithArrayInput(t *testing.T) {
|
||||
newUsers := []sw.User{
|
||||
sw.User{
|
||||
Id: int64(1001),
|
||||
FirstName: "gopher1",
|
||||
LastName: "lang1",
|
||||
Username: "gopher1",
|
||||
Password: "lang1",
|
||||
Email: "lang1@test.com",
|
||||
Phone: "5101112222",
|
||||
UserStatus: int32(1),
|
||||
Id: sw.PtrInt64(1001),
|
||||
FirstName: sw.PtrString("gopher1"),
|
||||
LastName: sw.PtrString("lang1"),
|
||||
Username: sw.PtrString("gopher1"),
|
||||
Password: sw.PtrString("lang1"),
|
||||
Email: sw.PtrString("lang1@test.com"),
|
||||
Phone: sw.PtrString("5101112222"),
|
||||
UserStatus: sw.PtrInt32(1),
|
||||
},
|
||||
sw.User{
|
||||
Id: int64(1002),
|
||||
FirstName: "gopher2",
|
||||
LastName: "lang2",
|
||||
Username: "gopher2",
|
||||
Password: "lang2",
|
||||
Email: "lang2@test.com",
|
||||
Phone: "5101112222",
|
||||
UserStatus: int32(1),
|
||||
Id: sw.PtrInt64(1002),
|
||||
FirstName: sw.PtrString("gopher2"),
|
||||
LastName: sw.PtrString("lang2"),
|
||||
Username: sw.PtrString("gopher2"),
|
||||
Password: sw.PtrString("lang2"),
|
||||
Email: sw.PtrString("lang2@test.com"),
|
||||
Phone: sw.PtrString("5101112222"),
|
||||
UserStatus: sw.PtrInt32(1),
|
||||
},
|
||||
}
|
||||
|
||||
apiResponse, err := client.UserApi.CreateUsersWithArrayInput(context.Background(), newUsers)
|
||||
apiResponse, err := client.UserApi.CreateUsersWithArrayInput(context.Background()).Body(newUsers).Execute()
|
||||
if err != nil {
|
||||
t.Fatalf("Error while adding users: %v", err)
|
||||
}
|
||||
if apiResponse.StatusCode != 200 {
|
||||
t.Log(apiResponse)
|
||||
}
|
||||
|
||||
/* issue with deleting users in the server side (500). commented out below for the time being
|
||||
/* issue deleting users due to issue in the server side (500). commented out below for the time being
|
||||
//tear down
|
||||
_, err1 := client.UserApi.DeleteUser(context.Background(), "gopher1")
|
||||
_, err1 := client.UserApi.DeleteUser(context.Background(), "gopher1").Execute()
|
||||
if err1 != nil {
|
||||
t.Errorf("Error while deleting user")
|
||||
t.Log(err1)
|
||||
}
|
||||
|
||||
_, err2 := client.UserApi.DeleteUser(context.Background(), "gopher2")
|
||||
_, err2 := client.UserApi.DeleteUser(context.Background(), "gopher2").Execute()
|
||||
if err2 != nil {
|
||||
t.Errorf("Error while deleting user")
|
||||
t.Log(err2)
|
||||
@@ -82,13 +81,13 @@ func TestCreateUsersWithArrayInput(t *testing.T) {
|
||||
func TestGetUserByName(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "gopher")
|
||||
resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "gopher").Execute()
|
||||
if err != nil {
|
||||
t.Fatalf("Error while getting user by id: %v", err)
|
||||
} else {
|
||||
assert.Equal(resp.Id, int64(1000), "User id should be equal")
|
||||
assert.Equal(resp.Username, "gopher", "User name should be gopher")
|
||||
assert.Equal(resp.LastName, "lang", "Last name should be lang")
|
||||
assert.Equal(*resp.Id, int64(1000), "User id should be equal")
|
||||
assert.Equal(*resp.Username, "gopher", "User name should be gopher")
|
||||
assert.Equal(*resp.LastName, "lang", "Last name should be lang")
|
||||
//t.Log(resp)
|
||||
}
|
||||
if apiResponse.StatusCode != 200 {
|
||||
@@ -97,7 +96,7 @@ func TestGetUserByName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetUserByNameWithInvalidID(t *testing.T) {
|
||||
resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "999999999")
|
||||
resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "999999999").Execute()
|
||||
if apiResponse != nil && apiResponse.StatusCode == 404 {
|
||||
return // This is a pass condition. API will return with a 404 error.
|
||||
} else if err != nil {
|
||||
@@ -115,16 +114,16 @@ func TestUpdateUser(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
newUser := sw.User{
|
||||
Id: 1000,
|
||||
FirstName: "gopher20",
|
||||
LastName: "lang20",
|
||||
Username: "gopher",
|
||||
Password: "lang",
|
||||
Email: "lang@test.com",
|
||||
Phone: "5101112222",
|
||||
UserStatus: 1}
|
||||
Id: sw.PtrInt64(1000),
|
||||
FirstName: sw.PtrString("gopher20"),
|
||||
LastName: sw.PtrString("lang20"),
|
||||
Username: sw.PtrString("gopher"),
|
||||
Password: sw.PtrString("lang"),
|
||||
Email: sw.PtrString("lang@test.com"),
|
||||
Phone: sw.PtrString("5101112222"),
|
||||
UserStatus: sw.PtrInt32(1)}
|
||||
|
||||
apiResponse, err := client.UserApi.UpdateUser(context.Background(), "gopher", newUser)
|
||||
apiResponse, err := client.UserApi.UpdateUser(context.Background(), "gopher").Body(newUser).Execute()
|
||||
if err != nil {
|
||||
t.Fatalf("Error while deleting user by id: %v", err)
|
||||
}
|
||||
@@ -133,20 +132,19 @@ func TestUpdateUser(t *testing.T) {
|
||||
}
|
||||
|
||||
//verify changings are correct
|
||||
resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "gopher")
|
||||
resp, apiResponse, err := client.UserApi.GetUserByName(context.Background(), "gopher").Execute()
|
||||
if err != nil {
|
||||
t.Fatalf("Error while getting user by id: %v", err)
|
||||
} else {
|
||||
assert.Equal(resp.Id, int64(1000), "User id should be equal")
|
||||
assert.Equal(resp.FirstName, "gopher20", "User name should be gopher")
|
||||
assert.Equal(resp.Password, "lang", "User name should be the same")
|
||||
assert.Equal(*resp.Id, int64(1000), "User id should be equal")
|
||||
assert.Equal(*resp.FirstName, "gopher20", "User name should be gopher")
|
||||
assert.Equal(*resp.Password, "lang", "User name should be the same")
|
||||
}
|
||||
}
|
||||
|
||||
/* issue in the server side as deleting user no longer works (returning 500)
|
||||
we may uncomment the following test when the server's issue is addressed
|
||||
/* issue deleting users due to issue in the server side (500). commented out below for the time being
|
||||
func TestDeleteUser(t *testing.T) {
|
||||
apiResponse, err := client.UserApi.DeleteUser(context.Background(), "gopher")
|
||||
apiResponse, err := client.UserApi.DeleteUser(context.Background(), "gopher").Execute()
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Error while deleting user: %v", err)
|
||||
@@ -154,4 +152,5 @@ func TestDeleteUser(t *testing.T) {
|
||||
if apiResponse.StatusCode != 200 {
|
||||
t.Log(apiResponse)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user