From b493de433b3c3a529b2d0c6062c19cc1cf55e455 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Wed, 10 Jun 2020 16:36:59 -0700 Subject: [PATCH] Add multiple inheritance group (#422) * Add multiple inheritance group * fix name --- rushScripts/regeneration.js | 1 + test/autorest/generated/migroup/client.go | 77 +++ test/autorest/generated/migroup/models.go | 102 ++++ .../multipleinheritanceserviceclient.go | 482 ++++++++++++++++++ test/autorest/migroup/migroup_test.go | 183 +++++++ 5 files changed, 845 insertions(+) create mode 100644 test/autorest/generated/migroup/client.go create mode 100644 test/autorest/generated/migroup/models.go create mode 100644 test/autorest/generated/migroup/multipleinheritanceserviceclient.go create mode 100644 test/autorest/migroup/migroup_test.go diff --git a/rushScripts/regeneration.js b/rushScripts/regeneration.js index cad71becd..9bea947ca 100644 --- a/rushScripts/regeneration.js +++ b/rushScripts/regeneration.js @@ -26,6 +26,7 @@ const goMappings = { 'httpinfrastructuregroup': 'httpInfrastructure.json', 'integergroup': 'body-integer.json', 'lrogroup': 'lro.json', + 'migroup': 'multiple-inheritance.json', //'modelflatteninggroup': 'model-flattening.json', 'morecustombaseurigroup': 'custom-baseUrl-more-options.json', 'numbergroup': 'body-number.json', diff --git a/test/autorest/generated/migroup/client.go b/test/autorest/generated/migroup/client.go new file mode 100644 index 000000000..c88dcbbf0 --- /dev/null +++ b/test/autorest/generated/migroup/client.go @@ -0,0 +1,77 @@ +// 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 migroup + +import ( + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "net/url" +) + +// 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 +} + +// DefaultClientOptions creates a ClientOptions type initialized with default values. +func DefaultClientOptions() ClientOptions { + return ClientOptions{ + HTTPClient: azcore.DefaultHTTPClientTransport(), + Retry: azcore.DefaultRetryOptions(), + } +} + +// Client - Service client for multiinheritance client testing +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.Telemetry), + 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 +} + +// MultipleInheritanceServiceClientOperations returns the MultipleInheritanceServiceClientOperations associated with this client. +func (client *Client) MultipleInheritanceServiceClientOperations() MultipleInheritanceServiceClientOperations { + return &multipleInheritanceServiceClientOperations{Client: client} +} diff --git a/test/autorest/generated/migroup/models.go b/test/autorest/generated/migroup/models.go new file mode 100644 index 000000000..842e3f665 --- /dev/null +++ b/test/autorest/generated/migroup/models.go @@ -0,0 +1,102 @@ +// 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 migroup + +import ( + "fmt" + "net/http" +) + +type Cat struct { + Feline + Pet + LikesMilk *bool `json:"likesMilk,omitempty"` +} + +// CatResponse is the response envelope for operations that return a Cat type. +type CatResponse struct { + Cat *Cat + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +type Error struct { + Message *string `json:"message,omitempty"` + Status *int32 `json:"status,omitempty"` +} + +func (e Error) Error() string { + msg := "" + if e.Message != nil { + msg += fmt.Sprintf("Message: %v\n", *e.Message) + } + if e.Status != nil { + msg += fmt.Sprintf("Status: %v\n", *e.Status) + } + if msg == "" { + msg = "missing error info" + } + return msg +} + +type Feline struct { + Hisses *bool `json:"hisses,omitempty"` + Meows *bool `json:"meows,omitempty"` +} + +// FelineResponse is the response envelope for operations that return a Feline type. +type FelineResponse struct { + Feline *Feline + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +type Horse struct { + Pet + IsAShowHorse *bool `json:"isAShowHorse,omitempty"` +} + +// HorseResponse is the response envelope for operations that return a Horse type. +type HorseResponse struct { + Horse *Horse + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +type Kitten struct { + Cat + EatsMiceYet *bool `json:"eatsMiceYet,omitempty"` +} + +// KittenResponse is the response envelope for operations that return a Kitten type. +type KittenResponse struct { + Kitten *Kitten + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +type Pet struct { + Name *string `json:"name,omitempty"` +} + +// 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 +} + +// StringResponse is the response envelope for operations that return a string type. +type StringResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response + Value *string +} diff --git a/test/autorest/generated/migroup/multipleinheritanceserviceclient.go b/test/autorest/generated/migroup/multipleinheritanceserviceclient.go new file mode 100644 index 000000000..19b4a5c66 --- /dev/null +++ b/test/autorest/generated/migroup/multipleinheritanceserviceclient.go @@ -0,0 +1,482 @@ +// 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 migroup + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "net/http" +) + +// MultipleInheritanceServiceClientOperations contains the methods for the MultipleInheritanceServiceClient group. +type MultipleInheritanceServiceClientOperations interface { + // GetCat - Get a cat with name 'Whiskers' where likesMilk, meows, and hisses is true + GetCat(ctx context.Context) (*CatResponse, error) + // GetFeline - Get a feline where meows and hisses are true + GetFeline(ctx context.Context) (*FelineResponse, error) + // GetHorse - Get a horse with name 'Fred' and isAShowHorse true + GetHorse(ctx context.Context) (*HorseResponse, error) + // GetKitten - Get a kitten with name 'Gatito' where likesMilk and meows is true, and hisses and eatsMiceYet is false + GetKitten(ctx context.Context) (*KittenResponse, error) + // GetPet - Get a pet with name 'Peanut' + GetPet(ctx context.Context) (*PetResponse, error) + // PutCat - Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true + PutCat(ctx context.Context, cat Cat) (*StringResponse, error) + // PutFeline - Put a feline who hisses and doesn't meow + PutFeline(ctx context.Context, feline Feline) (*StringResponse, error) + // PutHorse - Put a horse with name 'General' and isAShowHorse false + PutHorse(ctx context.Context, horse Horse) (*StringResponse, error) + // PutKitten - Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true + PutKitten(ctx context.Context, kitten Kitten) (*StringResponse, error) + // PutPet - Put a pet with name 'Butter' + PutPet(ctx context.Context, pet Pet) (*StringResponse, error) +} + +// multipleInheritanceServiceClientOperations implements the MultipleInheritanceServiceClientOperations interface. +type multipleInheritanceServiceClientOperations struct { + *Client +} + +// GetCat - Get a cat with name 'Whiskers' where likesMilk, meows, and hisses is true +func (client *multipleInheritanceServiceClientOperations) GetCat(ctx context.Context) (*CatResponse, error) { + req, err := client.getCatCreateRequest() + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.getCatHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// getCatCreateRequest creates the GetCat request. +func (client *multipleInheritanceServiceClientOperations) getCatCreateRequest() (*azcore.Request, error) { + urlPath := "/multipleInheritance/cat" + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodGet, *u) + return req, nil +} + +// getCatHandleResponse handles the GetCat response. +func (client *multipleInheritanceServiceClientOperations) getCatHandleResponse(resp *azcore.Response) (*CatResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.getCatHandleError(resp) + } + result := CatResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Cat) +} + +// getCatHandleError handles the GetCat error response. +func (client *multipleInheritanceServiceClientOperations) getCatHandleError(resp *azcore.Response) error { + var err Error + if err := resp.UnmarshalAsJSON(&err); err != nil { + return err + } + return err +} + +// GetFeline - Get a feline where meows and hisses are true +func (client *multipleInheritanceServiceClientOperations) GetFeline(ctx context.Context) (*FelineResponse, error) { + req, err := client.getFelineCreateRequest() + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.getFelineHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// getFelineCreateRequest creates the GetFeline request. +func (client *multipleInheritanceServiceClientOperations) getFelineCreateRequest() (*azcore.Request, error) { + urlPath := "/multipleInheritance/feline" + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodGet, *u) + return req, nil +} + +// getFelineHandleResponse handles the GetFeline response. +func (client *multipleInheritanceServiceClientOperations) getFelineHandleResponse(resp *azcore.Response) (*FelineResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.getFelineHandleError(resp) + } + result := FelineResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Feline) +} + +// getFelineHandleError handles the GetFeline error response. +func (client *multipleInheritanceServiceClientOperations) getFelineHandleError(resp *azcore.Response) error { + var err Error + if err := resp.UnmarshalAsJSON(&err); err != nil { + return err + } + return err +} + +// GetHorse - Get a horse with name 'Fred' and isAShowHorse true +func (client *multipleInheritanceServiceClientOperations) GetHorse(ctx context.Context) (*HorseResponse, error) { + req, err := client.getHorseCreateRequest() + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.getHorseHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// getHorseCreateRequest creates the GetHorse request. +func (client *multipleInheritanceServiceClientOperations) getHorseCreateRequest() (*azcore.Request, error) { + urlPath := "/multipleInheritance/horse" + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodGet, *u) + return req, nil +} + +// getHorseHandleResponse handles the GetHorse response. +func (client *multipleInheritanceServiceClientOperations) getHorseHandleResponse(resp *azcore.Response) (*HorseResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.getHorseHandleError(resp) + } + result := HorseResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Horse) +} + +// getHorseHandleError handles the GetHorse error response. +func (client *multipleInheritanceServiceClientOperations) getHorseHandleError(resp *azcore.Response) error { + var err Error + if err := resp.UnmarshalAsJSON(&err); err != nil { + return err + } + return err +} + +// GetKitten - Get a kitten with name 'Gatito' where likesMilk and meows is true, and hisses and eatsMiceYet is false +func (client *multipleInheritanceServiceClientOperations) GetKitten(ctx context.Context) (*KittenResponse, error) { + req, err := client.getKittenCreateRequest() + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.getKittenHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// getKittenCreateRequest creates the GetKitten request. +func (client *multipleInheritanceServiceClientOperations) getKittenCreateRequest() (*azcore.Request, error) { + urlPath := "/multipleInheritance/kitten" + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodGet, *u) + return req, nil +} + +// getKittenHandleResponse handles the GetKitten response. +func (client *multipleInheritanceServiceClientOperations) getKittenHandleResponse(resp *azcore.Response) (*KittenResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.getKittenHandleError(resp) + } + result := KittenResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Kitten) +} + +// getKittenHandleError handles the GetKitten error response. +func (client *multipleInheritanceServiceClientOperations) getKittenHandleError(resp *azcore.Response) error { + var err Error + if err := resp.UnmarshalAsJSON(&err); err != nil { + return err + } + return err +} + +// GetPet - Get a pet with name 'Peanut' +func (client *multipleInheritanceServiceClientOperations) GetPet(ctx context.Context) (*PetResponse, error) { + req, err := client.getPetCreateRequest() + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.getPetHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// getPetCreateRequest creates the GetPet request. +func (client *multipleInheritanceServiceClientOperations) getPetCreateRequest() (*azcore.Request, error) { + urlPath := "/multipleInheritance/pet" + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodGet, *u) + return req, nil +} + +// getPetHandleResponse handles the GetPet response. +func (client *multipleInheritanceServiceClientOperations) getPetHandleResponse(resp *azcore.Response) (*PetResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.getPetHandleError(resp) + } + result := PetResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Pet) +} + +// getPetHandleError handles the GetPet error response. +func (client *multipleInheritanceServiceClientOperations) getPetHandleError(resp *azcore.Response) error { + var err Error + if err := resp.UnmarshalAsJSON(&err); err != nil { + return err + } + return err +} + +// PutCat - Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true +func (client *multipleInheritanceServiceClientOperations) PutCat(ctx context.Context, cat Cat) (*StringResponse, error) { + req, err := client.putCatCreateRequest(cat) + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.putCatHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// putCatCreateRequest creates the PutCat request. +func (client *multipleInheritanceServiceClientOperations) putCatCreateRequest(cat Cat) (*azcore.Request, error) { + urlPath := "/multipleInheritance/cat" + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodPut, *u) + return req, req.MarshalAsJSON(cat) +} + +// putCatHandleResponse handles the PutCat response. +func (client *multipleInheritanceServiceClientOperations) putCatHandleResponse(resp *azcore.Response) (*StringResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.putCatHandleError(resp) + } + result := StringResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Value) +} + +// putCatHandleError handles the PutCat error response. +func (client *multipleInheritanceServiceClientOperations) putCatHandleError(resp *azcore.Response) error { + return errors.New(resp.Status) +} + +// PutFeline - Put a feline who hisses and doesn't meow +func (client *multipleInheritanceServiceClientOperations) PutFeline(ctx context.Context, feline Feline) (*StringResponse, error) { + req, err := client.putFelineCreateRequest(feline) + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.putFelineHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// putFelineCreateRequest creates the PutFeline request. +func (client *multipleInheritanceServiceClientOperations) putFelineCreateRequest(feline Feline) (*azcore.Request, error) { + urlPath := "/multipleInheritance/feline" + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodPut, *u) + return req, req.MarshalAsJSON(feline) +} + +// putFelineHandleResponse handles the PutFeline response. +func (client *multipleInheritanceServiceClientOperations) putFelineHandleResponse(resp *azcore.Response) (*StringResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.putFelineHandleError(resp) + } + result := StringResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Value) +} + +// putFelineHandleError handles the PutFeline error response. +func (client *multipleInheritanceServiceClientOperations) putFelineHandleError(resp *azcore.Response) error { + return errors.New(resp.Status) +} + +// PutHorse - Put a horse with name 'General' and isAShowHorse false +func (client *multipleInheritanceServiceClientOperations) PutHorse(ctx context.Context, horse Horse) (*StringResponse, error) { + req, err := client.putHorseCreateRequest(horse) + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.putHorseHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// putHorseCreateRequest creates the PutHorse request. +func (client *multipleInheritanceServiceClientOperations) putHorseCreateRequest(horse Horse) (*azcore.Request, error) { + urlPath := "/multipleInheritance/horse" + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodPut, *u) + return req, req.MarshalAsJSON(horse) +} + +// putHorseHandleResponse handles the PutHorse response. +func (client *multipleInheritanceServiceClientOperations) putHorseHandleResponse(resp *azcore.Response) (*StringResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.putHorseHandleError(resp) + } + result := StringResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Value) +} + +// putHorseHandleError handles the PutHorse error response. +func (client *multipleInheritanceServiceClientOperations) putHorseHandleError(resp *azcore.Response) error { + return errors.New(resp.Status) +} + +// PutKitten - Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true +func (client *multipleInheritanceServiceClientOperations) PutKitten(ctx context.Context, kitten Kitten) (*StringResponse, error) { + req, err := client.putKittenCreateRequest(kitten) + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.putKittenHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// putKittenCreateRequest creates the PutKitten request. +func (client *multipleInheritanceServiceClientOperations) putKittenCreateRequest(kitten Kitten) (*azcore.Request, error) { + urlPath := "/multipleInheritance/kitten" + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodPut, *u) + return req, req.MarshalAsJSON(kitten) +} + +// putKittenHandleResponse handles the PutKitten response. +func (client *multipleInheritanceServiceClientOperations) putKittenHandleResponse(resp *azcore.Response) (*StringResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.putKittenHandleError(resp) + } + result := StringResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Value) +} + +// putKittenHandleError handles the PutKitten error response. +func (client *multipleInheritanceServiceClientOperations) putKittenHandleError(resp *azcore.Response) error { + return errors.New(resp.Status) +} + +// PutPet - Put a pet with name 'Butter' +func (client *multipleInheritanceServiceClientOperations) PutPet(ctx context.Context, pet Pet) (*StringResponse, error) { + req, err := client.putPetCreateRequest(pet) + if err != nil { + return nil, err + } + resp, err := client.p.Do(ctx, req) + if err != nil { + return nil, err + } + result, err := client.putPetHandleResponse(resp) + if err != nil { + return nil, err + } + return result, nil +} + +// putPetCreateRequest creates the PutPet request. +func (client *multipleInheritanceServiceClientOperations) putPetCreateRequest(pet Pet) (*azcore.Request, error) { + urlPath := "/multipleInheritance/pet" + u, err := client.u.Parse(urlPath) + if err != nil { + return nil, err + } + req := azcore.NewRequest(http.MethodPut, *u) + return req, req.MarshalAsJSON(pet) +} + +// putPetHandleResponse handles the PutPet response. +func (client *multipleInheritanceServiceClientOperations) putPetHandleResponse(resp *azcore.Response) (*StringResponse, error) { + if !resp.HasStatusCode(http.StatusOK) { + return nil, client.putPetHandleError(resp) + } + result := StringResponse{RawResponse: resp.Response} + return &result, resp.UnmarshalAsJSON(&result.Value) +} + +// putPetHandleError handles the PutPet error response. +func (client *multipleInheritanceServiceClientOperations) putPetHandleError(resp *azcore.Response) error { + return errors.New(resp.Status) +} diff --git a/test/autorest/migroup/migroup_test.go b/test/autorest/migroup/migroup_test.go new file mode 100644 index 000000000..90841094e --- /dev/null +++ b/test/autorest/migroup/migroup_test.go @@ -0,0 +1,183 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package migrouptest + +import ( + "context" + "generatortests/autorest/generated/migroup" + "generatortests/helpers" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/to" +) + +func getMultipleInheritanceServiceClientOperations(t *testing.T) migroup.MultipleInheritanceServiceClientOperations { + client, err := migroup.NewDefaultClient(nil) + if err != nil { + t.Fatalf("failed to create client: %v", err) + } + return client.MultipleInheritanceServiceClientOperations() +} + +// GetCat - Get a cat with name 'Whiskers' where likesMilk, meows, and hisses is true +func TestGetCat(t *testing.T) { + client := getMultipleInheritanceServiceClientOperations(t) + result, err := client.GetCat(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Cat, &migroup.Cat{ + Feline: migroup.Feline{ + Hisses: to.BoolPtr(true), + Meows: to.BoolPtr(true), + }, + Pet: migroup.Pet{ + Name: to.StringPtr("Whiskers"), + }, + LikesMilk: to.BoolPtr(true), + }) +} + +// GetFeline - Get a feline where meows and hisses are true +func TestGetFeline(t *testing.T) { + client := getMultipleInheritanceServiceClientOperations(t) + result, err := client.GetFeline(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Feline, &migroup.Feline{ + Hisses: to.BoolPtr(true), + Meows: to.BoolPtr(true), + }) +} + +// GetHorse - Get a horse with name 'Fred' and isAShowHorse true +func TestGetHorse(t *testing.T) { + client := getMultipleInheritanceServiceClientOperations(t) + result, err := client.GetHorse(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Horse, &migroup.Horse{ + Pet: migroup.Pet{ + Name: to.StringPtr("Fred"), + }, + IsAShowHorse: to.BoolPtr(true), + }) +} + +// GetKitten - Get a kitten with name 'Gatito' where likesMilk and meows is true, and hisses and eatsMiceYet is false +func TestGetKitten(t *testing.T) { + client := getMultipleInheritanceServiceClientOperations(t) + result, err := client.GetKitten(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Kitten, &migroup.Kitten{ + Cat: migroup.Cat{ + Feline: migroup.Feline{ + Hisses: to.BoolPtr(true), + Meows: to.BoolPtr(true), + }, + Pet: migroup.Pet{ + Name: to.StringPtr("Gatito"), + }, + LikesMilk: to.BoolPtr(true), + }, + EatsMiceYet: to.BoolPtr(false), + }) +} + +// GetPet - Get a pet with name 'Peanut' +func TestGetPet(t *testing.T) { + client := getMultipleInheritanceServiceClientOperations(t) + result, err := client.GetPet(context.Background()) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Pet, &migroup.Pet{ + Name: to.StringPtr("Peanut"), + }) +} + +// PutCat - Put a cat with name 'Boots' where likesMilk and hisses is false, meows is true +func TestPutCat(t *testing.T) { + client := getMultipleInheritanceServiceClientOperations(t) + result, err := client.PutCat(context.Background(), migroup.Cat{ + Feline: migroup.Feline{ + Hisses: to.BoolPtr(false), + Meows: to.BoolPtr(true), + }, + Pet: migroup.Pet{ + Name: to.StringPtr("Boots"), + }, + LikesMilk: to.BoolPtr(false), + }) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Value, to.StringPtr("Cat was correct!")) +} + +// PutFeline - Put a feline who hisses and doesn't meow +func TestPutFeline(t *testing.T) { + client := getMultipleInheritanceServiceClientOperations(t) + result, err := client.PutFeline(context.Background(), migroup.Feline{ + Hisses: to.BoolPtr(true), + Meows: to.BoolPtr(false), + }) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Value, to.StringPtr("Feline was correct!")) +} + +// PutHorse - Put a horse with name 'General' and isAShowHorse false +func TestPutHorse(t *testing.T) { + client := getMultipleInheritanceServiceClientOperations(t) + result, err := client.PutHorse(context.Background(), migroup.Horse{ + Pet: migroup.Pet{ + Name: to.StringPtr("General"), + }, + IsAShowHorse: to.BoolPtr(false), + }) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Value, to.StringPtr("Horse was correct!")) +} + +// PutKitten - Put a kitten with name 'Kitty' where likesMilk and hisses is false, meows and eatsMiceYet is true +func TestPutKitten(t *testing.T) { + client := getMultipleInheritanceServiceClientOperations(t) + result, err := client.PutKitten(context.Background(), migroup.Kitten{ + Cat: migroup.Cat{ + Feline: migroup.Feline{ + Hisses: to.BoolPtr(false), + Meows: to.BoolPtr(true), + }, + Pet: migroup.Pet{ + Name: to.StringPtr("Kitty"), + }, + LikesMilk: to.BoolPtr(false), + }, + EatsMiceYet: to.BoolPtr(true), + }) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Value, to.StringPtr("Kitten was correct!")) +} + +// PutPet - Put a pet with name 'Butter' +func TestPutPet(t *testing.T) { + client := getMultipleInheritanceServiceClientOperations(t) + result, err := client.PutPet(context.Background(), migroup.Pet{ + Name: to.StringPtr("Butter"), + }) + if err != nil { + t.Fatal(err) + } + helpers.DeepEqualOrFatal(t, result.Value, to.StringPtr("Pet was correct!")) +}