diff --git a/globalcatalogv1/global_catalog_v1.go b/globalcatalogv1/global_catalog_v1.go index e23d0549..150950d7 100644 --- a/globalcatalogv1/global_catalog_v1.go +++ b/globalcatalogv1/global_catalog_v1.go @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2020. + * (C) Copyright IBM Corp. 2021. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,8 @@ */ /* - * IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-d753183b-20201209-163011 + * IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-4c92c221-20210211-060810 */ - // Package globalcatalogv1 : Operations and models for the GlobalCatalogV1 service package globalcatalogv1 @@ -26,13 +25,14 @@ import ( "context" "encoding/json" "fmt" - "github.com/IBM/go-sdk-core/v4/core" - common "github.com/IBM/platform-services-go-sdk/common" - "github.com/go-openapi/strfmt" "io" "net/http" "reflect" "time" + + "github.com/IBM/go-sdk-core/v5/core" + common "github.com/IBM/platform-services-go-sdk/common" + "github.com/go-openapi/strfmt" ) // GlobalCatalogV1 : The catalog service manages offerings across geographies as the system of record. The catalog @@ -215,9 +215,18 @@ func (globalCatalog *GlobalCatalogV1) ListCatalogEntriesWithContext(ctx context. if listCatalogEntriesOptions.Languages != nil { builder.AddQuery("languages", fmt.Sprint(*listCatalogEntriesOptions.Languages)) } + if listCatalogEntriesOptions.Catalog != nil { + builder.AddQuery("catalog", fmt.Sprint(*listCatalogEntriesOptions.Catalog)) + } if listCatalogEntriesOptions.Complete != nil { builder.AddQuery("complete", fmt.Sprint(*listCatalogEntriesOptions.Complete)) } + if listCatalogEntriesOptions.Offset != nil { + builder.AddQuery("_offset", fmt.Sprint(*listCatalogEntriesOptions.Offset)) + } + if listCatalogEntriesOptions.Limit != nil { + builder.AddQuery("_limit", fmt.Sprint(*listCatalogEntriesOptions.Limit)) + } request, err := builder.Build() if err != nil { @@ -599,7 +608,7 @@ func (globalCatalog *GlobalCatalogV1) GetChildObjectsWithContext(ctx context.Con } pathParamsMap := map[string]string{ - "id": *getChildObjectsOptions.ID, + "id": *getChildObjectsOptions.ID, "kind": *getChildObjectsOptions.Kind, } @@ -1064,7 +1073,7 @@ func (globalCatalog *GlobalCatalogV1) GetArtifactWithContext(ctx context.Context } pathParamsMap := map[string]string{ - "object_id": *getArtifactOptions.ObjectID, + "object_id": *getArtifactOptions.ObjectID, "artifact_id": *getArtifactOptions.ArtifactID, } @@ -1121,7 +1130,7 @@ func (globalCatalog *GlobalCatalogV1) UploadArtifactWithContext(ctx context.Cont } pathParamsMap := map[string]string{ - "object_id": *uploadArtifactOptions.ObjectID, + "object_id": *uploadArtifactOptions.ObjectID, "artifact_id": *uploadArtifactOptions.ArtifactID, } @@ -1182,7 +1191,7 @@ func (globalCatalog *GlobalCatalogV1) DeleteArtifactWithContext(ctx context.Cont } pathParamsMap := map[string]string{ - "object_id": *deleteArtifactOptions.ObjectID, + "object_id": *deleteArtifactOptions.ObjectID, "artifact_id": *deleteArtifactOptions.ArtifactID, } @@ -1226,7 +1235,6 @@ type AliasMetaData struct { PlanID *string `json:"plan_id,omitempty"` } - // UnmarshalAliasMetaData unmarshals an instance of AliasMetaData from the specified map of raw messages. func UnmarshalAliasMetaData(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(AliasMetaData) @@ -1254,7 +1262,6 @@ type Amount struct { Prices []Price `json:"prices,omitempty"` } - // UnmarshalAmount unmarshals an instance of Amount from the specified map of raw messages. func UnmarshalAmount(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Amount) @@ -1292,7 +1299,6 @@ type Artifact struct { Size *int64 `json:"size,omitempty"` } - // UnmarshalArtifact unmarshals an instance of Artifact from the specified map of raw messages. func UnmarshalArtifact(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Artifact) @@ -1329,7 +1335,6 @@ type Artifacts struct { Resources []Artifact `json:"resources,omitempty"` } - // UnmarshalArtifacts unmarshals an instance of Artifacts from the specified map of raw messages. func UnmarshalArtifacts(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Artifacts) @@ -1375,7 +1380,6 @@ type AuditSearchResult struct { Resources []Message `json:"resources,omitempty"` } - // UnmarshalAuditSearchResult unmarshals an instance of AuditSearchResult from the specified map of raw messages. func UnmarshalAuditSearchResult(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(AuditSearchResult) @@ -1428,7 +1432,6 @@ type Broker struct { GUID *string `json:"guid,omitempty"` } - // UnmarshalBroker unmarshals an instance of Broker from the specified map of raw messages. func UnmarshalBroker(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Broker) @@ -1459,7 +1462,6 @@ type Bullets struct { Quantity *int64 `json:"quantity,omitempty"` } - // UnmarshalBullets unmarshals an instance of Bullets from the specified map of raw messages. func UnmarshalBullets(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Bullets) @@ -1530,7 +1532,6 @@ type CfMetaData struct { CfGUID map[string]string `json:"cf_guid,omitempty"` } - // UnmarshalCfMetaData unmarshals an instance of CfMetaData from the specified map of raw messages. func UnmarshalCfMetaData(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(CfMetaData) @@ -1627,7 +1628,6 @@ type Callbacks struct { APIEndpoint map[string]string `json:"api_endpoint,omitempty"` } - // UnmarshalCallbacks unmarshals an instance of Callbacks from the specified map of raw messages. func UnmarshalCallbacks(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Callbacks) @@ -1743,11 +1743,10 @@ type CatalogEntry struct { // object. const ( CatalogEntryKindDashboardConst = "dashboard" - CatalogEntryKindServiceConst = "service" - CatalogEntryKindTemplateConst = "template" + CatalogEntryKindServiceConst = "service" + CatalogEntryKindTemplateConst = "template" ) - // UnmarshalCatalogEntry unmarshals an instance of CatalogEntry from the specified map of raw messages. func UnmarshalCatalogEntry(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(CatalogEntry) @@ -1876,7 +1875,6 @@ type CatalogEntryMetadata struct { Deployment *CatalogEntryMetadataDeployment `json:"deployment,omitempty"` } - // UnmarshalCatalogEntryMetadata unmarshals an instance of CatalogEntryMetadata from the specified map of raw messages. func UnmarshalCatalogEntryMetadata(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(CatalogEntryMetadata) @@ -1970,7 +1968,6 @@ type CatalogEntryMetadataDeployment struct { TargetNetwork *string `json:"target_network,omitempty"` } - // UnmarshalCatalogEntryMetadataDeployment unmarshals an instance of CatalogEntryMetadataDeployment from the specified map of raw messages. func UnmarshalCatalogEntryMetadataDeployment(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(CatalogEntryMetadataDeployment) @@ -2029,7 +2026,6 @@ type CatalogEntryMetadataPricing struct { Metrics []Metrics `json:"metrics,omitempty"` } - // UnmarshalCatalogEntryMetadataPricing unmarshals an instance of CatalogEntryMetadataPricing from the specified map of raw messages. func UnmarshalCatalogEntryMetadataPricing(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(CatalogEntryMetadataPricing) @@ -2057,47 +2053,47 @@ func UnmarshalCatalogEntryMetadataPricing(m map[string]json.RawMessage, result i type CreateCatalogEntryOptions struct { // Programmatic name for this catalog entry, which must be formatted like a CRN segment. See the display name in // OverviewUI for a user-readable name. - Name *string `json:"name" validate:"required"` + Name *string `validate:"required"` // The type of catalog entry, **service**, **template**, **dashboard**, which determines the type and shape of the // object. - Kind *string `json:"kind" validate:"required"` + Kind *string `validate:"required"` // Overview is nested in the top level. The key value pair is `[_language_]overview_ui`. - OverviewUI map[string]Overview `json:"overview_ui" validate:"required"` + OverviewUI map[string]Overview `validate:"required"` // Image annotation for this catalog entry. The image is a URL. - Images *Image `json:"images" validate:"required"` + Images *Image `validate:"required"` // Boolean value that determines the global visibility for the catalog entry, and its children. If it is not enabled, // all plans are disabled. - Disabled *bool `json:"disabled" validate:"required"` + Disabled *bool `validate:"required"` // A list of tags. For example, IBM, 3rd Party, Beta, GA, and Single Tenant. - Tags []string `json:"tags" validate:"required"` + Tags []string `validate:"required"` // Information related to the provider associated with a catalog entry. - Provider *Provider `json:"provider" validate:"required"` + Provider *Provider `validate:"required"` // Catalog entry's unique ID. It's the same across all catalog instances. - ID *string `json:"id" validate:"required"` + ID *string `validate:"required"` // The ID of the parent catalog entry if it exists. - ParentID *string `json:"parent_id,omitempty"` + ParentID *string // Boolean value that determines whether the catalog entry is a group. - Group *bool `json:"group,omitempty"` + Group *bool // Boolean value that describes whether the service is active. - Active *bool `json:"active,omitempty"` + Active *bool // Model used to describe metadata object that can be set. - Metadata *ObjectMetadataSet `json:"metadata,omitempty"` + Metadata *ObjectMetadataSet // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // Allows users to set headers on API requests Headers map[string]string @@ -2108,21 +2104,21 @@ type CreateCatalogEntryOptions struct { // object. const ( CreateCatalogEntryOptionsKindDashboardConst = "dashboard" - CreateCatalogEntryOptionsKindServiceConst = "service" - CreateCatalogEntryOptionsKindTemplateConst = "template" + CreateCatalogEntryOptionsKindServiceConst = "service" + CreateCatalogEntryOptionsKindTemplateConst = "template" ) // NewCreateCatalogEntryOptions : Instantiate CreateCatalogEntryOptions func (*GlobalCatalogV1) NewCreateCatalogEntryOptions(name string, kind string, overviewUI map[string]Overview, images *Image, disabled bool, tags []string, provider *Provider, id string) *CreateCatalogEntryOptions { return &CreateCatalogEntryOptions{ - Name: core.StringPtr(name), - Kind: core.StringPtr(kind), + Name: core.StringPtr(name), + Kind: core.StringPtr(kind), OverviewUI: overviewUI, - Images: images, - Disabled: core.BoolPtr(disabled), - Tags: tags, - Provider: provider, - ID: core.StringPtr(id), + Images: images, + Disabled: core.BoolPtr(disabled), + Tags: tags, + Provider: provider, + ID: core.StringPtr(id), } } @@ -2219,7 +2215,6 @@ type DrMetaData struct { Description *string `json:"description,omitempty"` } - // UnmarshalDrMetaData unmarshals an instance of DrMetaData from the specified map of raw messages. func UnmarshalDrMetaData(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(DrMetaData) @@ -2238,15 +2233,15 @@ func UnmarshalDrMetaData(m map[string]json.RawMessage, result interface{}) (err // DeleteArtifactOptions : The DeleteArtifact options. type DeleteArtifactOptions struct { // The object's unique ID. - ObjectID *string `json:"object_id" validate:"required,ne="` + ObjectID *string `validate:"required,ne="` // The artifact's ID. - ArtifactID *string `json:"artifact_id" validate:"required,ne="` + ArtifactID *string `validate:"required,ne="` // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // Allows users to set headers on API requests Headers map[string]string @@ -2255,7 +2250,7 @@ type DeleteArtifactOptions struct { // NewDeleteArtifactOptions : Instantiate DeleteArtifactOptions func (*GlobalCatalogV1) NewDeleteArtifactOptions(objectID string, artifactID string) *DeleteArtifactOptions { return &DeleteArtifactOptions{ - ObjectID: core.StringPtr(objectID), + ObjectID: core.StringPtr(objectID), ArtifactID: core.StringPtr(artifactID), } } @@ -2287,16 +2282,16 @@ func (options *DeleteArtifactOptions) SetHeaders(param map[string]string) *Delet // DeleteCatalogEntryOptions : The DeleteCatalogEntry options. type DeleteCatalogEntryOptions struct { // The object's unique ID. - ID *string `json:"id" validate:"required,ne="` + ID *string `validate:"required,ne="` // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // This will cause entry to be deleted fully. By default it is archived for two weeks, so that it can be restored if // necessary. - Force *bool `json:"force,omitempty"` + Force *bool // Allows users to set headers on API requests Headers map[string]string @@ -2363,7 +2358,6 @@ type DeploymentBase struct { TargetNetwork *string `json:"target_network,omitempty"` } - // UnmarshalDeploymentBase unmarshals an instance of DeploymentBase from the specified map of raw messages. func UnmarshalDeploymentBase(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(DeploymentBase) @@ -2437,7 +2431,6 @@ type EntrySearchResult struct { Resources []CatalogEntry `json:"resources,omitempty"` } - // UnmarshalEntrySearchResult unmarshals an instance of EntrySearchResult from the specified map of raw messages. func UnmarshalEntrySearchResult(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(EntrySearchResult) @@ -2484,18 +2477,18 @@ func UnmarshalEntrySearchResult(m map[string]json.RawMessage, result interface{} // GetArtifactOptions : The GetArtifact options. type GetArtifactOptions struct { // The object's unique ID. - ObjectID *string `json:"object_id" validate:"required,ne="` + ObjectID *string `validate:"required,ne="` // The artifact's ID. - ArtifactID *string `json:"artifact_id" validate:"required,ne="` + ArtifactID *string `validate:"required,ne="` // The type of the response: or *_/_*. - Accept *string `json:"Accept,omitempty"` + Accept *string // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // Allows users to set headers on API requests Headers map[string]string @@ -2504,7 +2497,7 @@ type GetArtifactOptions struct { // NewGetArtifactOptions : Instantiate GetArtifactOptions func (*GlobalCatalogV1) NewGetArtifactOptions(objectID string, artifactID string) *GetArtifactOptions { return &GetArtifactOptions{ - ObjectID: core.StringPtr(objectID), + ObjectID: core.StringPtr(objectID), ArtifactID: core.StringPtr(artifactID), } } @@ -2542,28 +2535,28 @@ func (options *GetArtifactOptions) SetHeaders(param map[string]string) *GetArtif // GetAuditLogsOptions : The GetAuditLogs options. type GetAuditLogsOptions struct { // The object's unique ID. - ID *string `json:"id" validate:"required,ne="` + ID *string `validate:"required,ne="` // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // Sets the sort order. False is descending. - Ascending *string `json:"ascending,omitempty"` + Ascending *string // Starting time for the logs. If it's descending then the entries will be equal or earlier. The default is latest. For // ascending it will entries equal or later. The default is earliest. It can be either a number or a string. If a // number then it is in the format of Unix timestamps. If it is a string then it is a date in the format // YYYY-MM-DDTHH:MM:SSZ and the time is UTC. The T and the Z are required. For example: 2017-12-24T12:00:00Z for Noon // UTC on Dec 24, 2017. - Startat *string `json:"startat,omitempty"` + Startat *string // Count of number of log entries to skip before returning logs. The default is zero. - Offset *int64 `json:"_offset,omitempty"` + Offset *int64 // Count of number of entries to return. The default is fifty. The maximum value is two hundred. - Limit *int64 `json:"_limit,omitempty"` + Limit *int64 // Allows users to set headers on API requests Headers map[string]string @@ -2621,31 +2614,31 @@ func (options *GetAuditLogsOptions) SetHeaders(param map[string]string) *GetAudi // GetCatalogEntryOptions : The GetCatalogEntry options. type GetCatalogEntryOptions struct { // The catalog entry's unqiue ID. - ID *string `json:"id" validate:"required,ne="` + ID *string `validate:"required,ne="` // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // A GET call by default returns a basic set of properties. To include other properties, you must add this parameter. A // wildcard (`*`) includes all properties for an object, for example `GET /id?include=*`. To include specific metadata // fields, separate each field with a colon (:), for example `GET /id?include=metadata.ui:metadata.pricing`. - Include *string `json:"include,omitempty"` + Include *string // Return the data strings in the specified langauge. By default the strings returned are of the language preferred by // your browser through the Accept-Langauge header, which allows an override of the header. Languages are specified in // standard form, such as `en-us`. To include all languages use a wildcard (*). - Languages *string `json:"languages,omitempty"` + Languages *string // Returns all available fields for all languages. Use the value `?complete=true` as shortcut for // ?include=*&languages=*. - Complete *string `json:"complete,omitempty"` + Complete *bool // Return the children down to the requested depth. Use * to include the entire children tree. If there are more // children than the maximum permitted an error will be returned. Be judicious with this as it can cause a large number // of database accesses and can result in a large amount of data returned. - Depth *int64 `json:"depth,omitempty"` + Depth *int64 // Allows users to set headers on API requests Headers map[string]string @@ -2683,8 +2676,8 @@ func (options *GetCatalogEntryOptions) SetLanguages(languages string) *GetCatalo } // SetComplete : Allow user to set Complete -func (options *GetCatalogEntryOptions) SetComplete(complete string) *GetCatalogEntryOptions { - options.Complete = core.StringPtr(complete) +func (options *GetCatalogEntryOptions) SetComplete(complete bool) *GetCatalogEntryOptions { + options.Complete = core.BoolPtr(complete) return options } @@ -2703,39 +2696,39 @@ func (options *GetCatalogEntryOptions) SetHeaders(param map[string]string) *GetC // GetChildObjectsOptions : The GetChildObjects options. type GetChildObjectsOptions struct { // The parent catalog entry's ID. - ID *string `json:"id" validate:"required,ne="` + ID *string `validate:"required,ne="` // The **kind** of child catalog entries to search for. A wildcard (*) includes all child catalog entries for all // kinds, for example `GET /service_name/_*`. - Kind *string `json:"kind" validate:"required,ne="` + Kind *string `validate:"required,ne="` // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // A colon (:) separated list of properties to include. A GET call by defaults return a limited set of properties. To // include other properties, you must add the include parameter. A wildcard (*) includes all properties. - Include *string `json:"include,omitempty"` + Include *string // A query filter, for example, `q=kind:iaas IBM` will filter on entries of **kind** iaas that has `IBM` in their // name, display name, or description. - Q *string `json:"q,omitempty"` + Q *string // The field on which to sort the output. By default by name. Available fields are **name**, **kind**, and // **provider**. - SortBy *string `json:"sort-by,omitempty"` + SortBy *string // The sort order. The default is false, which is ascending. - Descending *string `json:"descending,omitempty"` + Descending *string // Return the data strings in the specified langauge. By default the strings returned are of the language preferred by // your browser through the Accept-Langauge header. This allows an override of the header. Languages are specified in // standard form, such as `en-us`. To include all languages use the wildcard (*). - Languages *string `json:"languages,omitempty"` + Languages *string // Use the value `?complete=true` as shortcut for ?include=*&languages=*. - Complete *string `json:"complete,omitempty"` + Complete *bool // Allows users to set headers on API requests Headers map[string]string @@ -2744,7 +2737,7 @@ type GetChildObjectsOptions struct { // NewGetChildObjectsOptions : Instantiate GetChildObjectsOptions func (*GlobalCatalogV1) NewGetChildObjectsOptions(id string, kind string) *GetChildObjectsOptions { return &GetChildObjectsOptions{ - ID: core.StringPtr(id), + ID: core.StringPtr(id), Kind: core.StringPtr(kind), } } @@ -2798,8 +2791,8 @@ func (options *GetChildObjectsOptions) SetLanguages(languages string) *GetChildO } // SetComplete : Allow user to set Complete -func (options *GetChildObjectsOptions) SetComplete(complete string) *GetChildObjectsOptions { - options.Complete = core.StringPtr(complete) +func (options *GetChildObjectsOptions) SetComplete(complete bool) *GetChildObjectsOptions { + options.Complete = core.BoolPtr(complete) return options } @@ -2812,12 +2805,12 @@ func (options *GetChildObjectsOptions) SetHeaders(param map[string]string) *GetC // GetPricingOptions : The GetPricing options. type GetPricingOptions struct { // The object's unique ID. - ID *string `json:"id" validate:"required,ne="` + ID *string `validate:"required,ne="` // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // Allows users to set headers on API requests Headers map[string]string @@ -2851,12 +2844,12 @@ func (options *GetPricingOptions) SetHeaders(param map[string]string) *GetPricin // GetVisibilityOptions : The GetVisibility options. type GetVisibilityOptions struct { // The object's unique ID. - ID *string `json:"id" validate:"required,ne="` + ID *string `validate:"required,ne="` // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // Allows users to set headers on API requests Headers map[string]string @@ -2902,7 +2895,6 @@ type Image struct { FeatureImage *string `json:"feature_image,omitempty"` } - // NewImage : Instantiate Image (Generic Model Constructor) func (*GlobalCatalogV1) NewImage(image string) (model *Image, err error) { model = &Image{ @@ -2938,12 +2930,12 @@ func UnmarshalImage(m map[string]json.RawMessage, result interface{}) (err error // ListArtifactsOptions : The ListArtifacts options. type ListArtifactsOptions struct { // The object's unique ID. - ObjectID *string `json:"object_id" validate:"required,ne="` + ObjectID *string `validate:"required,ne="` // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // Allows users to set headers on API requests Headers map[string]string @@ -2979,36 +2971,47 @@ type ListCatalogEntriesOptions struct { // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // A GET call by default returns a basic set of properties. To include other properties, you must add this parameter. A // wildcard (`*`) includes all properties for an object, for example `GET /?include=*`. To include specific metadata // fields, separate each field with a colon (:), for example `GET /?include=metadata.ui:metadata.pricing`. - Include *string `json:"include,omitempty"` + Include *string // Searches the catalog entries for keywords. Add filters to refine your search. A query filter, for example, // `q=kind:iaas service_name rc:true`, filters entries of kind iaas with metadata.service.rc_compatible set to true and // have a service name is in their name, display name, or description. Valid tags are **kind**:, // **tag**:, **rc**:[true|false], **iam**:[true|false], **active**:[true|false], **geo**:, and // **price**:. - Q *string `json:"q,omitempty"` + Q *string // The field on which the output is sorted. Sorts by default by **name** property. Available fields are **name**, // **displayname** (overview_ui.display_name), **kind**, **provider** (provider.name), **sbsindex** // (metadata.ui.side_by_side_index), and the time **created**, and **updated**. - SortBy *string `json:"sort-by,omitempty"` + SortBy *string // Sets the sort order. The default is false, which is ascending. - Descending *string `json:"descending,omitempty"` + Descending *string // Return the data strings in a specified langauge. By default, the strings returned are of the language preferred by // your browser through the Accept-Langauge header, which allows an override of the header. Languages are specified in // standard form, such as `en-us`. To include all languages use a wildcard (*). - Languages *string `json:"languages,omitempty"` + Languages *string + + // Checks to see if a catalog's object is visible, or if it's filtered by service, plan, deployment, or region. Use the + // value `?catalog=true`. If a `200` code is returned, the object is visible. If a `403` code is returned, the object + // is not visible for the user. + Catalog *bool // Returns all available fields for all languages. Use the value `?complete=true` as shortcut for // ?include=*&languages=*. - Complete *string `json:"complete,omitempty"` + Complete *bool + + // Useful for pagination, specifies index (origin 0) of first item to return in response. + Offset *int64 + + // Useful for pagination, specifies the maximum number of items to return in the response. + Limit *int64 // Allows users to set headers on API requests Headers map[string]string @@ -3055,9 +3058,27 @@ func (options *ListCatalogEntriesOptions) SetLanguages(languages string) *ListCa return options } +// SetCatalog : Allow user to set Catalog +func (options *ListCatalogEntriesOptions) SetCatalog(catalog bool) *ListCatalogEntriesOptions { + options.Catalog = core.BoolPtr(catalog) + return options +} + // SetComplete : Allow user to set Complete -func (options *ListCatalogEntriesOptions) SetComplete(complete string) *ListCatalogEntriesOptions { - options.Complete = core.StringPtr(complete) +func (options *ListCatalogEntriesOptions) SetComplete(complete bool) *ListCatalogEntriesOptions { + options.Complete = core.BoolPtr(complete) + return options +} + +// SetOffset : Allow user to set Offset +func (options *ListCatalogEntriesOptions) SetOffset(offset int64) *ListCatalogEntriesOptions { + options.Offset = core.Int64Ptr(offset) + return options +} + +// SetLimit : Allow user to set Limit +func (options *ListCatalogEntriesOptions) SetLimit(limit int64) *ListCatalogEntriesOptions { + options.Limit = core.Int64Ptr(limit) return options } @@ -3103,7 +3124,6 @@ type Message struct { Data map[string]interface{} `json:"data,omitempty"` } - // UnmarshalMessage unmarshals an instance of Message from the specified map of raw messages. func UnmarshalMessage(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Message) @@ -3197,7 +3217,6 @@ type Metrics struct { Amounts []Amount `json:"amounts,omitempty"` } - // UnmarshalMetrics unmarshals an instance of Metrics from the specified map of raw messages. func UnmarshalMetrics(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Metrics) @@ -3302,7 +3321,6 @@ type ObjectMetadataSet struct { Deployment *DeploymentBase `json:"deployment,omitempty"` } - // UnmarshalObjectMetadataSet unmarshals an instance of ObjectMetadataSet from the specified map of raw messages. func UnmarshalObjectMetadataSet(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(ObjectMetadataSet) @@ -3381,13 +3399,12 @@ type Overview struct { FeaturedDescription *string `json:"featured_description,omitempty"` } - // NewOverview : Instantiate Overview (Generic Model Constructor) func (*GlobalCatalogV1) NewOverview(displayName string, longDescription string, description string) (model *Overview, err error) { model = &Overview{ - DisplayName: core.StringPtr(displayName), + DisplayName: core.StringPtr(displayName), LongDescription: core.StringPtr(longDescription), - Description: core.StringPtr(description), + Description: core.StringPtr(description), } err = core.ValidateStruct(model, "required parameters") return @@ -3447,7 +3464,6 @@ type PlanMetaData struct { CfGUID map[string]string `json:"cf_guid,omitempty"` } - // UnmarshalPlanMetaData unmarshals an instance of PlanMetaData from the specified map of raw messages. func UnmarshalPlanMetaData(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(PlanMetaData) @@ -3500,7 +3516,6 @@ type Price struct { Price *float64 `json:"Price,omitempty"` } - // UnmarshalPrice unmarshals an instance of Price from the specified map of raw messages. func UnmarshalPrice(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Price) @@ -3531,7 +3546,6 @@ type PricingGet struct { Metrics []Metrics `json:"metrics,omitempty"` } - // UnmarshalPricingGet unmarshals an instance of PricingGet from the specified map of raw messages. func UnmarshalPricingGet(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(PricingGet) @@ -3567,7 +3581,6 @@ type PricingSet struct { StartingPrice *StartingPrice `json:"starting_price,omitempty"` } - // UnmarshalPricingSet unmarshals an instance of PricingSet from the specified map of raw messages. func UnmarshalPricingSet(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(PricingSet) @@ -3605,12 +3618,11 @@ type Provider struct { Phone *string `json:"phone,omitempty"` } - // NewProvider : Instantiate Provider (Generic Model Constructor) func (*GlobalCatalogV1) NewProvider(email string, name string) (model *Provider, err error) { model = &Provider{ Email: core.StringPtr(email), - Name: core.StringPtr(name), + Name: core.StringPtr(name), } err = core.ValidateStruct(model, "required parameters") return @@ -3646,12 +3658,12 @@ func UnmarshalProvider(m map[string]json.RawMessage, result interface{}) (err er // RestoreCatalogEntryOptions : The RestoreCatalogEntry options. type RestoreCatalogEntryOptions struct { // The catalog entry's unique ID. - ID *string `json:"id" validate:"required,ne="` + ID *string `validate:"required,ne="` // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // Allows users to set headers on API requests Headers map[string]string @@ -3701,7 +3713,6 @@ type SLAMetaData struct { Dr *DrMetaData `json:"dr,omitempty"` } - // UnmarshalSLAMetaData unmarshals an instance of SLAMetaData from the specified map of raw messages. func UnmarshalSLAMetaData(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(SLAMetaData) @@ -3741,7 +3752,6 @@ type SourceMetaData struct { URL *string `json:"url,omitempty"` } - // UnmarshalSourceMetaData unmarshals an instance of SourceMetaData from the specified map of raw messages. func UnmarshalSourceMetaData(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(SourceMetaData) @@ -3776,7 +3786,6 @@ type StartingPrice struct { Amount []Amount `json:"amount,omitempty"` } - // UnmarshalStartingPrice unmarshals an instance of StartingPrice from the specified map of raw messages. func UnmarshalStartingPrice(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(StartingPrice) @@ -3824,7 +3833,6 @@ type Strings struct { Instruction *string `json:"instruction,omitempty"` } - // UnmarshalStrings unmarshals an instance of Strings from the specified map of raw messages. func UnmarshalStrings(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Strings) @@ -3893,7 +3901,6 @@ type TemplateMetaData struct { EnvironmentVariables map[string]string `json:"environment_variables,omitempty"` } - // UnmarshalTemplateMetaData unmarshals an instance of TemplateMetaData from the specified map of raw messages. func UnmarshalTemplateMetaData(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(TemplateMetaData) @@ -3983,7 +3990,6 @@ type UIMetaData struct { NoUpgradeNextStep *bool `json:"no_upgrade_next_step,omitempty"` } - // UnmarshalUIMetaData unmarshals an instance of UIMetaData from the specified map of raw messages. func UnmarshalUIMetaData(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(UIMetaData) @@ -4061,7 +4067,6 @@ type UIMetaMedia struct { Source *Bullets `json:"source,omitempty"` } - // UnmarshalUIMetaMedia unmarshals an instance of UIMetaMedia from the specified map of raw messages. func UnmarshalUIMetaMedia(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(UIMetaMedia) @@ -4128,7 +4133,6 @@ type Urls struct { Apidocsurl *string `json:"apidocsurl,omitempty"` } - // UnmarshalUrls unmarshals an instance of Urls from the specified map of raw messages. func UnmarshalUrls(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Urls) @@ -4187,54 +4191,54 @@ func UnmarshalUrls(m map[string]json.RawMessage, result interface{}) (err error) // UpdateCatalogEntryOptions : The UpdateCatalogEntry options. type UpdateCatalogEntryOptions struct { // The object's unique ID. - ID *string `json:"id" validate:"required,ne="` + ID *string `validate:"required,ne="` // Programmatic name for this catalog entry, which must be formatted like a CRN segment. See the display name in // OverviewUI for a user-readable name. - Name *string `json:"name" validate:"required"` + Name *string `validate:"required"` // The type of catalog entry, **service**, **template**, **dashboard**, which determines the type and shape of the // object. - Kind *string `json:"kind" validate:"required"` + Kind *string `validate:"required"` // Overview is nested in the top level. The key value pair is `[_language_]overview_ui`. - OverviewUI map[string]Overview `json:"overview_ui" validate:"required"` + OverviewUI map[string]Overview `validate:"required"` // Image annotation for this catalog entry. The image is a URL. - Images *Image `json:"images" validate:"required"` + Images *Image `validate:"required"` // Boolean value that determines the global visibility for the catalog entry, and its children. If it is not enabled, // all plans are disabled. - Disabled *bool `json:"disabled" validate:"required"` + Disabled *bool `validate:"required"` // A list of tags. For example, IBM, 3rd Party, Beta, GA, and Single Tenant. - Tags []string `json:"tags" validate:"required"` + Tags []string `validate:"required"` // Information related to the provider associated with a catalog entry. - Provider *Provider `json:"provider" validate:"required"` + Provider *Provider `validate:"required"` // The ID of the parent catalog entry if it exists. - ParentID *string `json:"parent_id,omitempty"` + ParentID *string // Boolean value that determines whether the catalog entry is a group. - Group *bool `json:"group,omitempty"` + Group *bool // Boolean value that describes whether the service is active. - Active *bool `json:"active,omitempty"` + Active *bool // Model used to describe metadata object that can be set. - Metadata *ObjectMetadataSet `json:"metadata,omitempty"` + Metadata *ObjectMetadataSet // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // Reparenting object. In the body set the parent_id to a different parent. Or remove the parent_id field to reparent // to the root of the catalog. If this is not set to 'true' then changing the parent_id in the body of the request will // not be permitted. If this is 'true' and no change to parent_id then this is also error. This is to prevent // accidental changing of parent. - Move *string `json:"move,omitempty"` + Move *string // Allows users to set headers on API requests Headers map[string]string @@ -4245,21 +4249,21 @@ type UpdateCatalogEntryOptions struct { // object. const ( UpdateCatalogEntryOptionsKindDashboardConst = "dashboard" - UpdateCatalogEntryOptionsKindServiceConst = "service" - UpdateCatalogEntryOptionsKindTemplateConst = "template" + UpdateCatalogEntryOptionsKindServiceConst = "service" + UpdateCatalogEntryOptionsKindTemplateConst = "template" ) // NewUpdateCatalogEntryOptions : Instantiate UpdateCatalogEntryOptions func (*GlobalCatalogV1) NewUpdateCatalogEntryOptions(id string, name string, kind string, overviewUI map[string]Overview, images *Image, disabled bool, tags []string, provider *Provider) *UpdateCatalogEntryOptions { return &UpdateCatalogEntryOptions{ - ID: core.StringPtr(id), - Name: core.StringPtr(name), - Kind: core.StringPtr(kind), + ID: core.StringPtr(id), + Name: core.StringPtr(name), + Kind: core.StringPtr(kind), OverviewUI: overviewUI, - Images: images, - Disabled: core.BoolPtr(disabled), - Tags: tags, - Provider: provider, + Images: images, + Disabled: core.BoolPtr(disabled), + Tags: tags, + Provider: provider, } } @@ -4356,21 +4360,21 @@ func (options *UpdateCatalogEntryOptions) SetHeaders(param map[string]string) *U // UpdateVisibilityOptions : The UpdateVisibility options. type UpdateVisibilityOptions struct { // The object's unique ID. - ID *string `json:"id" validate:"required,ne="` + ID *string `validate:"required,ne="` // Allows the visibility to be extenable. - Extendable *bool `json:"extendable,omitempty"` + Extendable *bool // Visibility details related to a catalog entry. - Include *VisibilityDetail `json:"include,omitempty"` + Include *VisibilityDetail // Visibility details related to a catalog entry. - Exclude *VisibilityDetail `json:"exclude,omitempty"` + Exclude *VisibilityDetail // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // Allows users to set headers on API requests Headers map[string]string @@ -4422,20 +4426,20 @@ func (options *UpdateVisibilityOptions) SetHeaders(param map[string]string) *Upd // UploadArtifactOptions : The UploadArtifact options. type UploadArtifactOptions struct { // The object's unique ID. - ObjectID *string `json:"object_id" validate:"required,ne="` + ObjectID *string `validate:"required,ne="` // The artifact's ID. - ArtifactID *string `json:"artifact_id" validate:"required,ne="` + ArtifactID *string `validate:"required,ne="` - Artifact io.ReadCloser `json:"artifact,omitempty"` + Artifact io.ReadCloser // The type of the input. - ContentType *string `json:"Content-Type,omitempty"` + ContentType *string // This changes the scope of the request regardless of the authorization header. Example scopes are `account` and // `global`. `account=global` is reqired if operating with a service ID that has a global admin policy, for example // `GET /?account=global`. - Account *string `json:"account,omitempty"` + Account *string // Allows users to set headers on API requests Headers map[string]string @@ -4444,7 +4448,7 @@ type UploadArtifactOptions struct { // NewUploadArtifactOptions : Instantiate UploadArtifactOptions func (*GlobalCatalogV1) NewUploadArtifactOptions(objectID string, artifactID string) *UploadArtifactOptions { return &UploadArtifactOptions{ - ObjectID: core.StringPtr(objectID), + ObjectID: core.StringPtr(objectID), ArtifactID: core.StringPtr(artifactID), } } @@ -4509,7 +4513,6 @@ type Visibility struct { Approved *bool `json:"approved,omitempty"` } - // UnmarshalVisibility unmarshals an instance of Visibility from the specified map of raw messages. func UnmarshalVisibility(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(Visibility) @@ -4547,7 +4550,6 @@ type VisibilityDetail struct { Accounts *VisibilityDetailAccounts `json:"accounts" validate:"required"` } - // NewVisibilityDetail : Instantiate VisibilityDetail (Generic Model Constructor) func (*GlobalCatalogV1) NewVisibilityDetail(accounts *VisibilityDetailAccounts) (model *VisibilityDetail, err error) { model = &VisibilityDetail{ @@ -4575,7 +4577,6 @@ type VisibilityDetailAccounts struct { Accountid *string `json:"_accountid_,omitempty"` } - // UnmarshalVisibilityDetailAccounts unmarshals an instance of VisibilityDetailAccounts from the specified map of raw messages. func UnmarshalVisibilityDetailAccounts(m map[string]json.RawMessage, result interface{}) (err error) { obj := new(VisibilityDetailAccounts) diff --git a/globalcatalogv1/global_catalog_v1_examples_test.go b/globalcatalogv1/global_catalog_v1_examples_test.go new file mode 100644 index 00000000..afc1d763 --- /dev/null +++ b/globalcatalogv1/global_catalog_v1_examples_test.go @@ -0,0 +1,447 @@ +// +build examples + +/** + * (C) Copyright IBM Corp. 2021. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package globalcatalogv1_test + +import ( + "encoding/json" + "fmt" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/IBM/platform-services-go-sdk/globalcatalogv1" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "io" + "os" +) + +const externalConfigFile = "../global_catalog_v1.env" + +var ( + globalCatalogService *globalcatalogv1.GlobalCatalogV1 + config map[string]string + configLoaded bool = false +) + +func shouldSkipTest() { + if !configLoaded { + Skip("External configuration is not available, skipping tests...") + } +} + +var _ = Describe(`GlobalCatalogV1 Examples Tests`, func() { + Describe(`External configuration`, func() { + It("Successfully load the configuration", func() { + var err error + _, err = os.Stat(externalConfigFile) + if err != nil { + Skip("External configuration file not found, skipping tests: " + err.Error()) + } + + os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile) + config, err = core.GetServiceProperties(globalcatalogv1.DefaultServiceName) + if err != nil { + Skip("Error loading service properties, skipping tests: " + err.Error()) + } + + configLoaded = len(config) > 0 + }) + }) + + Describe(`Client initialization`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It("Successfully construct the service client instance", func() { + var err error + + // begin-common + + globalCatalogServiceOptions := &globalcatalogv1.GlobalCatalogV1Options{} + + globalCatalogService, err = globalcatalogv1.NewGlobalCatalogV1UsingExternalConfig(globalCatalogServiceOptions) + + if err != nil { + panic(err) + } + + // end-common + + Expect(globalCatalogService).ToNot(BeNil()) + }) + }) + + Describe(`GlobalCatalogV1 request examples`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`ListCatalogEntries request example`, func() { + // begin-list_catalog_entries + + listCatalogEntriesOptions := globalCatalogService.NewListCatalogEntriesOptions() + + entrySearchResult, response, err := globalCatalogService.ListCatalogEntries(listCatalogEntriesOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(entrySearchResult, "", " ") + fmt.Println(string(b)) + + // end-list_catalog_entries + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(entrySearchResult).ToNot(BeNil()) + + }) + It(`CreateCatalogEntry request example`, func() { + // begin-create_catalog_entry + + overviewModel := &globalcatalogv1.Overview{ + DisplayName: core.StringPtr("testString"), + LongDescription: core.StringPtr("testString"), + Description: core.StringPtr("testString"), + } + + imageModel := &globalcatalogv1.Image{ + Image: core.StringPtr("testString"), + } + + providerModel := &globalcatalogv1.Provider{ + Email: core.StringPtr("testString"), + Name: core.StringPtr("testString"), + } + + createCatalogEntryOptions := globalCatalogService.NewCreateCatalogEntryOptions( + "testString", + "service", + make(map[string]globalcatalogv1.Overview), + imageModel, + true, + []string{"testString"}, + providerModel, + "testString", + ) + createCatalogEntryOptions.OverviewUI["foo"] = *overviewModel + + catalogEntry, response, err := globalCatalogService.CreateCatalogEntry(createCatalogEntryOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(catalogEntry, "", " ") + fmt.Println(string(b)) + + // end-create_catalog_entry + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(201)) + Expect(catalogEntry).ToNot(BeNil()) + + }) + It(`GetCatalogEntry request example`, func() { + // begin-get_catalog_entry + + getCatalogEntryOptions := globalCatalogService.NewGetCatalogEntryOptions( + "testString", + ) + + catalogEntry, response, err := globalCatalogService.GetCatalogEntry(getCatalogEntryOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(catalogEntry, "", " ") + fmt.Println(string(b)) + + // end-get_catalog_entry + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(catalogEntry).ToNot(BeNil()) + + }) + It(`UpdateCatalogEntry request example`, func() { + // begin-update_catalog_entry + + overviewModel := &globalcatalogv1.Overview{ + DisplayName: core.StringPtr("testString"), + LongDescription: core.StringPtr("testString"), + Description: core.StringPtr("testString"), + } + + imageModel := &globalcatalogv1.Image{ + Image: core.StringPtr("testString"), + } + + providerModel := &globalcatalogv1.Provider{ + Email: core.StringPtr("testString"), + Name: core.StringPtr("testString"), + } + + updateCatalogEntryOptions := globalCatalogService.NewUpdateCatalogEntryOptions( + "testString", + "testString", + "service", + make(map[string]globalcatalogv1.Overview), + imageModel, + true, + []string{"testString"}, + providerModel, + ) + updateCatalogEntryOptions.OverviewUI["foo"] = *overviewModel + + catalogEntry, response, err := globalCatalogService.UpdateCatalogEntry(updateCatalogEntryOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(catalogEntry, "", " ") + fmt.Println(string(b)) + + // end-update_catalog_entry + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(catalogEntry).ToNot(BeNil()) + + }) + It(`GetChildObjects request example`, func() { + // begin-get_child_objects + + getChildObjectsOptions := globalCatalogService.NewGetChildObjectsOptions( + "testString", + "testString", + ) + + entrySearchResult, response, err := globalCatalogService.GetChildObjects(getChildObjectsOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(entrySearchResult, "", " ") + fmt.Println(string(b)) + + // end-get_child_objects + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(entrySearchResult).ToNot(BeNil()) + + }) + It(`RestoreCatalogEntry request example`, func() { + // begin-restore_catalog_entry + + restoreCatalogEntryOptions := globalCatalogService.NewRestoreCatalogEntryOptions( + "testString", + ) + + response, err := globalCatalogService.RestoreCatalogEntry(restoreCatalogEntryOptions) + if err != nil { + panic(err) + } + + // end-restore_catalog_entry + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + + }) + It(`GetVisibility request example`, func() { + // begin-get_visibility + + getVisibilityOptions := globalCatalogService.NewGetVisibilityOptions( + "testString", + ) + + visibility, response, err := globalCatalogService.GetVisibility(getVisibilityOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(visibility, "", " ") + fmt.Println(string(b)) + + // end-get_visibility + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(visibility).ToNot(BeNil()) + + }) + It(`UpdateVisibility request example`, func() { + // begin-update_visibility + + updateVisibilityOptions := globalCatalogService.NewUpdateVisibilityOptions( + "testString", + ) + + response, err := globalCatalogService.UpdateVisibility(updateVisibilityOptions) + if err != nil { + panic(err) + } + + // end-update_visibility + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + + }) + It(`GetPricing request example`, func() { + // begin-get_pricing + + getPricingOptions := globalCatalogService.NewGetPricingOptions( + "testString", + ) + + pricingGet, response, err := globalCatalogService.GetPricing(getPricingOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(pricingGet, "", " ") + fmt.Println(string(b)) + + // end-get_pricing + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(pricingGet).ToNot(BeNil()) + + }) + It(`GetAuditLogs request example`, func() { + // begin-get_audit_logs + + getAuditLogsOptions := globalCatalogService.NewGetAuditLogsOptions( + "testString", + ) + + auditSearchResult, response, err := globalCatalogService.GetAuditLogs(getAuditLogsOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(auditSearchResult, "", " ") + fmt.Println(string(b)) + + // end-get_audit_logs + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(auditSearchResult).ToNot(BeNil()) + + }) + It(`ListArtifacts request example`, func() { + // begin-list_artifacts + + listArtifactsOptions := globalCatalogService.NewListArtifactsOptions( + "testString", + ) + + artifacts, response, err := globalCatalogService.ListArtifacts(listArtifactsOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(artifacts, "", " ") + fmt.Println(string(b)) + + // end-list_artifacts + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(artifacts).ToNot(BeNil()) + + }) + It(`GetArtifact request example`, func() { + // begin-get_artifact + + getArtifactOptions := globalCatalogService.NewGetArtifactOptions( + "testString", + "testString", + ) + + result, response, err := globalCatalogService.GetArtifact(getArtifactOptions) + if err != nil { + panic(err) + } + if result != nil { + defer result.Close() + outFile, err := os.Create("result.out") + if err != nil { panic(err) } + defer outFile.Close() + _, err = io.Copy(outFile, result) + if err != nil { panic(err) } + } + + // end-get_artifact + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(result).ToNot(BeNil()) + + }) + It(`UploadArtifact request example`, func() { + // begin-upload_artifact + + uploadArtifactOptions := globalCatalogService.NewUploadArtifactOptions( + "testString", + "testString", + ) + + response, err := globalCatalogService.UploadArtifact(uploadArtifactOptions) + if err != nil { + panic(err) + } + + // end-upload_artifact + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + + }) + It(`DeleteCatalogEntry request example`, func() { + // begin-delete_catalog_entry + + deleteCatalogEntryOptions := globalCatalogService.NewDeleteCatalogEntryOptions( + "testString", + ) + + response, err := globalCatalogService.DeleteCatalogEntry(deleteCatalogEntryOptions) + if err != nil { + panic(err) + } + + // end-delete_catalog_entry + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(204)) + + }) + It(`DeleteArtifact request example`, func() { + // begin-delete_artifact + + deleteArtifactOptions := globalCatalogService.NewDeleteArtifactOptions( + "testString", + "testString", + ) + + response, err := globalCatalogService.DeleteArtifact(deleteArtifactOptions) + if err != nil { + panic(err) + } + + // end-delete_artifact + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + + }) + }) +}) diff --git a/globalcatalogv1/global_catalog_v1_integration_test.go b/globalcatalogv1/global_catalog_v1_integration_test.go index 07a45858..4e4261f7 100644 --- a/globalcatalogv1/global_catalog_v1_integration_test.go +++ b/globalcatalogv1/global_catalog_v1_integration_test.go @@ -23,14 +23,14 @@ import ( "fmt" "io/ioutil" "log" + "os" "strings" "time" - "github.com/IBM/go-sdk-core/v4/core" + "github.com/IBM/go-sdk-core/v5/core" common "github.com/IBM/platform-services-go-sdk/common" "github.com/IBM/platform-services-go-sdk/globalcatalogv1" - "github.com/joho/godotenv" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -65,6 +65,7 @@ var ( listArtifacts *globalcatalogv1.ListArtifactsOptions getArtifact *globalcatalogv1.GetArtifactOptions deleteArtifact *globalcatalogv1.DeleteArtifactOptions + config map[string]string configLoaded bool = false ) @@ -76,13 +77,19 @@ func shouldSkipTest() { var _ = Describe("Global Catalog - Integration Tests", func() { It("Successfully load the configuration", func() { + var err error + _, err = os.Stat(externalConfigFile) + if err != nil { + Skip("External configuration file not found, skipping tests: " + err.Error()) + } - err := godotenv.Overload(externalConfigFile) - if err == nil { - configLoaded = true - } else { - Skip("External configuration could not be loaded, skipping...") + os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile) + config, err = core.GetServiceProperties(globalcatalogv1.DefaultServiceName) + if err != nil { + Skip("Error loading service properties, skipping tests: " + err.Error()) } + + configLoaded = len(config) > 0 }) It(`Successfully created GlobalCatalogV1 service instance`, func() { @@ -146,7 +153,7 @@ var _ = Describe("Global Catalog - Integration Tests", func() { Expect(err).To(BeNil()) Expect(service).ToNot(BeNil()) - core.SetLogger(core.NewLogger(core.LevelDebug, log.New(GinkgoWriter, "", log.LstdFlags))) + core.SetLogger(core.NewLogger(core.LevelDebug, log.New(GinkgoWriter, "", log.LstdFlags), log.New(GinkgoWriter, "", log.LstdFlags))) service.EnableRetries(4, 30*time.Second) overviewUi[en] = *overview @@ -328,6 +335,8 @@ var _ = Describe("Global Catalog - Integration Tests", func() { result, detailedResponse, err := service.ListCatalogEntries(defaultList) Expect(err).To(BeNil()) Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(result).ToNot(BeNil()) + fmt.Fprintf(GinkgoWriter, "ListCatalogEntries() result:\n%s", common.ToJSON(result)) Expect(result.Resources).NotTo(BeNil()) Expect(len(result.Resources)).NotTo(BeZero()) }) diff --git a/globalcatalogv1/global_catalog_v1_suite_test.go b/globalcatalogv1/global_catalog_v1_suite_test.go index 2294e413..28399f53 100644 --- a/globalcatalogv1/global_catalog_v1_suite_test.go +++ b/globalcatalogv1/global_catalog_v1_suite_test.go @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2020. + * (C) Copyright IBM Corp. 2021. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/globalcatalogv1/global_catalog_v1_test.go b/globalcatalogv1/global_catalog_v1_test.go index 7c3d1b52..2b28865c 100644 --- a/globalcatalogv1/global_catalog_v1_test.go +++ b/globalcatalogv1/global_catalog_v1_test.go @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2020. + * (C) Copyright IBM Corp. 2021. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import ( "bytes" "context" "fmt" - "github.com/IBM/go-sdk-core/v4/core" + "github.com/IBM/go-sdk-core/v5/core" "github.com/IBM/platform-services-go-sdk/globalcatalogv1" "github.com/go-openapi/strfmt" . "github.com/onsi/ginkgo" @@ -174,19 +174,15 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(listCatalogEntriesPath)) Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["include"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["q"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["sort-by"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["descending"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["languages"]).To(Equal([]string{"testString"})) - - Expect(req.URL.Query()["complete"]).To(Equal([]string{"testString"})) - + // TODO: Add check for catalog query parameter + // TODO: Add check for complete query parameter + Expect(req.URL.Query()["_offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(200))})) res.Header().Set("Content-type", "application/json") res.WriteHeader(200) fmt.Fprintf(res, `} this is not valid json {`) @@ -208,7 +204,10 @@ var _ = Describe(`GlobalCatalogV1`, func() { listCatalogEntriesOptionsModel.SortBy = core.StringPtr("testString") listCatalogEntriesOptionsModel.Descending = core.StringPtr("testString") listCatalogEntriesOptionsModel.Languages = core.StringPtr("testString") - listCatalogEntriesOptionsModel.Complete = core.StringPtr("testString") + listCatalogEntriesOptionsModel.Catalog = core.BoolPtr(true) + listCatalogEntriesOptionsModel.Complete = core.BoolPtr(true) + listCatalogEntriesOptionsModel.Offset = core.Int64Ptr(int64(38)) + listCatalogEntriesOptionsModel.Limit = core.Int64Ptr(int64(200)) listCatalogEntriesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Expect response parsing to fail since we are receiving a text/plain response result, response, operationErr := globalCatalogService.ListCatalogEntries(listCatalogEntriesOptionsModel) @@ -231,10 +230,8 @@ var _ = Describe(`GlobalCatalogV1`, func() { Describe(`ListCatalogEntries(listCatalogEntriesOptions *ListCatalogEntriesOptions)`, func() { listCatalogEntriesPath := "/" - var serverSleepTime time.Duration - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with timeout`, func() { BeforeEach(func() { - serverSleepTime = 0 testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -243,29 +240,25 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["include"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["q"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["sort-by"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["descending"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["languages"]).To(Equal([]string{"testString"})) - - Expect(req.URL.Query()["complete"]).To(Equal([]string{"testString"})) - + // TODO: Add check for catalog query parameter + // TODO: Add check for complete query parameter + Expect(req.URL.Query()["_offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(200))})) // Sleep a short time to support a timeout test - time.Sleep(serverSleepTime) + time.Sleep(100 * time.Millisecond) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"offset": 6, "limit": 5, "count": 5, "resource_count": 13, "first": "First", "last": "Last", "prev": "Prev", "next": "Next", "resources": [{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00", "effective_until": "2019-01-01T12:00:00", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00", "updated": "2019-01-01T12:00:00"}]}`) + fmt.Fprintf(res, "%s", `{"offset": 6, "limit": 5, "count": 5, "resource_count": 13, "first": "First", "last": "Last", "prev": "Prev", "next": "Next", "resources": [{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00.000Z", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00.000Z", "updated": "2019-01-01T12:00:00.000Z"}]}`) })) }) - It(`Invoke ListCatalogEntries successfully`, func() { + It(`Invoke ListCatalogEntries successfully with retries`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ URL: testServer.URL, Authenticator: &core.NoAuthAuthenticator{}, @@ -274,12 +267,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(globalCatalogService).ToNot(BeNil()) globalCatalogService.EnableRetries(0, 0) - // Invoke operation with nil options model (negative test) - result, response, operationErr := globalCatalogService.ListCatalogEntries(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct an instance of the ListCatalogEntriesOptions model listCatalogEntriesOptionsModel := new(globalcatalogv1.ListCatalogEntriesOptions) listCatalogEntriesOptionsModel.Account = core.StringPtr("testString") @@ -288,27 +275,22 @@ var _ = Describe(`GlobalCatalogV1`, func() { listCatalogEntriesOptionsModel.SortBy = core.StringPtr("testString") listCatalogEntriesOptionsModel.Descending = core.StringPtr("testString") listCatalogEntriesOptionsModel.Languages = core.StringPtr("testString") - listCatalogEntriesOptionsModel.Complete = core.StringPtr("testString") + listCatalogEntriesOptionsModel.Catalog = core.BoolPtr(true) + listCatalogEntriesOptionsModel.Complete = core.BoolPtr(true) + listCatalogEntriesOptionsModel.Offset = core.Int64Ptr(int64(38)) + listCatalogEntriesOptionsModel.Limit = core.Int64Ptr(int64(200)) listCatalogEntriesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with valid options model (positive test) - result, response, operationErr = globalCatalogService.ListCatalogEntries(listCatalogEntriesOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - // Invoke operation with a Context to test a timeout error ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.ListCatalogEntriesWithContext(ctx, listCatalogEntriesOptionsModel) + _, _, operationErr := globalCatalogService.ListCatalogEntriesWithContext(ctx, listCatalogEntriesOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) // Disable retries and test again globalCatalogService.DisableRetries() - result, response, operationErr = globalCatalogService.ListCatalogEntries(listCatalogEntriesOptionsModel) + result, response, operationErr := globalCatalogService.ListCatalogEntries(listCatalogEntriesOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) Expect(result).ToNot(BeNil()) @@ -316,11 +298,73 @@ var _ = Describe(`GlobalCatalogV1`, func() { // Re-test the timeout error with retries disabled ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc2() - serverSleepTime = 100 * time.Millisecond _, _, operationErr = globalCatalogService.ListCatalogEntriesWithContext(ctx, listCatalogEntriesOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listCatalogEntriesPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["include"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["q"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["sort-by"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["descending"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["languages"]).To(Equal([]string{"testString"})) + // TODO: Add check for catalog query parameter + // TODO: Add check for complete query parameter + Expect(req.URL.Query()["_offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(200))})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"offset": 6, "limit": 5, "count": 5, "resource_count": 13, "first": "First", "last": "Last", "prev": "Prev", "next": "Next", "resources": [{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00.000Z", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00.000Z", "updated": "2019-01-01T12:00:00.000Z"}]}`) + })) + }) + It(`Invoke ListCatalogEntries successfully`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := globalCatalogService.ListCatalogEntries(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListCatalogEntriesOptions model + listCatalogEntriesOptionsModel := new(globalcatalogv1.ListCatalogEntriesOptions) + listCatalogEntriesOptionsModel.Account = core.StringPtr("testString") + listCatalogEntriesOptionsModel.Include = core.StringPtr("testString") + listCatalogEntriesOptionsModel.Q = core.StringPtr("testString") + listCatalogEntriesOptionsModel.SortBy = core.StringPtr("testString") + listCatalogEntriesOptionsModel.Descending = core.StringPtr("testString") + listCatalogEntriesOptionsModel.Languages = core.StringPtr("testString") + listCatalogEntriesOptionsModel.Catalog = core.BoolPtr(true) + listCatalogEntriesOptionsModel.Complete = core.BoolPtr(true) + listCatalogEntriesOptionsModel.Offset = core.Int64Ptr(int64(38)) + listCatalogEntriesOptionsModel.Limit = core.Int64Ptr(int64(200)) + listCatalogEntriesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = globalCatalogService.ListCatalogEntries(listCatalogEntriesOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) It(`Invoke ListCatalogEntries with error: Operation request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -338,7 +382,10 @@ var _ = Describe(`GlobalCatalogV1`, func() { listCatalogEntriesOptionsModel.SortBy = core.StringPtr("testString") listCatalogEntriesOptionsModel.Descending = core.StringPtr("testString") listCatalogEntriesOptionsModel.Languages = core.StringPtr("testString") - listCatalogEntriesOptionsModel.Complete = core.StringPtr("testString") + listCatalogEntriesOptionsModel.Catalog = core.BoolPtr(true) + listCatalogEntriesOptionsModel.Complete = core.BoolPtr(true) + listCatalogEntriesOptionsModel.Offset = core.Int64Ptr(int64(38)) + listCatalogEntriesOptionsModel.Limit = core.Int64Ptr(int64(200)) listCatalogEntriesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := globalCatalogService.SetServiceURL("") @@ -365,7 +412,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(createCatalogEntryPath)) Expect(req.Method).To(Equal("POST")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - res.Header().Set("Content-type", "application/json") res.WriteHeader(201) fmt.Fprintf(res, `} this is not valid json {`) @@ -633,10 +679,8 @@ var _ = Describe(`GlobalCatalogV1`, func() { Describe(`CreateCatalogEntry(createCatalogEntryOptions *CreateCatalogEntryOptions)`, func() { createCatalogEntryPath := "/" - var serverSleepTime time.Duration - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with timeout`, func() { BeforeEach(func() { - serverSleepTime = 0 testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -661,17 +705,16 @@ var _ = Describe(`GlobalCatalogV1`, func() { fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - // Sleep a short time to support a timeout test - time.Sleep(serverSleepTime) + time.Sleep(100 * time.Millisecond) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(201) - fmt.Fprintf(res, "%s", `{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00", "effective_until": "2019-01-01T12:00:00", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00", "updated": "2019-01-01T12:00:00"}`) + fmt.Fprintf(res, "%s", `{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00.000Z", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00.000Z", "updated": "2019-01-01T12:00:00.000Z"}`) })) }) - It(`Invoke CreateCatalogEntry successfully`, func() { + It(`Invoke CreateCatalogEntry successfully with retries`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ URL: testServer.URL, Authenticator: &core.NoAuthAuthenticator{}, @@ -680,12 +723,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(globalCatalogService).ToNot(BeNil()) globalCatalogService.EnableRetries(0, 0) - // Invoke operation with nil options model (negative test) - result, response, operationErr := globalCatalogService.CreateCatalogEntry(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct an instance of the Overview model overviewModel := new(globalcatalogv1.Overview) overviewModel.DisplayName = core.StringPtr("testString") @@ -920,24 +957,16 @@ var _ = Describe(`GlobalCatalogV1`, func() { createCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} createCatalogEntryOptionsModel.OverviewUI["foo"] = *overviewModel - // Invoke operation with valid options model (positive test) - result, response, operationErr = globalCatalogService.CreateCatalogEntry(createCatalogEntryOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - // Invoke operation with a Context to test a timeout error ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.CreateCatalogEntryWithContext(ctx, createCatalogEntryOptionsModel) + _, _, operationErr := globalCatalogService.CreateCatalogEntryWithContext(ctx, createCatalogEntryOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) // Disable retries and test again globalCatalogService.DisableRetries() - result, response, operationErr = globalCatalogService.CreateCatalogEntry(createCatalogEntryOptionsModel) + result, response, operationErr := globalCatalogService.CreateCatalogEntry(createCatalogEntryOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) Expect(result).ToNot(BeNil()) @@ -945,13 +974,47 @@ var _ = Describe(`GlobalCatalogV1`, func() { // Re-test the timeout error with retries disabled ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc2() - serverSleepTime = 100 * time.Millisecond _, _, operationErr = globalCatalogService.CreateCatalogEntryWithContext(ctx, createCatalogEntryOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) }) - It(`Invoke CreateCatalogEntry with error: Operation validation and request error`, func() { + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(createCatalogEntryPath)) + Expect(req.Method).To(Equal("POST")) + + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(201) + fmt.Fprintf(res, "%s", `{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00.000Z", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00.000Z", "updated": "2019-01-01T12:00:00.000Z"}`) + })) + }) + It(`Invoke CreateCatalogEntry successfully`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ URL: testServer.URL, Authenticator: &core.NoAuthAuthenticator{}, @@ -959,6 +1022,12 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(serviceErr).To(BeNil()) Expect(globalCatalogService).ToNot(BeNil()) + // Invoke operation with nil options model (negative test) + result, response, operationErr := globalCatalogService.CreateCatalogEntry(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct an instance of the Overview model overviewModel := new(globalcatalogv1.Overview) overviewModel.DisplayName = core.StringPtr("testString") @@ -1192,53 +1261,15 @@ var _ = Describe(`GlobalCatalogV1`, func() { createCatalogEntryOptionsModel.Account = core.StringPtr("testString") createCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} createCatalogEntryOptionsModel.OverviewUI["foo"] = *overviewModel - // Invoke operation with empty URL (negative test) - err := globalCatalogService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := globalCatalogService.CreateCatalogEntry(createCatalogEntryOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct a second instance of the CreateCatalogEntryOptions model with no property values - createCatalogEntryOptionsModelNew := new(globalcatalogv1.CreateCatalogEntryOptions) - // Invoke operation with invalid model (negative test) - result, response, operationErr = globalCatalogService.CreateCatalogEntry(createCatalogEntryOptionsModelNew) - Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`GetCatalogEntry(getCatalogEntryOptions *GetCatalogEntryOptions) - Operation response error`, func() { - getCatalogEntryPath := "/testString" - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() - - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(getCatalogEntryPath)) - Expect(req.Method).To(Equal("GET")) - Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - - Expect(req.URL.Query()["include"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["languages"]).To(Equal([]string{"testString"})) - - Expect(req.URL.Query()["complete"]).To(Equal([]string{"testString"})) - - Expect(req.URL.Query()["depth"]).To(Equal([]string{fmt.Sprint(int64(38))})) + // Invoke operation with valid options model (positive test) + result, response, operationErr = globalCatalogService.CreateCatalogEntry(createCatalogEntryOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) - })) }) - It(`Invoke GetCatalogEntry with error: Operation response processing error`, func() { + It(`Invoke CreateCatalogEntry with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ URL: testServer.URL, Authenticator: &core.NoAuthAuthenticator{}, @@ -1246,153 +1277,744 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(serviceErr).To(BeNil()) Expect(globalCatalogService).ToNot(BeNil()) - // Construct an instance of the GetCatalogEntryOptions model - getCatalogEntryOptionsModel := new(globalcatalogv1.GetCatalogEntryOptions) - getCatalogEntryOptionsModel.ID = core.StringPtr("testString") - getCatalogEntryOptionsModel.Account = core.StringPtr("testString") - getCatalogEntryOptionsModel.Include = core.StringPtr("testString") - getCatalogEntryOptionsModel.Languages = core.StringPtr("testString") - getCatalogEntryOptionsModel.Complete = core.StringPtr("testString") - getCatalogEntryOptionsModel.Depth = core.Int64Ptr(int64(38)) - getCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Expect response parsing to fail since we are receiving a text/plain response - result, response, operationErr := globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) + // Construct an instance of the Overview model + overviewModel := new(globalcatalogv1.Overview) + overviewModel.DisplayName = core.StringPtr("testString") + overviewModel.LongDescription = core.StringPtr("testString") + overviewModel.Description = core.StringPtr("testString") + overviewModel.FeaturedDescription = core.StringPtr("testString") - // Enable retries and test again - globalCatalogService.EnableRetries(0, 0) - result, response, operationErr = globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) + // Construct an instance of the Image model + imageModel := new(globalcatalogv1.Image) + imageModel.Image = core.StringPtr("testString") + imageModel.SmallImage = core.StringPtr("testString") + imageModel.MediumImage = core.StringPtr("testString") + imageModel.FeatureImage = core.StringPtr("testString") - Describe(`GetCatalogEntry(getCatalogEntryOptions *GetCatalogEntryOptions)`, func() { - getCatalogEntryPath := "/testString" - var serverSleepTime time.Duration - Context(`Using mock server endpoint`, func() { - BeforeEach(func() { - serverSleepTime = 0 - testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { - defer GinkgoRecover() + // Construct an instance of the Provider model + providerModel := new(globalcatalogv1.Provider) + providerModel.Email = core.StringPtr("testString") + providerModel.Name = core.StringPtr("testString") + providerModel.Contact = core.StringPtr("testString") + providerModel.SupportEmail = core.StringPtr("testString") + providerModel.Phone = core.StringPtr("testString") - // Verify the contents of the request - Expect(req.URL.EscapedPath()).To(Equal(getCatalogEntryPath)) - Expect(req.Method).To(Equal("GET")) + // Construct an instance of the CfMetaData model + cfMetaDataModel := new(globalcatalogv1.CfMetaData) + cfMetaDataModel.Type = core.StringPtr("testString") + cfMetaDataModel.IamCompatible = core.BoolPtr(true) + cfMetaDataModel.UniqueAPIKey = core.BoolPtr(true) + cfMetaDataModel.Provisionable = core.BoolPtr(true) + cfMetaDataModel.Bindable = core.BoolPtr(true) + cfMetaDataModel.AsyncProvisioningSupported = core.BoolPtr(true) + cfMetaDataModel.AsyncUnprovisioningSupported = core.BoolPtr(true) + cfMetaDataModel.Requires = []string{"testString"} + cfMetaDataModel.PlanUpdateable = core.BoolPtr(true) + cfMetaDataModel.State = core.StringPtr("testString") + cfMetaDataModel.ServiceCheckEnabled = core.BoolPtr(true) + cfMetaDataModel.TestCheckInterval = core.Int64Ptr(int64(38)) + cfMetaDataModel.ServiceKeySupported = core.BoolPtr(true) + cfMetaDataModel.CfGUID = make(map[string]string) + + // Construct an instance of the PlanMetaData model + planMetaDataModel := new(globalcatalogv1.PlanMetaData) + planMetaDataModel.Bindable = core.BoolPtr(true) + planMetaDataModel.Reservable = core.BoolPtr(true) + planMetaDataModel.AllowInternalUsers = core.BoolPtr(true) + planMetaDataModel.AsyncProvisioningSupported = core.BoolPtr(true) + planMetaDataModel.AsyncUnprovisioningSupported = core.BoolPtr(true) + planMetaDataModel.TestCheckInterval = core.Int64Ptr(int64(38)) + planMetaDataModel.SingleScopeInstance = core.StringPtr("testString") + planMetaDataModel.ServiceCheckEnabled = core.BoolPtr(true) + planMetaDataModel.CfGUID = make(map[string]string) + + // Construct an instance of the AliasMetaData model + aliasMetaDataModel := new(globalcatalogv1.AliasMetaData) + aliasMetaDataModel.Type = core.StringPtr("testString") + aliasMetaDataModel.PlanID = core.StringPtr("testString") + + // Construct an instance of the SourceMetaData model + sourceMetaDataModel := new(globalcatalogv1.SourceMetaData) + sourceMetaDataModel.Path = core.StringPtr("testString") + sourceMetaDataModel.Type = core.StringPtr("testString") + sourceMetaDataModel.URL = core.StringPtr("testString") + + // Construct an instance of the TemplateMetaData model + templateMetaDataModel := new(globalcatalogv1.TemplateMetaData) + templateMetaDataModel.Services = []string{"testString"} + templateMetaDataModel.DefaultMemory = core.Int64Ptr(int64(38)) + templateMetaDataModel.StartCmd = core.StringPtr("testString") + templateMetaDataModel.Source = sourceMetaDataModel + templateMetaDataModel.RuntimeCatalogID = core.StringPtr("testString") + templateMetaDataModel.CfRuntimeID = core.StringPtr("testString") + templateMetaDataModel.TemplateID = core.StringPtr("testString") + templateMetaDataModel.ExecutableFile = core.StringPtr("testString") + templateMetaDataModel.Buildpack = core.StringPtr("testString") + templateMetaDataModel.EnvironmentVariables = make(map[string]string) + + // Construct an instance of the Bullets model + bulletsModel := new(globalcatalogv1.Bullets) + bulletsModel.Title = core.StringPtr("testString") + bulletsModel.Description = core.StringPtr("testString") + bulletsModel.Icon = core.StringPtr("testString") + bulletsModel.Quantity = core.Int64Ptr(int64(38)) + + // Construct an instance of the UIMetaMedia model + uiMetaMediaModel := new(globalcatalogv1.UIMetaMedia) + uiMetaMediaModel.Caption = core.StringPtr("testString") + uiMetaMediaModel.ThumbnailURL = core.StringPtr("testString") + uiMetaMediaModel.Type = core.StringPtr("testString") + uiMetaMediaModel.URL = core.StringPtr("testString") + uiMetaMediaModel.Source = bulletsModel + + // Construct an instance of the Strings model + stringsModel := new(globalcatalogv1.Strings) + stringsModel.Bullets = []globalcatalogv1.Bullets{*bulletsModel} + stringsModel.Media = []globalcatalogv1.UIMetaMedia{*uiMetaMediaModel} + stringsModel.NotCreatableMsg = core.StringPtr("testString") + stringsModel.NotCreatableRobotMsg = core.StringPtr("testString") + stringsModel.DeprecationWarning = core.StringPtr("testString") + stringsModel.PopupWarningMessage = core.StringPtr("testString") + stringsModel.Instruction = core.StringPtr("testString") + + // Construct an instance of the Urls model + urlsModel := new(globalcatalogv1.Urls) + urlsModel.DocURL = core.StringPtr("testString") + urlsModel.InstructionsURL = core.StringPtr("testString") + urlsModel.APIURL = core.StringPtr("testString") + urlsModel.CreateURL = core.StringPtr("testString") + urlsModel.SdkDownloadURL = core.StringPtr("testString") + urlsModel.TermsURL = core.StringPtr("testString") + urlsModel.CustomCreatePageURL = core.StringPtr("testString") + urlsModel.CatalogDetailsURL = core.StringPtr("testString") + urlsModel.DeprecationDocURL = core.StringPtr("testString") + urlsModel.DashboardURL = core.StringPtr("testString") + urlsModel.RegistrationURL = core.StringPtr("testString") + urlsModel.Apidocsurl = core.StringPtr("testString") + + // Construct an instance of the UIMetaData model + uiMetaDataModel := new(globalcatalogv1.UIMetaData) + uiMetaDataModel.Strings = make(map[string]globalcatalogv1.Strings) + uiMetaDataModel.Urls = urlsModel + uiMetaDataModel.EmbeddableDashboard = core.StringPtr("testString") + uiMetaDataModel.EmbeddableDashboardFullWidth = core.BoolPtr(true) + uiMetaDataModel.NavigationOrder = []string{"testString"} + uiMetaDataModel.NotCreatable = core.BoolPtr(true) + uiMetaDataModel.PrimaryOfferingID = core.StringPtr("testString") + uiMetaDataModel.AccessibleDuringProvision = core.BoolPtr(true) + uiMetaDataModel.SideBySideIndex = core.Int64Ptr(int64(38)) + uiMetaDataModel.EndOfServiceTime = CreateMockDateTime() + uiMetaDataModel.Hidden = core.BoolPtr(true) + uiMetaDataModel.HideLiteMetering = core.BoolPtr(true) + uiMetaDataModel.NoUpgradeNextStep = core.BoolPtr(true) + uiMetaDataModel.Strings["foo"] = *stringsModel + + // Construct an instance of the DrMetaData model + drMetaDataModel := new(globalcatalogv1.DrMetaData) + drMetaDataModel.Dr = core.BoolPtr(true) + drMetaDataModel.Description = core.StringPtr("testString") + + // Construct an instance of the SLAMetaData model + slaMetaDataModel := new(globalcatalogv1.SLAMetaData) + slaMetaDataModel.Terms = core.StringPtr("testString") + slaMetaDataModel.Tenancy = core.StringPtr("testString") + slaMetaDataModel.Provisioning = core.StringPtr("testString") + slaMetaDataModel.Responsiveness = core.StringPtr("testString") + slaMetaDataModel.Dr = drMetaDataModel + + // Construct an instance of the Callbacks model + callbacksModel := new(globalcatalogv1.Callbacks) + callbacksModel.ControllerURL = core.StringPtr("testString") + callbacksModel.BrokerURL = core.StringPtr("testString") + callbacksModel.BrokerProxyURL = core.StringPtr("testString") + callbacksModel.DashboardURL = core.StringPtr("testString") + callbacksModel.DashboardDataURL = core.StringPtr("testString") + callbacksModel.DashboardDetailTabURL = core.StringPtr("testString") + callbacksModel.DashboardDetailTabExtURL = core.StringPtr("testString") + callbacksModel.ServiceMonitorAPI = core.StringPtr("testString") + callbacksModel.ServiceMonitorApp = core.StringPtr("testString") + callbacksModel.APIEndpoint = make(map[string]string) + + // Construct an instance of the Price model + priceModel := new(globalcatalogv1.Price) + priceModel.QuantityTier = core.Int64Ptr(int64(38)) + priceModel.Price = core.Float64Ptr(float64(72.5)) + + // Construct an instance of the Amount model + amountModel := new(globalcatalogv1.Amount) + amountModel.Country = core.StringPtr("testString") + amountModel.Currency = core.StringPtr("testString") + amountModel.Prices = []globalcatalogv1.Price{*priceModel} + + // Construct an instance of the StartingPrice model + startingPriceModel := new(globalcatalogv1.StartingPrice) + startingPriceModel.PlanID = core.StringPtr("testString") + startingPriceModel.DeploymentID = core.StringPtr("testString") + startingPriceModel.Unit = core.StringPtr("testString") + startingPriceModel.Amount = []globalcatalogv1.Amount{*amountModel} + + // Construct an instance of the PricingSet model + pricingSetModel := new(globalcatalogv1.PricingSet) + pricingSetModel.Type = core.StringPtr("testString") + pricingSetModel.Origin = core.StringPtr("testString") + pricingSetModel.StartingPrice = startingPriceModel + + // Construct an instance of the Broker model + brokerModel := new(globalcatalogv1.Broker) + brokerModel.Name = core.StringPtr("testString") + brokerModel.GUID = core.StringPtr("testString") + + // Construct an instance of the DeploymentBase model + deploymentBaseModel := new(globalcatalogv1.DeploymentBase) + deploymentBaseModel.Location = core.StringPtr("testString") + deploymentBaseModel.LocationURL = core.StringPtr("testString") + deploymentBaseModel.OriginalLocation = core.StringPtr("testString") + deploymentBaseModel.TargetCRN = core.StringPtr("testString") + deploymentBaseModel.ServiceCRN = core.StringPtr("testString") + deploymentBaseModel.MccpID = core.StringPtr("testString") + deploymentBaseModel.Broker = brokerModel + deploymentBaseModel.SupportsRcMigration = core.BoolPtr(true) + deploymentBaseModel.TargetNetwork = core.StringPtr("testString") + + // Construct an instance of the ObjectMetadataSet model + objectMetadataSetModel := new(globalcatalogv1.ObjectMetadataSet) + objectMetadataSetModel.RcCompatible = core.BoolPtr(true) + objectMetadataSetModel.Service = cfMetaDataModel + objectMetadataSetModel.Plan = planMetaDataModel + objectMetadataSetModel.Alias = aliasMetaDataModel + objectMetadataSetModel.Template = templateMetaDataModel + objectMetadataSetModel.UI = uiMetaDataModel + objectMetadataSetModel.Compliance = []string{"testString"} + objectMetadataSetModel.SLA = slaMetaDataModel + objectMetadataSetModel.Callbacks = callbacksModel + objectMetadataSetModel.OriginalName = core.StringPtr("testString") + objectMetadataSetModel.Version = core.StringPtr("testString") + objectMetadataSetModel.Other = make(map[string]interface{}) + objectMetadataSetModel.Pricing = pricingSetModel + objectMetadataSetModel.Deployment = deploymentBaseModel + + // Construct an instance of the CreateCatalogEntryOptions model + createCatalogEntryOptionsModel := new(globalcatalogv1.CreateCatalogEntryOptions) + createCatalogEntryOptionsModel.Name = core.StringPtr("testString") + createCatalogEntryOptionsModel.Kind = core.StringPtr("service") + createCatalogEntryOptionsModel.OverviewUI = make(map[string]globalcatalogv1.Overview) + createCatalogEntryOptionsModel.Images = imageModel + createCatalogEntryOptionsModel.Disabled = core.BoolPtr(true) + createCatalogEntryOptionsModel.Tags = []string{"testString"} + createCatalogEntryOptionsModel.Provider = providerModel + createCatalogEntryOptionsModel.ID = core.StringPtr("testString") + createCatalogEntryOptionsModel.ParentID = core.StringPtr("testString") + createCatalogEntryOptionsModel.Group = core.BoolPtr(true) + createCatalogEntryOptionsModel.Active = core.BoolPtr(true) + createCatalogEntryOptionsModel.Metadata = objectMetadataSetModel + createCatalogEntryOptionsModel.Account = core.StringPtr("testString") + createCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + createCatalogEntryOptionsModel.OverviewUI["foo"] = *overviewModel + // Invoke operation with empty URL (negative test) + err := globalCatalogService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := globalCatalogService.CreateCatalogEntry(createCatalogEntryOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the CreateCatalogEntryOptions model with no property values + createCatalogEntryOptionsModelNew := new(globalcatalogv1.CreateCatalogEntryOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = globalCatalogService.CreateCatalogEntry(createCatalogEntryOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetCatalogEntry(getCatalogEntryOptions *GetCatalogEntryOptions) - Operation response error`, func() { + getCatalogEntryPath := "/testString" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getCatalogEntryPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["include"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["languages"]).To(Equal([]string{"testString"})) + // TODO: Add check for complete query parameter + Expect(req.URL.Query()["depth"]).To(Equal([]string{fmt.Sprint(int64(38))})) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetCatalogEntry with error: Operation response processing error`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + + // Construct an instance of the GetCatalogEntryOptions model + getCatalogEntryOptionsModel := new(globalcatalogv1.GetCatalogEntryOptions) + getCatalogEntryOptionsModel.ID = core.StringPtr("testString") + getCatalogEntryOptionsModel.Account = core.StringPtr("testString") + getCatalogEntryOptionsModel.Include = core.StringPtr("testString") + getCatalogEntryOptionsModel.Languages = core.StringPtr("testString") + getCatalogEntryOptionsModel.Complete = core.BoolPtr(true) + getCatalogEntryOptionsModel.Depth = core.Int64Ptr(int64(38)) + getCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + globalCatalogService.EnableRetries(0, 0) + result, response, operationErr = globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`GetCatalogEntry(getCatalogEntryOptions *GetCatalogEntryOptions)`, func() { + getCatalogEntryPath := "/testString" + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getCatalogEntryPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["include"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["languages"]).To(Equal([]string{"testString"})) + // TODO: Add check for complete query parameter + Expect(req.URL.Query()["depth"]).To(Equal([]string{fmt.Sprint(int64(38))})) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00.000Z", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00.000Z", "updated": "2019-01-01T12:00:00.000Z"}`) + })) + }) + It(`Invoke GetCatalogEntry successfully with retries`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + globalCatalogService.EnableRetries(0, 0) - Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + // Construct an instance of the GetCatalogEntryOptions model + getCatalogEntryOptionsModel := new(globalcatalogv1.GetCatalogEntryOptions) + getCatalogEntryOptionsModel.ID = core.StringPtr("testString") + getCatalogEntryOptionsModel.Account = core.StringPtr("testString") + getCatalogEntryOptionsModel.Include = core.StringPtr("testString") + getCatalogEntryOptionsModel.Languages = core.StringPtr("testString") + getCatalogEntryOptionsModel.Complete = core.BoolPtr(true) + getCatalogEntryOptionsModel.Depth = core.Int64Ptr(int64(38)) + getCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := globalCatalogService.GetCatalogEntryWithContext(ctx, getCatalogEntryOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + globalCatalogService.DisableRetries() + result, response, operationErr := globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = globalCatalogService.GetCatalogEntryWithContext(ctx, getCatalogEntryOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getCatalogEntryPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["include"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["languages"]).To(Equal([]string{"testString"})) + // TODO: Add check for complete query parameter + Expect(req.URL.Query()["depth"]).To(Equal([]string{fmt.Sprint(int64(38))})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00.000Z", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00.000Z", "updated": "2019-01-01T12:00:00.000Z"}`) + })) + }) + It(`Invoke GetCatalogEntry successfully`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := globalCatalogService.GetCatalogEntry(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetCatalogEntryOptions model + getCatalogEntryOptionsModel := new(globalcatalogv1.GetCatalogEntryOptions) + getCatalogEntryOptionsModel.ID = core.StringPtr("testString") + getCatalogEntryOptionsModel.Account = core.StringPtr("testString") + getCatalogEntryOptionsModel.Include = core.StringPtr("testString") + getCatalogEntryOptionsModel.Languages = core.StringPtr("testString") + getCatalogEntryOptionsModel.Complete = core.BoolPtr(true) + getCatalogEntryOptionsModel.Depth = core.Int64Ptr(int64(38)) + getCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + }) + It(`Invoke GetCatalogEntry with error: Operation validation and request error`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + + // Construct an instance of the GetCatalogEntryOptions model + getCatalogEntryOptionsModel := new(globalcatalogv1.GetCatalogEntryOptions) + getCatalogEntryOptionsModel.ID = core.StringPtr("testString") + getCatalogEntryOptionsModel.Account = core.StringPtr("testString") + getCatalogEntryOptionsModel.Include = core.StringPtr("testString") + getCatalogEntryOptionsModel.Languages = core.StringPtr("testString") + getCatalogEntryOptionsModel.Complete = core.BoolPtr(true) + getCatalogEntryOptionsModel.Depth = core.Int64Ptr(int64(38)) + getCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := globalCatalogService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the GetCatalogEntryOptions model with no property values + getCatalogEntryOptionsModelNew := new(globalcatalogv1.GetCatalogEntryOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateCatalogEntry(updateCatalogEntryOptions *UpdateCatalogEntryOptions) - Operation response error`, func() { + updateCatalogEntryPath := "/testString" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(updateCatalogEntryPath)) + Expect(req.Method).To(Equal("PUT")) + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["move"]).To(Equal([]string{"testString"})) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke UpdateCatalogEntry with error: Operation response processing error`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + + // Construct an instance of the Overview model + overviewModel := new(globalcatalogv1.Overview) + overviewModel.DisplayName = core.StringPtr("testString") + overviewModel.LongDescription = core.StringPtr("testString") + overviewModel.Description = core.StringPtr("testString") + overviewModel.FeaturedDescription = core.StringPtr("testString") + + // Construct an instance of the Image model + imageModel := new(globalcatalogv1.Image) + imageModel.Image = core.StringPtr("testString") + imageModel.SmallImage = core.StringPtr("testString") + imageModel.MediumImage = core.StringPtr("testString") + imageModel.FeatureImage = core.StringPtr("testString") + + // Construct an instance of the Provider model + providerModel := new(globalcatalogv1.Provider) + providerModel.Email = core.StringPtr("testString") + providerModel.Name = core.StringPtr("testString") + providerModel.Contact = core.StringPtr("testString") + providerModel.SupportEmail = core.StringPtr("testString") + providerModel.Phone = core.StringPtr("testString") + + // Construct an instance of the CfMetaData model + cfMetaDataModel := new(globalcatalogv1.CfMetaData) + cfMetaDataModel.Type = core.StringPtr("testString") + cfMetaDataModel.IamCompatible = core.BoolPtr(true) + cfMetaDataModel.UniqueAPIKey = core.BoolPtr(true) + cfMetaDataModel.Provisionable = core.BoolPtr(true) + cfMetaDataModel.Bindable = core.BoolPtr(true) + cfMetaDataModel.AsyncProvisioningSupported = core.BoolPtr(true) + cfMetaDataModel.AsyncUnprovisioningSupported = core.BoolPtr(true) + cfMetaDataModel.Requires = []string{"testString"} + cfMetaDataModel.PlanUpdateable = core.BoolPtr(true) + cfMetaDataModel.State = core.StringPtr("testString") + cfMetaDataModel.ServiceCheckEnabled = core.BoolPtr(true) + cfMetaDataModel.TestCheckInterval = core.Int64Ptr(int64(38)) + cfMetaDataModel.ServiceKeySupported = core.BoolPtr(true) + cfMetaDataModel.CfGUID = make(map[string]string) + + // Construct an instance of the PlanMetaData model + planMetaDataModel := new(globalcatalogv1.PlanMetaData) + planMetaDataModel.Bindable = core.BoolPtr(true) + planMetaDataModel.Reservable = core.BoolPtr(true) + planMetaDataModel.AllowInternalUsers = core.BoolPtr(true) + planMetaDataModel.AsyncProvisioningSupported = core.BoolPtr(true) + planMetaDataModel.AsyncUnprovisioningSupported = core.BoolPtr(true) + planMetaDataModel.TestCheckInterval = core.Int64Ptr(int64(38)) + planMetaDataModel.SingleScopeInstance = core.StringPtr("testString") + planMetaDataModel.ServiceCheckEnabled = core.BoolPtr(true) + planMetaDataModel.CfGUID = make(map[string]string) + + // Construct an instance of the AliasMetaData model + aliasMetaDataModel := new(globalcatalogv1.AliasMetaData) + aliasMetaDataModel.Type = core.StringPtr("testString") + aliasMetaDataModel.PlanID = core.StringPtr("testString") + + // Construct an instance of the SourceMetaData model + sourceMetaDataModel := new(globalcatalogv1.SourceMetaData) + sourceMetaDataModel.Path = core.StringPtr("testString") + sourceMetaDataModel.Type = core.StringPtr("testString") + sourceMetaDataModel.URL = core.StringPtr("testString") + + // Construct an instance of the TemplateMetaData model + templateMetaDataModel := new(globalcatalogv1.TemplateMetaData) + templateMetaDataModel.Services = []string{"testString"} + templateMetaDataModel.DefaultMemory = core.Int64Ptr(int64(38)) + templateMetaDataModel.StartCmd = core.StringPtr("testString") + templateMetaDataModel.Source = sourceMetaDataModel + templateMetaDataModel.RuntimeCatalogID = core.StringPtr("testString") + templateMetaDataModel.CfRuntimeID = core.StringPtr("testString") + templateMetaDataModel.TemplateID = core.StringPtr("testString") + templateMetaDataModel.ExecutableFile = core.StringPtr("testString") + templateMetaDataModel.Buildpack = core.StringPtr("testString") + templateMetaDataModel.EnvironmentVariables = make(map[string]string) + + // Construct an instance of the Bullets model + bulletsModel := new(globalcatalogv1.Bullets) + bulletsModel.Title = core.StringPtr("testString") + bulletsModel.Description = core.StringPtr("testString") + bulletsModel.Icon = core.StringPtr("testString") + bulletsModel.Quantity = core.Int64Ptr(int64(38)) + + // Construct an instance of the UIMetaMedia model + uiMetaMediaModel := new(globalcatalogv1.UIMetaMedia) + uiMetaMediaModel.Caption = core.StringPtr("testString") + uiMetaMediaModel.ThumbnailURL = core.StringPtr("testString") + uiMetaMediaModel.Type = core.StringPtr("testString") + uiMetaMediaModel.URL = core.StringPtr("testString") + uiMetaMediaModel.Source = bulletsModel + + // Construct an instance of the Strings model + stringsModel := new(globalcatalogv1.Strings) + stringsModel.Bullets = []globalcatalogv1.Bullets{*bulletsModel} + stringsModel.Media = []globalcatalogv1.UIMetaMedia{*uiMetaMediaModel} + stringsModel.NotCreatableMsg = core.StringPtr("testString") + stringsModel.NotCreatableRobotMsg = core.StringPtr("testString") + stringsModel.DeprecationWarning = core.StringPtr("testString") + stringsModel.PopupWarningMessage = core.StringPtr("testString") + stringsModel.Instruction = core.StringPtr("testString") + + // Construct an instance of the Urls model + urlsModel := new(globalcatalogv1.Urls) + urlsModel.DocURL = core.StringPtr("testString") + urlsModel.InstructionsURL = core.StringPtr("testString") + urlsModel.APIURL = core.StringPtr("testString") + urlsModel.CreateURL = core.StringPtr("testString") + urlsModel.SdkDownloadURL = core.StringPtr("testString") + urlsModel.TermsURL = core.StringPtr("testString") + urlsModel.CustomCreatePageURL = core.StringPtr("testString") + urlsModel.CatalogDetailsURL = core.StringPtr("testString") + urlsModel.DeprecationDocURL = core.StringPtr("testString") + urlsModel.DashboardURL = core.StringPtr("testString") + urlsModel.RegistrationURL = core.StringPtr("testString") + urlsModel.Apidocsurl = core.StringPtr("testString") - Expect(req.URL.Query()["languages"]).To(Equal([]string{"testString"})) + // Construct an instance of the UIMetaData model + uiMetaDataModel := new(globalcatalogv1.UIMetaData) + uiMetaDataModel.Strings = make(map[string]globalcatalogv1.Strings) + uiMetaDataModel.Urls = urlsModel + uiMetaDataModel.EmbeddableDashboard = core.StringPtr("testString") + uiMetaDataModel.EmbeddableDashboardFullWidth = core.BoolPtr(true) + uiMetaDataModel.NavigationOrder = []string{"testString"} + uiMetaDataModel.NotCreatable = core.BoolPtr(true) + uiMetaDataModel.PrimaryOfferingID = core.StringPtr("testString") + uiMetaDataModel.AccessibleDuringProvision = core.BoolPtr(true) + uiMetaDataModel.SideBySideIndex = core.Int64Ptr(int64(38)) + uiMetaDataModel.EndOfServiceTime = CreateMockDateTime() + uiMetaDataModel.Hidden = core.BoolPtr(true) + uiMetaDataModel.HideLiteMetering = core.BoolPtr(true) + uiMetaDataModel.NoUpgradeNextStep = core.BoolPtr(true) + uiMetaDataModel.Strings["foo"] = *stringsModel - Expect(req.URL.Query()["complete"]).To(Equal([]string{"testString"})) + // Construct an instance of the DrMetaData model + drMetaDataModel := new(globalcatalogv1.DrMetaData) + drMetaDataModel.Dr = core.BoolPtr(true) + drMetaDataModel.Description = core.StringPtr("testString") - Expect(req.URL.Query()["depth"]).To(Equal([]string{fmt.Sprint(int64(38))})) + // Construct an instance of the SLAMetaData model + slaMetaDataModel := new(globalcatalogv1.SLAMetaData) + slaMetaDataModel.Terms = core.StringPtr("testString") + slaMetaDataModel.Tenancy = core.StringPtr("testString") + slaMetaDataModel.Provisioning = core.StringPtr("testString") + slaMetaDataModel.Responsiveness = core.StringPtr("testString") + slaMetaDataModel.Dr = drMetaDataModel - // Sleep a short time to support a timeout test - time.Sleep(serverSleepTime) + // Construct an instance of the Callbacks model + callbacksModel := new(globalcatalogv1.Callbacks) + callbacksModel.ControllerURL = core.StringPtr("testString") + callbacksModel.BrokerURL = core.StringPtr("testString") + callbacksModel.BrokerProxyURL = core.StringPtr("testString") + callbacksModel.DashboardURL = core.StringPtr("testString") + callbacksModel.DashboardDataURL = core.StringPtr("testString") + callbacksModel.DashboardDetailTabURL = core.StringPtr("testString") + callbacksModel.DashboardDetailTabExtURL = core.StringPtr("testString") + callbacksModel.ServiceMonitorAPI = core.StringPtr("testString") + callbacksModel.ServiceMonitorApp = core.StringPtr("testString") + callbacksModel.APIEndpoint = make(map[string]string) - // Set mock response - res.Header().Set("Content-type", "application/json") - res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00", "effective_until": "2019-01-01T12:00:00", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00", "updated": "2019-01-01T12:00:00"}`) - })) - }) - It(`Invoke GetCatalogEntry successfully`, func() { - globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(globalCatalogService).ToNot(BeNil()) - globalCatalogService.EnableRetries(0, 0) + // Construct an instance of the Price model + priceModel := new(globalcatalogv1.Price) + priceModel.QuantityTier = core.Int64Ptr(int64(38)) + priceModel.Price = core.Float64Ptr(float64(72.5)) - // Invoke operation with nil options model (negative test) - result, response, operationErr := globalCatalogService.GetCatalogEntry(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) + // Construct an instance of the Amount model + amountModel := new(globalcatalogv1.Amount) + amountModel.Country = core.StringPtr("testString") + amountModel.Currency = core.StringPtr("testString") + amountModel.Prices = []globalcatalogv1.Price{*priceModel} - // Construct an instance of the GetCatalogEntryOptions model - getCatalogEntryOptionsModel := new(globalcatalogv1.GetCatalogEntryOptions) - getCatalogEntryOptionsModel.ID = core.StringPtr("testString") - getCatalogEntryOptionsModel.Account = core.StringPtr("testString") - getCatalogEntryOptionsModel.Include = core.StringPtr("testString") - getCatalogEntryOptionsModel.Languages = core.StringPtr("testString") - getCatalogEntryOptionsModel.Complete = core.StringPtr("testString") - getCatalogEntryOptionsModel.Depth = core.Int64Ptr(int64(38)) - getCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Construct an instance of the StartingPrice model + startingPriceModel := new(globalcatalogv1.StartingPrice) + startingPriceModel.PlanID = core.StringPtr("testString") + startingPriceModel.DeploymentID = core.StringPtr("testString") + startingPriceModel.Unit = core.StringPtr("testString") + startingPriceModel.Amount = []globalcatalogv1.Amount{*amountModel} - // Invoke operation with valid options model (positive test) - result, response, operationErr = globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) + // Construct an instance of the PricingSet model + pricingSetModel := new(globalcatalogv1.PricingSet) + pricingSetModel.Type = core.StringPtr("testString") + pricingSetModel.Origin = core.StringPtr("testString") + pricingSetModel.StartingPrice = startingPriceModel - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.GetCatalogEntryWithContext(ctx, getCatalogEntryOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) + // Construct an instance of the Broker model + brokerModel := new(globalcatalogv1.Broker) + brokerModel.Name = core.StringPtr("testString") + brokerModel.GUID = core.StringPtr("testString") - // Disable retries and test again - globalCatalogService.DisableRetries() - result, response, operationErr = globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) + // Construct an instance of the DeploymentBase model + deploymentBaseModel := new(globalcatalogv1.DeploymentBase) + deploymentBaseModel.Location = core.StringPtr("testString") + deploymentBaseModel.LocationURL = core.StringPtr("testString") + deploymentBaseModel.OriginalLocation = core.StringPtr("testString") + deploymentBaseModel.TargetCRN = core.StringPtr("testString") + deploymentBaseModel.ServiceCRN = core.StringPtr("testString") + deploymentBaseModel.MccpID = core.StringPtr("testString") + deploymentBaseModel.Broker = brokerModel + deploymentBaseModel.SupportsRcMigration = core.BoolPtr(true) + deploymentBaseModel.TargetNetwork = core.StringPtr("testString") - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.GetCatalogEntryWithContext(ctx, getCatalogEntryOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) - }) - It(`Invoke GetCatalogEntry with error: Operation validation and request error`, func() { - globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(globalCatalogService).ToNot(BeNil()) + // Construct an instance of the ObjectMetadataSet model + objectMetadataSetModel := new(globalcatalogv1.ObjectMetadataSet) + objectMetadataSetModel.RcCompatible = core.BoolPtr(true) + objectMetadataSetModel.Service = cfMetaDataModel + objectMetadataSetModel.Plan = planMetaDataModel + objectMetadataSetModel.Alias = aliasMetaDataModel + objectMetadataSetModel.Template = templateMetaDataModel + objectMetadataSetModel.UI = uiMetaDataModel + objectMetadataSetModel.Compliance = []string{"testString"} + objectMetadataSetModel.SLA = slaMetaDataModel + objectMetadataSetModel.Callbacks = callbacksModel + objectMetadataSetModel.OriginalName = core.StringPtr("testString") + objectMetadataSetModel.Version = core.StringPtr("testString") + objectMetadataSetModel.Other = make(map[string]interface{}) + objectMetadataSetModel.Pricing = pricingSetModel + objectMetadataSetModel.Deployment = deploymentBaseModel - // Construct an instance of the GetCatalogEntryOptions model - getCatalogEntryOptionsModel := new(globalcatalogv1.GetCatalogEntryOptions) - getCatalogEntryOptionsModel.ID = core.StringPtr("testString") - getCatalogEntryOptionsModel.Account = core.StringPtr("testString") - getCatalogEntryOptionsModel.Include = core.StringPtr("testString") - getCatalogEntryOptionsModel.Languages = core.StringPtr("testString") - getCatalogEntryOptionsModel.Complete = core.StringPtr("testString") - getCatalogEntryOptionsModel.Depth = core.Int64Ptr(int64(38)) - getCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := globalCatalogService.SetServiceURL("") - Expect(err).To(BeNil()) - result, response, operationErr := globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModel) + // Construct an instance of the UpdateCatalogEntryOptions model + updateCatalogEntryOptionsModel := new(globalcatalogv1.UpdateCatalogEntryOptions) + updateCatalogEntryOptionsModel.ID = core.StringPtr("testString") + updateCatalogEntryOptionsModel.Name = core.StringPtr("testString") + updateCatalogEntryOptionsModel.Kind = core.StringPtr("service") + updateCatalogEntryOptionsModel.OverviewUI = make(map[string]globalcatalogv1.Overview) + updateCatalogEntryOptionsModel.Images = imageModel + updateCatalogEntryOptionsModel.Disabled = core.BoolPtr(true) + updateCatalogEntryOptionsModel.Tags = []string{"testString"} + updateCatalogEntryOptionsModel.Provider = providerModel + updateCatalogEntryOptionsModel.ParentID = core.StringPtr("testString") + updateCatalogEntryOptionsModel.Group = core.BoolPtr(true) + updateCatalogEntryOptionsModel.Active = core.BoolPtr(true) + updateCatalogEntryOptionsModel.Metadata = objectMetadataSetModel + updateCatalogEntryOptionsModel.Account = core.StringPtr("testString") + updateCatalogEntryOptionsModel.Move = core.StringPtr("testString") + updateCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + updateCatalogEntryOptionsModel.OverviewUI["foo"] = *overviewModel + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := globalCatalogService.UpdateCatalogEntry(updateCatalogEntryOptionsModel) Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) + Expect(response).ToNot(BeNil()) Expect(result).To(BeNil()) - // Construct a second instance of the GetCatalogEntryOptions model with no property values - getCatalogEntryOptionsModelNew := new(globalcatalogv1.GetCatalogEntryOptions) - // Invoke operation with invalid model (negative test) - result, response, operationErr = globalCatalogService.GetCatalogEntry(getCatalogEntryOptionsModelNew) + + // Enable retries and test again + globalCatalogService.EnableRetries(0, 0) + result, response, operationErr = globalCatalogService.UpdateCatalogEntry(updateCatalogEntryOptionsModel) Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) + Expect(response).ToNot(BeNil()) Expect(result).To(BeNil()) }) AfterEach(func() { @@ -1400,9 +2022,10 @@ var _ = Describe(`GlobalCatalogV1`, func() { }) }) }) - Describe(`UpdateCatalogEntry(updateCatalogEntryOptions *UpdateCatalogEntryOptions) - Operation response error`, func() { + + Describe(`UpdateCatalogEntry(updateCatalogEntryOptions *UpdateCatalogEntryOptions)`, func() { updateCatalogEntryPath := "/testString" - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with timeout`, func() { BeforeEach(func() { testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -1410,22 +2033,42 @@ var _ = Describe(`GlobalCatalogV1`, func() { // Verify the contents of the request Expect(req.URL.EscapedPath()).To(Equal(updateCatalogEntryPath)) Expect(req.Method).To(Equal("PUT")) - Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + // For gzip-disabled operation, verify Content-Encoding is not set. + Expect(req.Header.Get("Content-Encoding")).To(BeEmpty()) + + // If there is a body, then make sure we can read it + bodyBuf := new(bytes.Buffer) + if req.Header.Get("Content-Encoding") == "gzip" { + body, err := core.NewGzipDecompressionReader(req.Body) + Expect(err).To(BeNil()) + _, err = bodyBuf.ReadFrom(body) + Expect(err).To(BeNil()) + } else { + _, err := bodyBuf.ReadFrom(req.Body) + Expect(err).To(BeNil()) + } + fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["move"]).To(Equal([]string{"testString"})) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) + fmt.Fprintf(res, "%s", `{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00.000Z", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00.000Z", "updated": "2019-01-01T12:00:00.000Z"}`) })) }) - It(`Invoke UpdateCatalogEntry with error: Operation response processing error`, func() { + It(`Invoke UpdateCatalogEntry successfully with retries`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ URL: testServer.URL, Authenticator: &core.NoAuthAuthenticator{}, }) Expect(serviceErr).To(BeNil()) Expect(globalCatalogService).ToNot(BeNil()) + globalCatalogService.EnableRetries(0, 0) // Construct an instance of the Overview model overviewModel := new(globalcatalogv1.Overview) @@ -1661,31 +2304,34 @@ var _ = Describe(`GlobalCatalogV1`, func() { updateCatalogEntryOptionsModel.Move = core.StringPtr("testString") updateCatalogEntryOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} updateCatalogEntryOptionsModel.OverviewUI["foo"] = *overviewModel - // Expect response parsing to fail since we are receiving a text/plain response - result, response, operationErr := globalCatalogService.UpdateCatalogEntry(updateCatalogEntryOptionsModel) + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := globalCatalogService.UpdateCatalogEntryWithContext(ctx, updateCatalogEntryOptionsModel) Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + globalCatalogService.DisableRetries() + result, response, operationErr := globalCatalogService.UpdateCatalogEntry(updateCatalogEntryOptionsModel) + Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) + Expect(result).ToNot(BeNil()) - // Enable retries and test again - globalCatalogService.EnableRetries(0, 0) - result, response, operationErr = globalCatalogService.UpdateCatalogEntry(updateCatalogEntryOptionsModel) + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = globalCatalogService.UpdateCatalogEntryWithContext(ctx, updateCatalogEntryOptionsModel) Expect(operationErr).ToNot(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).To(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) }) AfterEach(func() { testServer.Close() }) }) - }) - - Describe(`UpdateCatalogEntry(updateCatalogEntryOptions *UpdateCatalogEntryOptions)`, func() { - updateCatalogEntryPath := "/testString" - var serverSleepTime time.Duration Context(`Using mock server endpoint`, func() { BeforeEach(func() { - serverSleepTime = 0 testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -1710,16 +2356,11 @@ var _ = Describe(`GlobalCatalogV1`, func() { fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - - Expect(req.URL.Query()["move"]).To(Equal([]string{"testString"})) - - // Sleep a short time to support a timeout test - time.Sleep(serverSleepTime) - + Expect(req.URL.Query()["move"]).To(Equal([]string{"testString"})) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00", "effective_until": "2019-01-01T12:00:00", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00", "updated": "2019-01-01T12:00:00"}`) + fmt.Fprintf(res, "%s", `{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00.000Z", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00.000Z", "updated": "2019-01-01T12:00:00.000Z"}`) })) }) It(`Invoke UpdateCatalogEntry successfully`, func() { @@ -1729,7 +2370,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { }) Expect(serviceErr).To(BeNil()) Expect(globalCatalogService).ToNot(BeNil()) - globalCatalogService.EnableRetries(0, 0) // Invoke operation with nil options model (negative test) result, response, operationErr := globalCatalogService.UpdateCatalogEntry(nil) @@ -1978,30 +2618,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(response).ToNot(BeNil()) Expect(result).ToNot(BeNil()) - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.UpdateCatalogEntryWithContext(ctx, updateCatalogEntryOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) - - // Disable retries and test again - globalCatalogService.DisableRetries() - result, response, operationErr = globalCatalogService.UpdateCatalogEntry(updateCatalogEntryOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.UpdateCatalogEntryWithContext(ctx, updateCatalogEntryOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) }) It(`Invoke UpdateCatalogEntry with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -2279,10 +2895,7 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.Method).To(Equal("DELETE")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - - // TODO: Add check for force query parameter - res.WriteHeader(204) })) }) @@ -2293,7 +2906,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { }) Expect(serviceErr).To(BeNil()) Expect(globalCatalogService).ToNot(BeNil()) - globalCatalogService.EnableRetries(0, 0) // Invoke operation with nil options model (negative test) response, operationErr := globalCatalogService.DeleteCatalogEntry(nil) @@ -2311,12 +2923,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { response, operationErr = globalCatalogService.DeleteCatalogEntry(deleteCatalogEntryOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) - - // Disable retries and test again - globalCatalogService.DisableRetries() - response, operationErr = globalCatalogService.DeleteCatalogEntry(deleteCatalogEntryOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) }) It(`Invoke DeleteCatalogEntry with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -2362,19 +2968,12 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(getChildObjectsPath)) Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["include"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["q"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["sort-by"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["descending"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["languages"]).To(Equal([]string{"testString"})) - - Expect(req.URL.Query()["complete"]).To(Equal([]string{"testString"})) - + // TODO: Add check for complete query parameter res.Header().Set("Content-type", "application/json") res.WriteHeader(200) fmt.Fprintf(res, `} this is not valid json {`) @@ -2398,7 +2997,7 @@ var _ = Describe(`GlobalCatalogV1`, func() { getChildObjectsOptionsModel.SortBy = core.StringPtr("testString") getChildObjectsOptionsModel.Descending = core.StringPtr("testString") getChildObjectsOptionsModel.Languages = core.StringPtr("testString") - getChildObjectsOptionsModel.Complete = core.StringPtr("testString") + getChildObjectsOptionsModel.Complete = core.BoolPtr(true) getChildObjectsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Expect response parsing to fail since we are receiving a text/plain response result, response, operationErr := globalCatalogService.GetChildObjects(getChildObjectsOptionsModel) @@ -2421,10 +3020,8 @@ var _ = Describe(`GlobalCatalogV1`, func() { Describe(`GetChildObjects(getChildObjectsOptions *GetChildObjectsOptions)`, func() { getChildObjectsPath := "/testString/testString" - var serverSleepTime time.Duration - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with timeout`, func() { BeforeEach(func() { - serverSleepTime = 0 testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -2433,29 +3030,22 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["include"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["q"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["sort-by"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["descending"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["languages"]).To(Equal([]string{"testString"})) - - Expect(req.URL.Query()["complete"]).To(Equal([]string{"testString"})) - + // TODO: Add check for complete query parameter // Sleep a short time to support a timeout test - time.Sleep(serverSleepTime) + time.Sleep(100 * time.Millisecond) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"offset": 6, "limit": 5, "count": 5, "resource_count": 13, "first": "First", "last": "Last", "prev": "Prev", "next": "Next", "resources": [{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00", "effective_until": "2019-01-01T12:00:00", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00", "updated": "2019-01-01T12:00:00"}]}`) + fmt.Fprintf(res, "%s", `{"offset": 6, "limit": 5, "count": 5, "resource_count": 13, "first": "First", "last": "Last", "prev": "Prev", "next": "Next", "resources": [{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00.000Z", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00.000Z", "updated": "2019-01-01T12:00:00.000Z"}]}`) })) }) - It(`Invoke GetChildObjects successfully`, func() { + It(`Invoke GetChildObjects successfully with retries`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ URL: testServer.URL, Authenticator: &core.NoAuthAuthenticator{}, @@ -2464,12 +3054,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(globalCatalogService).ToNot(BeNil()) globalCatalogService.EnableRetries(0, 0) - // Invoke operation with nil options model (negative test) - result, response, operationErr := globalCatalogService.GetChildObjects(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct an instance of the GetChildObjectsOptions model getChildObjectsOptionsModel := new(globalcatalogv1.GetChildObjectsOptions) getChildObjectsOptionsModel.ID = core.StringPtr("testString") @@ -2480,27 +3064,19 @@ var _ = Describe(`GlobalCatalogV1`, func() { getChildObjectsOptionsModel.SortBy = core.StringPtr("testString") getChildObjectsOptionsModel.Descending = core.StringPtr("testString") getChildObjectsOptionsModel.Languages = core.StringPtr("testString") - getChildObjectsOptionsModel.Complete = core.StringPtr("testString") + getChildObjectsOptionsModel.Complete = core.BoolPtr(true) getChildObjectsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with valid options model (positive test) - result, response, operationErr = globalCatalogService.GetChildObjects(getChildObjectsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - // Invoke operation with a Context to test a timeout error ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.GetChildObjectsWithContext(ctx, getChildObjectsOptionsModel) + _, _, operationErr := globalCatalogService.GetChildObjectsWithContext(ctx, getChildObjectsOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) // Disable retries and test again globalCatalogService.DisableRetries() - result, response, operationErr = globalCatalogService.GetChildObjects(getChildObjectsOptionsModel) + result, response, operationErr := globalCatalogService.GetChildObjects(getChildObjectsOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) Expect(result).ToNot(BeNil()) @@ -2508,11 +3084,69 @@ var _ = Describe(`GlobalCatalogV1`, func() { // Re-test the timeout error with retries disabled ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc2() - serverSleepTime = 100 * time.Millisecond _, _, operationErr = globalCatalogService.GetChildObjectsWithContext(ctx, getChildObjectsOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getChildObjectsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["include"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["q"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["sort-by"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["descending"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["languages"]).To(Equal([]string{"testString"})) + // TODO: Add check for complete query parameter + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"offset": 6, "limit": 5, "count": 5, "resource_count": 13, "first": "First", "last": "Last", "prev": "Prev", "next": "Next", "resources": [{"name": "Name", "kind": "service", "overview_ui": {"mapKey": {"display_name": "DisplayName", "long_description": "LongDescription", "description": "Description", "featured_description": "FeaturedDescription"}}, "images": {"image": "Image", "small_image": "SmallImage", "medium_image": "MediumImage", "feature_image": "FeatureImage"}, "parent_id": "ParentID", "disabled": true, "tags": ["Tags"], "group": false, "provider": {"email": "Email", "name": "Name", "contact": "Contact", "support_email": "SupportEmail", "phone": "Phone"}, "active": true, "metadata": {"rc_compatible": true, "service": {"type": "Type", "iam_compatible": false, "unique_api_key": true, "provisionable": false, "bindable": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "requires": ["Requires"], "plan_updateable": true, "state": "State", "service_check_enabled": false, "test_check_interval": 17, "service_key_supported": false, "cf_guid": {"mapKey": "Inner"}}, "plan": {"bindable": true, "reservable": true, "allow_internal_users": true, "async_provisioning_supported": true, "async_unprovisioning_supported": true, "test_check_interval": 17, "single_scope_instance": "SingleScopeInstance", "service_check_enabled": false, "cf_guid": {"mapKey": "Inner"}}, "alias": {"type": "Type", "plan_id": "PlanID"}, "template": {"services": ["Services"], "default_memory": 13, "start_cmd": "StartCmd", "source": {"path": "Path", "type": "Type", "url": "URL"}, "runtime_catalog_id": "RuntimeCatalogID", "cf_runtime_id": "CfRuntimeID", "template_id": "TemplateID", "executable_file": "ExecutableFile", "buildpack": "Buildpack", "environment_variables": {"mapKey": "Inner"}}, "ui": {"strings": {"mapKey": {"bullets": [{"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}], "media": [{"caption": "Caption", "thumbnail_url": "ThumbnailURL", "type": "Type", "URL": "URL", "source": {"title": "Title", "description": "Description", "icon": "Icon", "quantity": 8}}], "not_creatable_msg": "NotCreatableMsg", "not_creatable__robot_msg": "NotCreatableRobotMsg", "deprecation_warning": "DeprecationWarning", "popup_warning_message": "PopupWarningMessage", "instruction": "Instruction"}}, "urls": {"doc_url": "DocURL", "instructions_url": "InstructionsURL", "api_url": "APIURL", "create_url": "CreateURL", "sdk_download_url": "SdkDownloadURL", "terms_url": "TermsURL", "custom_create_page_url": "CustomCreatePageURL", "catalog_details_url": "CatalogDetailsURL", "deprecation_doc_url": "DeprecationDocURL", "dashboard_url": "DashboardURL", "registration_url": "RegistrationURL", "apidocsurl": "Apidocsurl"}, "embeddable_dashboard": "EmbeddableDashboard", "embeddable_dashboard_full_width": true, "navigation_order": ["NavigationOrder"], "not_creatable": true, "primary_offering_id": "PrimaryOfferingID", "accessible_during_provision": false, "side_by_side_index": 15, "end_of_service_time": "2019-01-01T12:00:00.000Z", "hidden": true, "hide_lite_metering": true, "no_upgrade_next_step": false}, "compliance": ["Compliance"], "sla": {"terms": "Terms", "tenancy": "Tenancy", "provisioning": "Provisioning", "responsiveness": "Responsiveness", "dr": {"dr": true, "description": "Description"}}, "callbacks": {"controller_url": "ControllerURL", "broker_url": "BrokerURL", "broker_proxy_url": "BrokerProxyURL", "dashboard_url": "DashboardURL", "dashboard_data_url": "DashboardDataURL", "dashboard_detail_tab_url": "DashboardDetailTabURL", "dashboard_detail_tab_ext_url": "DashboardDetailTabExtURL", "service_monitor_api": "ServiceMonitorAPI", "service_monitor_app": "ServiceMonitorApp", "api_endpoint": {"mapKey": "Inner"}}, "original_name": "OriginalName", "version": "Version", "other": {"mapKey": {"anyKey": "anyValue"}}, "pricing": {"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}, "deployment": {"location": "Location", "location_url": "LocationURL", "original_location": "OriginalLocation", "target_crn": "TargetCRN", "service_crn": "ServiceCRN", "mccp_id": "MccpID", "broker": {"name": "Name", "guid": "GUID"}, "supports_rc_migration": false, "target_network": "TargetNetwork"}}, "id": "ID", "catalog_crn": "CatalogCRN", "url": "URL", "children_url": "ChildrenURL", "geo_tags": ["GeoTags"], "pricing_tags": ["PricingTags"], "created": "2019-01-01T12:00:00.000Z", "updated": "2019-01-01T12:00:00.000Z"}]}`) + })) + }) + It(`Invoke GetChildObjects successfully`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := globalCatalogService.GetChildObjects(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetChildObjectsOptions model + getChildObjectsOptionsModel := new(globalcatalogv1.GetChildObjectsOptions) + getChildObjectsOptionsModel.ID = core.StringPtr("testString") + getChildObjectsOptionsModel.Kind = core.StringPtr("testString") + getChildObjectsOptionsModel.Account = core.StringPtr("testString") + getChildObjectsOptionsModel.Include = core.StringPtr("testString") + getChildObjectsOptionsModel.Q = core.StringPtr("testString") + getChildObjectsOptionsModel.SortBy = core.StringPtr("testString") + getChildObjectsOptionsModel.Descending = core.StringPtr("testString") + getChildObjectsOptionsModel.Languages = core.StringPtr("testString") + getChildObjectsOptionsModel.Complete = core.BoolPtr(true) + getChildObjectsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = globalCatalogService.GetChildObjects(getChildObjectsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) It(`Invoke GetChildObjects with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -2532,7 +3166,7 @@ var _ = Describe(`GlobalCatalogV1`, func() { getChildObjectsOptionsModel.SortBy = core.StringPtr("testString") getChildObjectsOptionsModel.Descending = core.StringPtr("testString") getChildObjectsOptionsModel.Languages = core.StringPtr("testString") - getChildObjectsOptionsModel.Complete = core.StringPtr("testString") + getChildObjectsOptionsModel.Complete = core.BoolPtr(true) getChildObjectsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := globalCatalogService.SetServiceURL("") @@ -2568,7 +3202,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.Method).To(Equal("PUT")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - res.WriteHeader(204) })) }) @@ -2579,7 +3212,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { }) Expect(serviceErr).To(BeNil()) Expect(globalCatalogService).ToNot(BeNil()) - globalCatalogService.EnableRetries(0, 0) // Invoke operation with nil options model (negative test) response, operationErr := globalCatalogService.RestoreCatalogEntry(nil) @@ -2596,12 +3228,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { response, operationErr = globalCatalogService.RestoreCatalogEntry(restoreCatalogEntryOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) - - // Disable retries and test again - globalCatalogService.DisableRetries() - response, operationErr = globalCatalogService.RestoreCatalogEntry(restoreCatalogEntryOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) }) It(`Invoke RestoreCatalogEntry with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -2774,7 +3400,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(getVisibilityPath)) Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - res.Header().Set("Content-type", "application/json") res.WriteHeader(200) fmt.Fprintf(res, `} this is not valid json {`) @@ -2814,10 +3439,8 @@ var _ = Describe(`GlobalCatalogV1`, func() { Describe(`GetVisibility(getVisibilityOptions *GetVisibilityOptions)`, func() { getVisibilityPath := "/testString/visibility" - var serverSleepTime time.Duration - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with timeout`, func() { BeforeEach(func() { - serverSleepTime = 0 testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -2826,9 +3449,8 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - // Sleep a short time to support a timeout test - time.Sleep(serverSleepTime) + time.Sleep(100 * time.Millisecond) // Set mock response res.Header().Set("Content-type", "application/json") @@ -2836,7 +3458,7 @@ var _ = Describe(`GlobalCatalogV1`, func() { fmt.Fprintf(res, "%s", `{"restrictions": "Restrictions", "owner": "Owner", "extendable": true, "include": {"accounts": {"_accountid_": "Accountid"}}, "exclude": {"accounts": {"_accountid_": "Accountid"}}, "approved": true}`) })) }) - It(`Invoke GetVisibility successfully`, func() { + It(`Invoke GetVisibility successfully with retries`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ URL: testServer.URL, Authenticator: &core.NoAuthAuthenticator{}, @@ -2845,36 +3467,22 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(globalCatalogService).ToNot(BeNil()) globalCatalogService.EnableRetries(0, 0) - // Invoke operation with nil options model (negative test) - result, response, operationErr := globalCatalogService.GetVisibility(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct an instance of the GetVisibilityOptions model getVisibilityOptionsModel := new(globalcatalogv1.GetVisibilityOptions) getVisibilityOptionsModel.ID = core.StringPtr("testString") getVisibilityOptionsModel.Account = core.StringPtr("testString") getVisibilityOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with valid options model (positive test) - result, response, operationErr = globalCatalogService.GetVisibility(getVisibilityOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - // Invoke operation with a Context to test a timeout error ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.GetVisibilityWithContext(ctx, getVisibilityOptionsModel) + _, _, operationErr := globalCatalogService.GetVisibilityWithContext(ctx, getVisibilityOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) // Disable retries and test again globalCatalogService.DisableRetries() - result, response, operationErr = globalCatalogService.GetVisibility(getVisibilityOptionsModel) + result, response, operationErr := globalCatalogService.GetVisibility(getVisibilityOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) Expect(result).ToNot(BeNil()) @@ -2882,11 +3490,56 @@ var _ = Describe(`GlobalCatalogV1`, func() { // Re-test the timeout error with retries disabled ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc2() - serverSleepTime = 100 * time.Millisecond _, _, operationErr = globalCatalogService.GetVisibilityWithContext(ctx, getVisibilityOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getVisibilityPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"restrictions": "Restrictions", "owner": "Owner", "extendable": true, "include": {"accounts": {"_accountid_": "Accountid"}}, "exclude": {"accounts": {"_accountid_": "Accountid"}}, "approved": true}`) + })) + }) + It(`Invoke GetVisibility successfully`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := globalCatalogService.GetVisibility(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetVisibilityOptions model + getVisibilityOptionsModel := new(globalcatalogv1.GetVisibilityOptions) + getVisibilityOptionsModel.ID = core.StringPtr("testString") + getVisibilityOptionsModel.Account = core.StringPtr("testString") + getVisibilityOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = globalCatalogService.GetVisibility(getVisibilityOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) It(`Invoke GetVisibility with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -2951,7 +3604,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - res.WriteHeader(200) })) }) @@ -2962,7 +3614,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { }) Expect(serviceErr).To(BeNil()) Expect(globalCatalogService).ToNot(BeNil()) - globalCatalogService.EnableRetries(0, 0) // Invoke operation with nil options model (negative test) response, operationErr := globalCatalogService.UpdateVisibility(nil) @@ -2990,12 +3641,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { response, operationErr = globalCatalogService.UpdateVisibility(updateVisibilityOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) - - // Disable retries and test again - globalCatalogService.DisableRetries() - response, operationErr = globalCatalogService.UpdateVisibility(updateVisibilityOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) }) It(`Invoke UpdateVisibility with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -3179,7 +3824,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(getPricingPath)) Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - res.Header().Set("Content-type", "application/json") res.WriteHeader(200) fmt.Fprintf(res, `} this is not valid json {`) @@ -3219,10 +3863,67 @@ var _ = Describe(`GlobalCatalogV1`, func() { Describe(`GetPricing(getPricingOptions *GetPricingOptions)`, func() { getPricingPath := "/testString/pricing" - var serverSleepTime time.Duration + Context(`Using mock server endpoint with timeout`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getPricingPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + // Sleep a short time to support a timeout test + time.Sleep(100 * time.Millisecond) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}`) + })) + }) + It(`Invoke GetPricing successfully with retries`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + globalCatalogService.EnableRetries(0, 0) + + // Construct an instance of the GetPricingOptions model + getPricingOptionsModel := new(globalcatalogv1.GetPricingOptions) + getPricingOptionsModel.ID = core.StringPtr("testString") + getPricingOptionsModel.Account = core.StringPtr("testString") + getPricingOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + _, _, operationErr := globalCatalogService.GetPricingWithContext(ctx, getPricingOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + + // Disable retries and test again + globalCatalogService.DisableRetries() + result, response, operationErr := globalCatalogService.GetPricing(getPricingOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + _, _, operationErr = globalCatalogService.GetPricingWithContext(ctx, getPricingOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + }) + AfterEach(func() { + testServer.Close() + }) + }) Context(`Using mock server endpoint`, func() { BeforeEach(func() { - serverSleepTime = 0 testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -3231,14 +3932,10 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - - // Sleep a short time to support a timeout test - time.Sleep(serverSleepTime) - // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00", "effective_until": "2019-01-01T12:00:00", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}`) + fmt.Fprintf(res, "%s", `{"type": "Type", "origin": "Origin", "starting_price": {"plan_id": "PlanID", "deployment_id": "DeploymentID", "unit": "Unit", "amount": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}, "metrics": [{"part_ref": "PartRef", "metric_id": "MetricID", "tier_model": "TierModel", "charge_unit": "ChargeUnit", "charge_unit_name": "ChargeUnitName", "charge_unit_quantity": "ChargeUnitQuantity", "resource_display_name": "ResourceDisplayName", "charge_unit_display_name": "ChargeUnitDisplayName", "usage_cap_qty": 11, "display_cap": 10, "effective_from": "2019-01-01T12:00:00.000Z", "effective_until": "2019-01-01T12:00:00.000Z", "amounts": [{"country": "Country", "currency": "Currency", "prices": [{"quantity_tier": 12, "Price": 5}]}]}]}`) })) }) It(`Invoke GetPricing successfully`, func() { @@ -3248,7 +3945,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { }) Expect(serviceErr).To(BeNil()) Expect(globalCatalogService).ToNot(BeNil()) - globalCatalogService.EnableRetries(0, 0) // Invoke operation with nil options model (negative test) result, response, operationErr := globalCatalogService.GetPricing(nil) @@ -3268,30 +3964,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(response).ToNot(BeNil()) Expect(result).ToNot(BeNil()) - // Invoke operation with a Context to test a timeout error - ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.GetPricingWithContext(ctx, getPricingOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) - - // Disable retries and test again - globalCatalogService.DisableRetries() - result, response, operationErr = globalCatalogService.GetPricing(getPricingOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - - // Re-test the timeout error with retries disabled - ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) - defer cancelFunc2() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.GetPricingWithContext(ctx, getPricingOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) }) It(`Invoke GetPricing with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -3466,15 +4138,10 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(getAuditLogsPath)) Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["ascending"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["startat"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["_offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) - Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(200))})) - res.Header().Set("Content-type", "application/json") res.WriteHeader(200) fmt.Fprintf(res, `} this is not valid json {`) @@ -3518,10 +4185,8 @@ var _ = Describe(`GlobalCatalogV1`, func() { Describe(`GetAuditLogs(getAuditLogsOptions *GetAuditLogsOptions)`, func() { getAuditLogsPath := "/testString/logs" - var serverSleepTime time.Duration - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with timeout`, func() { BeforeEach(func() { - serverSleepTime = 0 testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -3530,25 +4195,20 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["ascending"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["startat"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["_offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) - Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(200))})) - // Sleep a short time to support a timeout test - time.Sleep(serverSleepTime) + time.Sleep(100 * time.Millisecond) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"offset": 6, "limit": 5, "count": 5, "resource_count": 13, "first": "First", "last": "Last", "prev": "Prev", "next": "Next", "resources": [{"id": "ID", "effective": {"restrictions": "Restrictions", "owner": "Owner", "extendable": true, "include": {"accounts": {"_accountid_": "Accountid"}}, "exclude": {"accounts": {"_accountid_": "Accountid"}}, "approved": true}, "time": "2019-01-01T12:00:00", "who_id": "WhoID", "who_name": "WhoName", "who_email": "WhoEmail", "instance": "Instance", "gid": "Gid", "type": "Type", "message": "Message", "data": {"mapKey": "anyValue"}}]}`) + fmt.Fprintf(res, "%s", `{"offset": 6, "limit": 5, "count": 5, "resource_count": 13, "first": "First", "last": "Last", "prev": "Prev", "next": "Next", "resources": [{"id": "ID", "effective": {"restrictions": "Restrictions", "owner": "Owner", "extendable": true, "include": {"accounts": {"_accountid_": "Accountid"}}, "exclude": {"accounts": {"_accountid_": "Accountid"}}, "approved": true}, "time": "2019-01-01T12:00:00.000Z", "who_id": "WhoID", "who_name": "WhoName", "who_email": "WhoEmail", "instance": "Instance", "gid": "Gid", "type": "Type", "message": "Message", "data": {"mapKey": "anyValue"}}]}`) })) }) - It(`Invoke GetAuditLogs successfully`, func() { + It(`Invoke GetAuditLogs successfully with retries`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ URL: testServer.URL, Authenticator: &core.NoAuthAuthenticator{}, @@ -3557,12 +4217,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(globalCatalogService).ToNot(BeNil()) globalCatalogService.EnableRetries(0, 0) - // Invoke operation with nil options model (negative test) - result, response, operationErr := globalCatalogService.GetAuditLogs(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct an instance of the GetAuditLogsOptions model getAuditLogsOptionsModel := new(globalcatalogv1.GetAuditLogsOptions) getAuditLogsOptionsModel.ID = core.StringPtr("testString") @@ -3573,24 +4227,16 @@ var _ = Describe(`GlobalCatalogV1`, func() { getAuditLogsOptionsModel.Limit = core.Int64Ptr(int64(200)) getAuditLogsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with valid options model (positive test) - result, response, operationErr = globalCatalogService.GetAuditLogs(getAuditLogsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - // Invoke operation with a Context to test a timeout error ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.GetAuditLogsWithContext(ctx, getAuditLogsOptionsModel) + _, _, operationErr := globalCatalogService.GetAuditLogsWithContext(ctx, getAuditLogsOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) // Disable retries and test again globalCatalogService.DisableRetries() - result, response, operationErr = globalCatalogService.GetAuditLogs(getAuditLogsOptionsModel) + result, response, operationErr := globalCatalogService.GetAuditLogs(getAuditLogsOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) Expect(result).ToNot(BeNil()) @@ -3598,11 +4244,64 @@ var _ = Describe(`GlobalCatalogV1`, func() { // Re-test the timeout error with retries disabled ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc2() - serverSleepTime = 100 * time.Millisecond _, _, operationErr = globalCatalogService.GetAuditLogsWithContext(ctx, getAuditLogsOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getAuditLogsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["ascending"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["startat"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["_offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + Expect(req.URL.Query()["_limit"]).To(Equal([]string{fmt.Sprint(int64(200))})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"offset": 6, "limit": 5, "count": 5, "resource_count": 13, "first": "First", "last": "Last", "prev": "Prev", "next": "Next", "resources": [{"id": "ID", "effective": {"restrictions": "Restrictions", "owner": "Owner", "extendable": true, "include": {"accounts": {"_accountid_": "Accountid"}}, "exclude": {"accounts": {"_accountid_": "Accountid"}}, "approved": true}, "time": "2019-01-01T12:00:00.000Z", "who_id": "WhoID", "who_name": "WhoName", "who_email": "WhoEmail", "instance": "Instance", "gid": "Gid", "type": "Type", "message": "Message", "data": {"mapKey": "anyValue"}}]}`) + })) + }) + It(`Invoke GetAuditLogs successfully`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := globalCatalogService.GetAuditLogs(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetAuditLogsOptions model + getAuditLogsOptionsModel := new(globalcatalogv1.GetAuditLogsOptions) + getAuditLogsOptionsModel.ID = core.StringPtr("testString") + getAuditLogsOptionsModel.Account = core.StringPtr("testString") + getAuditLogsOptionsModel.Ascending = core.StringPtr("testString") + getAuditLogsOptionsModel.Startat = core.StringPtr("testString") + getAuditLogsOptionsModel.Offset = core.Int64Ptr(int64(38)) + getAuditLogsOptionsModel.Limit = core.Int64Ptr(int64(200)) + getAuditLogsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = globalCatalogService.GetAuditLogs(getAuditLogsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) It(`Invoke GetAuditLogs with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -3781,7 +4480,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(listArtifactsPath)) Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - res.Header().Set("Content-type", "application/json") res.WriteHeader(200) fmt.Fprintf(res, `} this is not valid json {`) @@ -3821,10 +4519,8 @@ var _ = Describe(`GlobalCatalogV1`, func() { Describe(`ListArtifacts(listArtifactsOptions *ListArtifactsOptions)`, func() { listArtifactsPath := "/testString/artifacts" - var serverSleepTime time.Duration - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with timeout`, func() { BeforeEach(func() { - serverSleepTime = 0 testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -3833,17 +4529,16 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.Method).To(Equal("GET")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - // Sleep a short time to support a timeout test - time.Sleep(serverSleepTime) + time.Sleep(100 * time.Millisecond) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"count": 5, "resources": [{"name": "Name", "updated": "2019-01-01T12:00:00", "url": "URL", "etag": "Etag", "size": 4}]}`) + fmt.Fprintf(res, "%s", `{"count": 5, "resources": [{"name": "Name", "updated": "2019-01-01T12:00:00.000Z", "url": "URL", "etag": "Etag", "size": 4}]}`) })) }) - It(`Invoke ListArtifacts successfully`, func() { + It(`Invoke ListArtifacts successfully with retries`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ URL: testServer.URL, Authenticator: &core.NoAuthAuthenticator{}, @@ -3852,36 +4547,22 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(globalCatalogService).ToNot(BeNil()) globalCatalogService.EnableRetries(0, 0) - // Invoke operation with nil options model (negative test) - result, response, operationErr := globalCatalogService.ListArtifacts(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct an instance of the ListArtifactsOptions model listArtifactsOptionsModel := new(globalcatalogv1.ListArtifactsOptions) listArtifactsOptionsModel.ObjectID = core.StringPtr("testString") listArtifactsOptionsModel.Account = core.StringPtr("testString") listArtifactsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with valid options model (positive test) - result, response, operationErr = globalCatalogService.ListArtifacts(listArtifactsOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - // Invoke operation with a Context to test a timeout error ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.ListArtifactsWithContext(ctx, listArtifactsOptionsModel) + _, _, operationErr := globalCatalogService.ListArtifactsWithContext(ctx, listArtifactsOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) // Disable retries and test again globalCatalogService.DisableRetries() - result, response, operationErr = globalCatalogService.ListArtifacts(listArtifactsOptionsModel) + result, response, operationErr := globalCatalogService.ListArtifacts(listArtifactsOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) Expect(result).ToNot(BeNil()) @@ -3889,11 +4570,56 @@ var _ = Describe(`GlobalCatalogV1`, func() { // Re-test the timeout error with retries disabled ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc2() - serverSleepTime = 100 * time.Millisecond _, _, operationErr = globalCatalogService.ListArtifactsWithContext(ctx, listArtifactsOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listArtifactsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"count": 5, "resources": [{"name": "Name", "updated": "2019-01-01T12:00:00.000Z", "url": "URL", "etag": "Etag", "size": 4}]}`) + })) + }) + It(`Invoke ListArtifacts successfully`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := globalCatalogService.ListArtifacts(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListArtifactsOptions model + listArtifactsOptionsModel := new(globalcatalogv1.ListArtifactsOptions) + listArtifactsOptionsModel.ObjectID = core.StringPtr("testString") + listArtifactsOptionsModel.Account = core.StringPtr("testString") + listArtifactsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = globalCatalogService.ListArtifacts(listArtifactsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) It(`Invoke ListArtifacts with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -3932,10 +4658,8 @@ var _ = Describe(`GlobalCatalogV1`, func() { Describe(`GetArtifact(getArtifactOptions *GetArtifactOptions)`, func() { getArtifactPath := "/testString/artifacts/testString" - var serverSleepTime time.Duration - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with timeout`, func() { BeforeEach(func() { - serverSleepTime = 0 testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -3946,9 +4670,8 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.Header["Accept"]).ToNot(BeNil()) Expect(req.Header["Accept"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - // Sleep a short time to support a timeout test - time.Sleep(serverSleepTime) + time.Sleep(100 * time.Millisecond) // Set mock response res.Header().Set("Content-type", "*/*") @@ -3956,7 +4679,7 @@ var _ = Describe(`GlobalCatalogV1`, func() { fmt.Fprintf(res, "%s", `This is a mock binary response.`) })) }) - It(`Invoke GetArtifact successfully`, func() { + It(`Invoke GetArtifact successfully with retries`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ URL: testServer.URL, Authenticator: &core.NoAuthAuthenticator{}, @@ -3965,12 +4688,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(globalCatalogService).ToNot(BeNil()) globalCatalogService.EnableRetries(0, 0) - // Invoke operation with nil options model (negative test) - result, response, operationErr := globalCatalogService.GetArtifact(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - Expect(result).To(BeNil()) - // Construct an instance of the GetArtifactOptions model getArtifactOptionsModel := new(globalcatalogv1.GetArtifactOptions) getArtifactOptionsModel.ObjectID = core.StringPtr("testString") @@ -3979,24 +4696,16 @@ var _ = Describe(`GlobalCatalogV1`, func() { getArtifactOptionsModel.Account = core.StringPtr("testString") getArtifactOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with valid options model (positive test) - result, response, operationErr = globalCatalogService.GetArtifact(getArtifactOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - Expect(result).ToNot(BeNil()) - // Invoke operation with a Context to test a timeout error ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc() - serverSleepTime = 100 * time.Millisecond - _, _, operationErr = globalCatalogService.GetArtifactWithContext(ctx, getArtifactOptionsModel) + _, _, operationErr := globalCatalogService.GetArtifactWithContext(ctx, getArtifactOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) // Disable retries and test again globalCatalogService.DisableRetries() - result, response, operationErr = globalCatalogService.GetArtifact(getArtifactOptionsModel) + result, response, operationErr := globalCatalogService.GetArtifact(getArtifactOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) Expect(result).ToNot(BeNil()) @@ -4004,11 +4713,60 @@ var _ = Describe(`GlobalCatalogV1`, func() { // Re-test the timeout error with retries disabled ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) defer cancelFunc2() - serverSleepTime = 100 * time.Millisecond _, _, operationErr = globalCatalogService.GetArtifactWithContext(ctx, getArtifactOptionsModel) Expect(operationErr).ToNot(BeNil()) Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) - serverSleepTime = time.Duration(0) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getArtifactPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.Header["Accept"]).ToNot(BeNil()) + Expect(req.Header["Accept"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) + Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) + // Set mock response + res.Header().Set("Content-type", "*/*") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `This is a mock binary response.`) + })) + }) + It(`Invoke GetArtifact successfully`, func() { + globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(globalCatalogService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := globalCatalogService.GetArtifact(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetArtifactOptions model + getArtifactOptionsModel := new(globalcatalogv1.GetArtifactOptions) + getArtifactOptionsModel.ObjectID = core.StringPtr("testString") + getArtifactOptionsModel.ArtifactID = core.StringPtr("testString") + getArtifactOptionsModel.Accept = core.StringPtr("testString") + getArtifactOptionsModel.Account = core.StringPtr("testString") + getArtifactOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = globalCatalogService.GetArtifact(getArtifactOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) It(`Invoke GetArtifact with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -4077,7 +4835,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.Header["Content-Type"]).ToNot(BeNil()) Expect(req.Header["Content-Type"][0]).To(Equal(fmt.Sprintf("%v", "testString"))) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - res.WriteHeader(200) })) }) @@ -4088,7 +4845,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { }) Expect(serviceErr).To(BeNil()) Expect(globalCatalogService).ToNot(BeNil()) - globalCatalogService.EnableRetries(0, 0) // Invoke operation with nil options model (negative test) response, operationErr := globalCatalogService.UploadArtifact(nil) @@ -4108,12 +4864,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { response, operationErr = globalCatalogService.UploadArtifact(uploadArtifactOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) - - // Disable retries and test again - globalCatalogService.DisableRetries() - response, operationErr = globalCatalogService.UploadArtifact(uploadArtifactOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) }) It(`Invoke UploadArtifact with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -4163,7 +4913,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(req.Method).To(Equal("DELETE")) Expect(req.URL.Query()["account"]).To(Equal([]string{"testString"})) - res.WriteHeader(200) })) }) @@ -4174,7 +4923,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { }) Expect(serviceErr).To(BeNil()) Expect(globalCatalogService).ToNot(BeNil()) - globalCatalogService.EnableRetries(0, 0) // Invoke operation with nil options model (negative test) response, operationErr := globalCatalogService.DeleteArtifact(nil) @@ -4192,12 +4940,6 @@ var _ = Describe(`GlobalCatalogV1`, func() { response, operationErr = globalCatalogService.DeleteArtifact(deleteArtifactOptionsModel) Expect(operationErr).To(BeNil()) Expect(response).ToNot(BeNil()) - - // Disable retries and test again - globalCatalogService.DisableRetries() - response, operationErr = globalCatalogService.DeleteArtifact(deleteArtifactOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) }) It(`Invoke DeleteArtifact with error: Operation validation and request error`, func() { globalCatalogService, serviceErr := globalcatalogv1.NewGlobalCatalogV1(&globalcatalogv1.GlobalCatalogV1Options{ @@ -4738,7 +5480,7 @@ var _ = Describe(`GlobalCatalogV1`, func() { getCatalogEntryOptionsModel.SetAccount("testString") getCatalogEntryOptionsModel.SetInclude("testString") getCatalogEntryOptionsModel.SetLanguages("testString") - getCatalogEntryOptionsModel.SetComplete("testString") + getCatalogEntryOptionsModel.SetComplete(true) getCatalogEntryOptionsModel.SetDepth(int64(38)) getCatalogEntryOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(getCatalogEntryOptionsModel).ToNot(BeNil()) @@ -4746,7 +5488,7 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(getCatalogEntryOptionsModel.Account).To(Equal(core.StringPtr("testString"))) Expect(getCatalogEntryOptionsModel.Include).To(Equal(core.StringPtr("testString"))) Expect(getCatalogEntryOptionsModel.Languages).To(Equal(core.StringPtr("testString"))) - Expect(getCatalogEntryOptionsModel.Complete).To(Equal(core.StringPtr("testString"))) + Expect(getCatalogEntryOptionsModel.Complete).To(Equal(core.BoolPtr(true))) Expect(getCatalogEntryOptionsModel.Depth).To(Equal(core.Int64Ptr(int64(38)))) Expect(getCatalogEntryOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) @@ -4763,7 +5505,7 @@ var _ = Describe(`GlobalCatalogV1`, func() { getChildObjectsOptionsModel.SetSortBy("testString") getChildObjectsOptionsModel.SetDescending("testString") getChildObjectsOptionsModel.SetLanguages("testString") - getChildObjectsOptionsModel.SetComplete("testString") + getChildObjectsOptionsModel.SetComplete(true) getChildObjectsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(getChildObjectsOptionsModel).ToNot(BeNil()) Expect(getChildObjectsOptionsModel.ID).To(Equal(core.StringPtr("testString"))) @@ -4774,7 +5516,7 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(getChildObjectsOptionsModel.SortBy).To(Equal(core.StringPtr("testString"))) Expect(getChildObjectsOptionsModel.Descending).To(Equal(core.StringPtr("testString"))) Expect(getChildObjectsOptionsModel.Languages).To(Equal(core.StringPtr("testString"))) - Expect(getChildObjectsOptionsModel.Complete).To(Equal(core.StringPtr("testString"))) + Expect(getChildObjectsOptionsModel.Complete).To(Equal(core.BoolPtr(true))) Expect(getChildObjectsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewGetPricingOptions successfully`, func() { @@ -4828,7 +5570,10 @@ var _ = Describe(`GlobalCatalogV1`, func() { listCatalogEntriesOptionsModel.SetSortBy("testString") listCatalogEntriesOptionsModel.SetDescending("testString") listCatalogEntriesOptionsModel.SetLanguages("testString") - listCatalogEntriesOptionsModel.SetComplete("testString") + listCatalogEntriesOptionsModel.SetCatalog(true) + listCatalogEntriesOptionsModel.SetComplete(true) + listCatalogEntriesOptionsModel.SetOffset(int64(38)) + listCatalogEntriesOptionsModel.SetLimit(int64(200)) listCatalogEntriesOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(listCatalogEntriesOptionsModel).ToNot(BeNil()) Expect(listCatalogEntriesOptionsModel.Account).To(Equal(core.StringPtr("testString"))) @@ -4837,7 +5582,10 @@ var _ = Describe(`GlobalCatalogV1`, func() { Expect(listCatalogEntriesOptionsModel.SortBy).To(Equal(core.StringPtr("testString"))) Expect(listCatalogEntriesOptionsModel.Descending).To(Equal(core.StringPtr("testString"))) Expect(listCatalogEntriesOptionsModel.Languages).To(Equal(core.StringPtr("testString"))) - Expect(listCatalogEntriesOptionsModel.Complete).To(Equal(core.StringPtr("testString"))) + Expect(listCatalogEntriesOptionsModel.Catalog).To(Equal(core.BoolPtr(true))) + Expect(listCatalogEntriesOptionsModel.Complete).To(Equal(core.BoolPtr(true))) + Expect(listCatalogEntriesOptionsModel.Offset).To(Equal(core.Int64Ptr(int64(38)))) + Expect(listCatalogEntriesOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(200)))) Expect(listCatalogEntriesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewOverview successfully`, func() {