From 6336f43c85ca092a37766a87bf4ecf1ce95073bb Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Wed, 17 Jun 2020 17:48:02 -0700 Subject: [PATCH] Add more test server tests (#428) Added missing urlgroup tests. Added extensible enum codegen and tests. --- rushScripts/regeneration.js | 1 + .../extenumsgroup/extenumsgroup_test.go | 75 ++++++ .../generated/extenumsgroup/client.go | 98 +++++++ .../autorest/generated/extenumsgroup/enums.go | 58 ++++ .../generated/extenumsgroup/models.go | 28 ++ test/autorest/generated/extenumsgroup/pet.go | 128 +++++++++ test/autorest/urlgroup/queries_test.go | 251 +++++++++++++++++- 7 files changed, 637 insertions(+), 2 deletions(-) create mode 100644 test/autorest/extenumsgroup/extenumsgroup_test.go create mode 100644 test/autorest/generated/extenumsgroup/client.go create mode 100644 test/autorest/generated/extenumsgroup/enums.go create mode 100644 test/autorest/generated/extenumsgroup/models.go create mode 100644 test/autorest/generated/extenumsgroup/pet.go diff --git a/rushScripts/regeneration.js b/rushScripts/regeneration.js index 3f3738489..79785de94 100644 --- a/rushScripts/regeneration.js +++ b/rushScripts/regeneration.js @@ -20,6 +20,7 @@ const goMappings = { 'dictionarygroup': 'body-dictionary.json', //'durationgroup': 'body-duration.json', 'errorsgroup': 'xms-error-responses.json', + 'extenumsgroup': 'extensible-enums-swagger.json', 'filegroup': 'body-file.json', //'formdatagroup': 'body-formdata.json', 'headergroup': 'header.json', diff --git a/test/autorest/extenumsgroup/extenumsgroup_test.go b/test/autorest/extenumsgroup/extenumsgroup_test.go new file mode 100644 index 000000000..d150b57c3 --- /dev/null +++ b/test/autorest/extenumsgroup/extenumsgroup_test.go @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package extenumsgrouptest + +import ( + "context" + "generatortests/autorest/generated/extenumsgroup" + "generatortests/helpers" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/to" +) + +func getPetOperations(t *testing.T) extenumsgroup.PetOperations { + client, err := extenumsgroup.NewDefaultClient(nil) + if err != nil { + t.Fatalf("failed to create enum client: %v", err) + } + return client.PetOperations() +} + +func TestAddPet(t *testing.T) { + client := getPetOperations(t) + result, err := client.AddPet(context.Background(), &extenumsgroup.PetAddPetOptions{ + PetParam: &extenumsgroup.Pet{ + Name: to.StringPtr("Retriever"), + }, + }) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Pet, &extenumsgroup.Pet{ + Name: to.StringPtr("Retriever"), + }) +} + +func TestGetByPetIDExpected(t *testing.T) { + client := getPetOperations(t) + result, err := client.GetByPetID(context.Background(), "tommy") + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Pet, &extenumsgroup.Pet{ + DaysOfWeek: extenumsgroup.DaysOfWeekExtensibleEnumMonday.ToPtr(), + IntEnum: extenumsgroup.IntEnumOne.ToPtr(), + Name: to.StringPtr("Tommy Tomson"), + }) +} + +func TestGetByPetIDUnexpected(t *testing.T) { + client := getPetOperations(t) + result, err := client.GetByPetID(context.Background(), "casper") + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Pet, &extenumsgroup.Pet{ + DaysOfWeek: (*extenumsgroup.DaysOfWeekExtensibleEnum)(to.StringPtr("Weekend")), + IntEnum: extenumsgroup.IntEnumTwo.ToPtr(), + Name: to.StringPtr("Casper Ghosty"), + }) +} + +func TestGetByPetIDAllowed(t *testing.T) { + client := getPetOperations(t) + result, err := client.GetByPetID(context.Background(), "scooby") + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Pet, &extenumsgroup.Pet{ + DaysOfWeek: extenumsgroup.DaysOfWeekExtensibleEnumThursday.ToPtr(), + IntEnum: (*extenumsgroup.IntEnum)(to.StringPtr("2.1")), + Name: to.StringPtr("Scooby Scarface"), + }) +} diff --git a/test/autorest/generated/extenumsgroup/client.go b/test/autorest/generated/extenumsgroup/client.go new file mode 100644 index 000000000..ec5de4a53 --- /dev/null +++ b/test/autorest/generated/extenumsgroup/client.go @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package extenumsgroup + +import ( + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "net/url" + "strings" +) + +const telemetryInfo = "azsdk-go-extenumsgroup/" + +// ClientOptions contains configuration settings for the default client's pipeline. +type ClientOptions struct { + // HTTPClient sets the transport for making HTTP requests. + HTTPClient azcore.Transport + // LogOptions configures the built-in request logging policy behavior. + LogOptions azcore.RequestLogOptions + // Retry configures the built-in retry policy behavior. + Retry azcore.RetryOptions + // Telemetry configures the built-in telemetry policy behavior. + Telemetry azcore.TelemetryOptions + // ApplicationID is an application-specific identification string used in telemetry. + // It has a maximum length of 24 characters and must not contain any spaces. + ApplicationID string +} + +// DefaultClientOptions creates a ClientOptions type initialized with default values. +func DefaultClientOptions() ClientOptions { + return ClientOptions{ + HTTPClient: azcore.DefaultHTTPClientTransport(), + Retry: azcore.DefaultRetryOptions(), + } +} + +func (c *ClientOptions) telemetryOptions() azcore.TelemetryOptions { + t := telemetryInfo + if c.ApplicationID != "" { + a := strings.ReplaceAll(c.ApplicationID, " ", "/") + if len(a) > 24 { + a = a[:24] + } + t = fmt.Sprintf("%s %s", a, telemetryInfo) + } + if c.Telemetry.Value == "" { + return azcore.TelemetryOptions{Value: t} + } + return azcore.TelemetryOptions{Value: fmt.Sprintf("%s %s", c.Telemetry.Value, t)} +} + +// Client - PetStore +type Client struct { + u *url.URL + p azcore.Pipeline +} + +// DefaultEndpoint is the default service endpoint. +const DefaultEndpoint = "http://localhost:3000" + +// NewDefaultClient creates an instance of the Client type using the DefaultEndpoint. +func NewDefaultClient(options *ClientOptions) (*Client, error) { + return NewClient(DefaultEndpoint, options) +} + +// NewClient creates an instance of the Client type with the specified endpoint. +func NewClient(endpoint string, options *ClientOptions) (*Client, error) { + if options == nil { + o := DefaultClientOptions() + options = &o + } + p := azcore.NewPipeline(options.HTTPClient, + azcore.NewTelemetryPolicy(options.telemetryOptions()), + azcore.NewUniqueRequestIDPolicy(), + azcore.NewRetryPolicy(&options.Retry), + azcore.NewRequestLogPolicy(options.LogOptions)) + return NewClientWithPipeline(endpoint, p) +} + +// NewClientWithPipeline creates an instance of the Client type with the specified endpoint and pipeline. +func NewClientWithPipeline(endpoint string, p azcore.Pipeline) (*Client, error) { + u, err := url.Parse(endpoint) + if err != nil { + return nil, err + } + if u.Scheme == "" { + return nil, fmt.Errorf("no scheme detected in endpoint %s", endpoint) + } + return &Client{u: u, p: p}, nil +} + +// PetOperations returns the PetOperations associated with this client. +func (client *Client) PetOperations() PetOperations { + return &petOperations{Client: client} +} diff --git a/test/autorest/generated/extenumsgroup/enums.go b/test/autorest/generated/extenumsgroup/enums.go new file mode 100644 index 000000000..b60558e99 --- /dev/null +++ b/test/autorest/generated/extenumsgroup/enums.go @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package extenumsgroup + +// DaysOfWeekExtensibleEnum - Type of Pet +type DaysOfWeekExtensibleEnum string + +const ( + DaysOfWeekExtensibleEnumFriday DaysOfWeekExtensibleEnum = "Friday" + DaysOfWeekExtensibleEnumMonday DaysOfWeekExtensibleEnum = "Monday" + DaysOfWeekExtensibleEnumSaturday DaysOfWeekExtensibleEnum = "Saturday" + DaysOfWeekExtensibleEnumSunday DaysOfWeekExtensibleEnum = "Sunday" + DaysOfWeekExtensibleEnumThursday DaysOfWeekExtensibleEnum = "Thursday" + DaysOfWeekExtensibleEnumTuesday DaysOfWeekExtensibleEnum = "Tuesday" + DaysOfWeekExtensibleEnumWednesday DaysOfWeekExtensibleEnum = "Wednesday" +) + +func PossibleDaysOfWeekExtensibleEnumValues() []DaysOfWeekExtensibleEnum { + return []DaysOfWeekExtensibleEnum{ + DaysOfWeekExtensibleEnumFriday, + DaysOfWeekExtensibleEnumMonday, + DaysOfWeekExtensibleEnumSaturday, + DaysOfWeekExtensibleEnumSunday, + DaysOfWeekExtensibleEnumThursday, + DaysOfWeekExtensibleEnumTuesday, + DaysOfWeekExtensibleEnumWednesday, + } +} + +func (c DaysOfWeekExtensibleEnum) ToPtr() *DaysOfWeekExtensibleEnum { + return &c +} + +type IntEnum string + +const ( + // IntEnumOne - one + IntEnumOne IntEnum = "1" + // IntEnumThree - three + IntEnumThree IntEnum = "3" + // IntEnumTwo - two + IntEnumTwo IntEnum = "2" +) + +func PossibleIntEnumValues() []IntEnum { + return []IntEnum{ + IntEnumOne, + IntEnumThree, + IntEnumTwo, + } +} + +func (c IntEnum) ToPtr() *IntEnum { + return &c +} diff --git a/test/autorest/generated/extenumsgroup/models.go b/test/autorest/generated/extenumsgroup/models.go new file mode 100644 index 000000000..050587934 --- /dev/null +++ b/test/autorest/generated/extenumsgroup/models.go @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package extenumsgroup + +import "net/http" + +type Pet struct { + // Type of Pet + DaysOfWeek *DaysOfWeekExtensibleEnum `json:"DaysOfWeek,omitempty"` + IntEnum *IntEnum `json:"IntEnum,omitempty"` + Name *string `json:"name,omitempty"` +} + +// PetAddPetOptions contains the optional parameters for the Pet.AddPet method. +type PetAddPetOptions struct { + PetParam *Pet +} + +// PetResponse is the response envelope for operations that return a Pet type. +type PetResponse struct { + Pet *Pet + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} diff --git a/test/autorest/generated/extenumsgroup/pet.go b/test/autorest/generated/extenumsgroup/pet.go new file mode 100644 index 000000000..bf156478e --- /dev/null +++ b/test/autorest/generated/extenumsgroup/pet.go @@ -0,0 +1,128 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package extenumsgroup + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "io/ioutil" + "net/http" + "net/url" + "strings" +) + +// PetOperations contains the methods for the Pet group. +type PetOperations interface { + AddPet(ctx context.Context, petAddPetOptions *PetAddPetOptions) (*PetResponse, error) + GetByPetID(ctx context.Context, petId string) (*PetResponse, error) +} + +// petOperations implements the PetOperations interface. +type petOperations struct { + *Client +} + +func (client *petOperations) AddPet(ctx context.Context, petAddPetOptions *PetAddPetOptions) (*PetResponse, error) { + req, err := client.addPetCreateRequest(petAddPetOptions) + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.addPetHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// addPetCreateRequest creates the AddPet request. +func (client *petOperations) addPetCreateRequest(petAddPetOptions *PetAddPetOptions) (*azcore.Request, error) { + urlPath := "/extensibleenums/pet/addPet" + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodPost, *u) + if petAddPetOptions != nil { + return req, req.MarshalAsJSON(petAddPetOptions.PetParam) + } + return req, nil +} + +// addPetHandleResponse handles the AddPet response. +func (client *petOperations) addPetHandleResponse(resp *azcore.Response) (*PetResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.addPetHandleError(resp) + } + result := PetResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Pet) +} + +// addPetHandleError handles the AddPet error response. +func (client *petOperations) addPetHandleError(resp *azcore.Response) error { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return fmt.Errorf("%s; failed to read response body: %w", resp.Status, err) + } + if len(body) == 0 { + return errors.New(resp.Status) + } + return errors.New(string(body)) +} + +func (client *petOperations) GetByPetID(ctx context.Context, petId string) (*PetResponse, error) { + req, err := client.getByPetIdCreateRequest(petId) + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.getByPetIdHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// getByPetIdCreateRequest creates the GetByPetID request. +func (client *petOperations) getByPetIdCreateRequest(petId string) (*azcore.Request, error) { + urlPath := "/extensibleenums/pet/{petId}" + urlPath = strings.ReplaceAll(urlPath, "{petId}", url.PathEscape(petId)) + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodGet, *u) + return req, nil +} + +// getByPetIdHandleResponse handles the GetByPetID response. +func (client *petOperations) getByPetIdHandleResponse(resp *azcore.Response) (*PetResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.getByPetIdHandleError(resp) + } + result := PetResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Pet) +} + +// getByPetIdHandleError handles the GetByPetID error response. +func (client *petOperations) getByPetIdHandleError(resp *azcore.Response) error { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return fmt.Errorf("%s; failed to read response body: %w", resp.Status, err) + } + if len(body) == 0 { + return errors.New(resp.Status) + } + return errors.New(string(body)) +} diff --git a/test/autorest/urlgroup/queries_test.go b/test/autorest/urlgroup/queries_test.go index 363b565c0..07e569f99 100644 --- a/test/autorest/urlgroup/queries_test.go +++ b/test/autorest/urlgroup/queries_test.go @@ -19,6 +19,29 @@ func getQueriesClient(t *testing.T) urlgroup.QueriesOperations { return client.QueriesOperations() } +// ArrayStringCSVEmpty - Get an empty array [] of string using the csv-array format +func TestArrayStringCSVEmpty(t *testing.T) { + client := getQueriesClient(t) + result, err := client.ArrayStringCSVEmpty(context.Background(), &urlgroup.QueriesArrayStringCSVEmptyOptions{ + ArrayQuery: &[]string{}, + }) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// ArrayStringCSVNull - Get a null array of string using the csv-array format +func TestArrayStringCSVNull(t *testing.T) { + client := getQueriesClient(t) + result, err := client.ArrayStringCSVNull(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// ArrayStringCSVValid - Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the csv-array format func TestArrayStringCsvValid(t *testing.T) { client := getQueriesClient(t) result, err := client.ArrayStringCSVValid(context.Background(), &urlgroup.QueriesArrayStringCSVValidOptions{ @@ -30,6 +53,7 @@ func TestArrayStringCsvValid(t *testing.T) { helpers.VerifyStatusCode(t, result, http.StatusOK) } +// ArrayStringPipesValid - Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the pipes-array format func TestArrayStringPipesValid(t *testing.T) { client := getQueriesClient(t) result, err := client.ArrayStringPipesValid(context.Background(), &urlgroup.QueriesArrayStringPipesValidOptions{ @@ -41,10 +65,41 @@ func TestArrayStringPipesValid(t *testing.T) { helpers.VerifyStatusCode(t, result, http.StatusOK) } -func toByteSlicePtr(v []byte) *[]byte { - return &v +// ArrayStringSsvValid - Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the ssv-array format +func TestArrayStringSsvValid(t *testing.T) { + client := getQueriesClient(t) + result, err := client.ArrayStringSsvValid(context.Background(), &urlgroup.QueriesArrayStringSsvValidOptions{ + ArrayQuery: &[]string{"ArrayQuery1", "begin!*'();:@ &=+$,/?#[]end", "", ""}, + }) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// ArrayStringTsvValid - Get an array of string ['ArrayQuery1', 'begin!*'();:@ &=+$,/?#[]end' , null, ''] using the tsv-array format +func TestArrayStringTsvValid(t *testing.T) { + client := getQueriesClient(t) + result, err := client.ArrayStringTsvValid(context.Background(), &urlgroup.QueriesArrayStringTsvValidOptions{ + ArrayQuery: &[]string{"ArrayQuery1", "begin!*'();:@ &=+$,/?#[]end", "", ""}, + }) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) } +// ByteEmpty - Get '' as byte array +func TestByteEmpty(t *testing.T) { + client := getQueriesClient(t) + result, err := client.ByteEmpty(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// ByteMultiByte - Get '啊齄丂狛狜隣郎隣兀﨩' multibyte value as utf-8 encoded byte array func TestByteMultiByte(t *testing.T) { client := getQueriesClient(t) result, err := client.ByteMultiByte(context.Background(), &urlgroup.QueriesByteMultiByteOptions{ @@ -56,6 +111,37 @@ func TestByteMultiByte(t *testing.T) { helpers.VerifyStatusCode(t, result, http.StatusOK) } +// ByteNull - Get null as byte array (no query parameters in uri) +func TestByteNull(t *testing.T) { + client := getQueriesClient(t) + result, err := client.ByteNull(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// DateNull - Get null as date - this should result in no query parameters in uri +func TestDateNull(t *testing.T) { + client := getQueriesClient(t) + result, err := client.DateNull(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// DateTimeNull - Get null as date-time, should result in no query parameters in uri +func TestDateTimeNull(t *testing.T) { + client := getQueriesClient(t) + result, err := client.DateTimeNull(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// DateTimeValid - Get '2012-01-01T01:01:01Z' as date-time func TestDateTimeValid(t *testing.T) { client := getQueriesClient(t) result, err := client.DateTimeValid(context.Background()) @@ -65,6 +151,17 @@ func TestDateTimeValid(t *testing.T) { helpers.VerifyStatusCode(t, result, http.StatusOK) } +// DateValid - Get '2012-01-01' as date +func TestDateValid(t *testing.T) { + client := getQueriesClient(t) + result, err := client.DateValid(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// DoubleDecimalNegative - Get '-9999999.999' numeric value func TestDoubleDecimalNegative(t *testing.T) { client := getQueriesClient(t) result, err := client.DoubleDecimalNegative(context.Background()) @@ -74,6 +171,37 @@ func TestDoubleDecimalNegative(t *testing.T) { helpers.VerifyStatusCode(t, result, http.StatusOK) } +// DoubleDecimalPositive - Get '9999999.999' numeric value +func TestDoubleDecimalPositive(t *testing.T) { + client := getQueriesClient(t) + result, err := client.DoubleDecimalPositive(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// DoubleNull - Get null numeric value (no query parameter) +func TestDoubleNull(t *testing.T) { + client := getQueriesClient(t) + result, err := client.DoubleNull(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// EnumNull - Get null (no query parameter in url) +func TestEnumNull(t *testing.T) { + client := getQueriesClient(t) + result, err := client.EnumNull(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// EnumValid - Get using uri with query parameter 'green color' func TestEnumValid(t *testing.T) { client := getQueriesClient(t) result, err := client.EnumValid(context.Background(), &urlgroup.QueriesEnumValidOptions{ @@ -85,6 +213,17 @@ func TestEnumValid(t *testing.T) { helpers.VerifyStatusCode(t, result, http.StatusOK) } +// FloatNull - Get null numeric value (no query parameter) +func TestFloatNull(t *testing.T) { + client := getQueriesClient(t) + result, err := client.FloatNull(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// FloatScientificNegative - Get '-1.034E-20' numeric value func TestFloatScientificNegative(t *testing.T) { client := getQueriesClient(t) result, err := client.FloatScientificNegative(context.Background()) @@ -94,6 +233,37 @@ func TestFloatScientificNegative(t *testing.T) { helpers.VerifyStatusCode(t, result, http.StatusOK) } +// FloatScientificPositive - Get '1.034E+20' numeric value +func TestFloatScientificPositive(t *testing.T) { + client := getQueriesClient(t) + result, err := client.FloatScientificPositive(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// GetBooleanFalse - Get false Boolean value on path +func TestGetBooleanFalse(t *testing.T) { + client := getQueriesClient(t) + result, err := client.GetBooleanFalse(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// GetBooleanNull - Get null Boolean value on query (query string should be absent) +func TestGetBooleanNull(t *testing.T) { + client := getQueriesClient(t) + result, err := client.GetBooleanNull(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// GetBooleanTrue - Get true Boolean value on path func TestGetBooleanTrue(t *testing.T) { client := getQueriesClient(t) result, err := client.GetBooleanTrue(context.Background()) @@ -103,6 +273,27 @@ func TestGetBooleanTrue(t *testing.T) { helpers.VerifyStatusCode(t, result, http.StatusOK) } +// GetIntNegativeOneMillion - Get '-1000000' integer value +func TestGetIntNegativeOneMillion(t *testing.T) { + client := getQueriesClient(t) + result, err := client.GetIntNegativeOneMillion(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// GetIntNull - Get null integer value (no query parameter) +func TestGetIntNull(t *testing.T) { + client := getQueriesClient(t) + result, err := client.GetIntNull(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// GetIntOneMillion - Get '1000000' integer value func TestGetIntOneMillion(t *testing.T) { client := getQueriesClient(t) result, err := client.GetIntOneMillion(context.Background()) @@ -112,6 +303,27 @@ func TestGetIntOneMillion(t *testing.T) { helpers.VerifyStatusCode(t, result, http.StatusOK) } +// GetLongNull - Get 'null 64 bit integer value (no query param in uri) +func TestGetLongNull(t *testing.T) { + client := getQueriesClient(t) + result, err := client.GetLongNull(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// GetNegativeTenBillion - Get '-10000000000' 64 bit integer value +func TestGetNegativeTenBillion(t *testing.T) { + client := getQueriesClient(t) + result, err := client.GetNegativeTenBillion(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// GetTenBillion - Get '10000000000' 64 bit integer value func TestGetTenBillion(t *testing.T) { client := getQueriesClient(t) result, err := client.GetTenBillion(context.Background()) @@ -121,6 +333,37 @@ func TestGetTenBillion(t *testing.T) { helpers.VerifyStatusCode(t, result, http.StatusOK) } +// StringEmpty - Get '' +func TestStringEmpty(t *testing.T) { + client := getQueriesClient(t) + result, err := client.StringEmpty(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// StringNull - Get null (no query parameter in url) +func TestStringNull(t *testing.T) { + client := getQueriesClient(t) + result, err := client.StringNull(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// StringURLEncoded - Get 'begin!*'();:@ &=+$,/?#[]end +func TestStringURLEncoded(t *testing.T) { + client := getQueriesClient(t) + result, err := client.StringURLEncoded(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.VerifyStatusCode(t, result, http.StatusOK) +} + +// StringUnicode - Get '啊齄丂狛狜隣郎隣兀﨩' multi-byte string value func TestStringUnicode(t *testing.T) { client := getQueriesClient(t) result, err := client.StringUnicode(context.Background()) @@ -129,3 +372,7 @@ func TestStringUnicode(t *testing.T) { } helpers.VerifyStatusCode(t, result, http.StatusOK) } + +func toByteSlicePtr(v []byte) *[]byte { + return &v +}