diff --git a/.secrets.baseline b/.secrets.baseline index 04f09684..3116ed80 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "go.sum|^.secrets.baseline$|_test.go|package-lock.json|.cra/.cveignore", "lines": null }, - "generated_at": "2022-11-01T19:28:02Z", + "generated_at": "2022-11-03T17:59:31Z", "plugins_used": [ { "name": "AWSKeyDetector" diff --git a/enterprisemanagementv1/enterprise_management_v1.go b/enterprisemanagementv1/enterprise_management_v1.go index 8833f025..31df9444 100644 --- a/enterprisemanagementv1/enterprise_management_v1.go +++ b/enterprisemanagementv1/enterprise_management_v1.go @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2021. + * (C) Copyright IBM Corp. 2021, 2022. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ /* - * IBM OpenAPI SDK Code Generator Version: 3.30.0-bd714324-20210406-200538 + * IBM OpenAPI SDK Code Generator Version: 3.60.2-95dc7721-20221102-203229 */ // Package enterprisemanagementv1 : Operations and models for the EnterpriseManagementV1 service @@ -37,7 +37,7 @@ import ( // EnterpriseManagementV1 : The Enterprise Management API enables you to create and manage an enterprise, account // groups, and accounts within the enterprise. // -// Version: 1.0 +// API Version: 1.0 type EnterpriseManagementV1 struct { Service *core.BaseService } @@ -230,11 +230,13 @@ func (enterpriseManagement *EnterpriseManagementV1) CreateEnterpriseWithContext( if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateEnterpriseResponse) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateEnterpriseResponse) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -303,11 +305,13 @@ func (enterpriseManagement *EnterpriseManagementV1) ListEnterprisesWithContext(c if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalListEnterprisesResponse) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalListEnterprisesResponse) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -362,11 +366,13 @@ func (enterpriseManagement *EnterpriseManagementV1) GetEnterpriseWithContext(ctx if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalEnterprise) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalEnterprise) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -568,11 +574,13 @@ func (enterpriseManagement *EnterpriseManagementV1) CreateAccountWithContext(ctx if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateAccountResponse) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateAccountResponse) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -642,11 +650,13 @@ func (enterpriseManagement *EnterpriseManagementV1) ListAccountsWithContext(ctx if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalListAccountsResponse) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalListAccountsResponse) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -701,11 +711,13 @@ func (enterpriseManagement *EnterpriseManagementV1) GetAccountWithContext(ctx co if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalAccount) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalAccount) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -831,11 +843,13 @@ func (enterpriseManagement *EnterpriseManagementV1) CreateAccountGroupWithContex if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateAccountGroupResponse) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreateAccountGroupResponse) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -906,11 +920,13 @@ func (enterpriseManagement *EnterpriseManagementV1) ListAccountGroupsWithContext if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalListAccountGroupsResponse) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalListAccountGroupsResponse) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -965,11 +981,13 @@ func (enterpriseManagement *EnterpriseManagementV1) GetAccountGroupWithContext(c if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalAccountGroup) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalAccountGroup) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -1284,13 +1302,13 @@ func UnmarshalAccountGroup(m map[string]json.RawMessage, result interface{}) (er type CreateAccountGroupOptions struct { // The CRN of the parent under which the account group will be created. The parent can be an existing account group or // the enterprise itself. - Parent *string `validate:"required"` + Parent *string `json:"parent" validate:"required"` // The name of the account group. This field must have 3 - 60 characters. - Name *string `validate:"required"` + Name *string `json:"name" validate:"required"` // The IAM ID of the primary contact for this account group, such as `IBMid-0123ABC`. The IAM ID must already exist. - PrimaryContactIamID *string `validate:"required"` + PrimaryContactIamID *string `json:"primary_contact_iam_id" validate:"required"` // Allows users to set headers on API requests Headers map[string]string @@ -1306,21 +1324,21 @@ func (*EnterpriseManagementV1) NewCreateAccountGroupOptions(parent string, name } // SetParent : Allow user to set Parent -func (options *CreateAccountGroupOptions) SetParent(parent string) *CreateAccountGroupOptions { - options.Parent = core.StringPtr(parent) - return options +func (_options *CreateAccountGroupOptions) SetParent(parent string) *CreateAccountGroupOptions { + _options.Parent = core.StringPtr(parent) + return _options } // SetName : Allow user to set Name -func (options *CreateAccountGroupOptions) SetName(name string) *CreateAccountGroupOptions { - options.Name = core.StringPtr(name) - return options +func (_options *CreateAccountGroupOptions) SetName(name string) *CreateAccountGroupOptions { + _options.Name = core.StringPtr(name) + return _options } // SetPrimaryContactIamID : Allow user to set PrimaryContactIamID -func (options *CreateAccountGroupOptions) SetPrimaryContactIamID(primaryContactIamID string) *CreateAccountGroupOptions { - options.PrimaryContactIamID = core.StringPtr(primaryContactIamID) - return options +func (_options *CreateAccountGroupOptions) SetPrimaryContactIamID(primaryContactIamID string) *CreateAccountGroupOptions { + _options.PrimaryContactIamID = core.StringPtr(primaryContactIamID) + return _options } // SetHeaders : Allow user to set Headers @@ -1350,13 +1368,13 @@ func UnmarshalCreateAccountGroupResponse(m map[string]json.RawMessage, result in type CreateAccountOptions struct { // The CRN of the parent under which the account will be created. The parent can be an existing account group or the // enterprise itself. - Parent *string `validate:"required"` + Parent *string `json:"parent" validate:"required"` // The name of the account. This field must have 3 - 60 characters. - Name *string `validate:"required"` + Name *string `json:"name" validate:"required"` // The IAM ID of the account owner, such as `IBMid-0123ABC`. The IAM ID must already exist. - OwnerIamID *string `validate:"required"` + OwnerIamID *string `json:"owner_iam_id" validate:"required"` // Allows users to set headers on API requests Headers map[string]string @@ -1372,21 +1390,21 @@ func (*EnterpriseManagementV1) NewCreateAccountOptions(parent string, name strin } // SetParent : Allow user to set Parent -func (options *CreateAccountOptions) SetParent(parent string) *CreateAccountOptions { - options.Parent = core.StringPtr(parent) - return options +func (_options *CreateAccountOptions) SetParent(parent string) *CreateAccountOptions { + _options.Parent = core.StringPtr(parent) + return _options } // SetName : Allow user to set Name -func (options *CreateAccountOptions) SetName(name string) *CreateAccountOptions { - options.Name = core.StringPtr(name) - return options +func (_options *CreateAccountOptions) SetName(name string) *CreateAccountOptions { + _options.Name = core.StringPtr(name) + return _options } // SetOwnerIamID : Allow user to set OwnerIamID -func (options *CreateAccountOptions) SetOwnerIamID(ownerIamID string) *CreateAccountOptions { - options.OwnerIamID = core.StringPtr(ownerIamID) - return options +func (_options *CreateAccountOptions) SetOwnerIamID(ownerIamID string) *CreateAccountOptions { + _options.OwnerIamID = core.StringPtr(ownerIamID) + return _options } // SetHeaders : Allow user to set Headers @@ -1415,16 +1433,16 @@ func UnmarshalCreateAccountResponse(m map[string]json.RawMessage, result interfa // CreateEnterpriseOptions : The CreateEnterprise options. type CreateEnterpriseOptions struct { // The ID of the account that is used to create the enterprise. - SourceAccountID *string `validate:"required"` + SourceAccountID *string `json:"source_account_id" validate:"required"` // The name of the enterprise. This field must have 3 - 60 characters. - Name *string `validate:"required"` + Name *string `json:"name" validate:"required"` // The IAM ID of the enterprise primary contact, such as `IBMid-0123ABC`. The IAM ID must already exist. - PrimaryContactIamID *string `validate:"required"` + PrimaryContactIamID *string `json:"primary_contact_iam_id" validate:"required"` // A domain or subdomain for the enterprise, such as `example.com` or `my.example.com`. - Domain *string + Domain *string `json:"domain,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -1440,27 +1458,27 @@ func (*EnterpriseManagementV1) NewCreateEnterpriseOptions(sourceAccountID string } // SetSourceAccountID : Allow user to set SourceAccountID -func (options *CreateEnterpriseOptions) SetSourceAccountID(sourceAccountID string) *CreateEnterpriseOptions { - options.SourceAccountID = core.StringPtr(sourceAccountID) - return options +func (_options *CreateEnterpriseOptions) SetSourceAccountID(sourceAccountID string) *CreateEnterpriseOptions { + _options.SourceAccountID = core.StringPtr(sourceAccountID) + return _options } // SetName : Allow user to set Name -func (options *CreateEnterpriseOptions) SetName(name string) *CreateEnterpriseOptions { - options.Name = core.StringPtr(name) - return options +func (_options *CreateEnterpriseOptions) SetName(name string) *CreateEnterpriseOptions { + _options.Name = core.StringPtr(name) + return _options } // SetPrimaryContactIamID : Allow user to set PrimaryContactIamID -func (options *CreateEnterpriseOptions) SetPrimaryContactIamID(primaryContactIamID string) *CreateEnterpriseOptions { - options.PrimaryContactIamID = core.StringPtr(primaryContactIamID) - return options +func (_options *CreateEnterpriseOptions) SetPrimaryContactIamID(primaryContactIamID string) *CreateEnterpriseOptions { + _options.PrimaryContactIamID = core.StringPtr(primaryContactIamID) + return _options } // SetDomain : Allow user to set Domain -func (options *CreateEnterpriseOptions) SetDomain(domain string) *CreateEnterpriseOptions { - options.Domain = core.StringPtr(domain) - return options +func (_options *CreateEnterpriseOptions) SetDomain(domain string) *CreateEnterpriseOptions { + _options.Domain = core.StringPtr(domain) + return _options } // SetHeaders : Allow user to set Headers @@ -1598,7 +1616,7 @@ func UnmarshalEnterprise(m map[string]json.RawMessage, result interface{}) (err // GetAccountGroupOptions : The GetAccountGroup options. type GetAccountGroupOptions struct { // The ID of the account group to retrieve. - AccountGroupID *string `validate:"required,ne="` + AccountGroupID *string `json:"account_group_id" validate:"required,ne="` // Allows users to set headers on API requests Headers map[string]string @@ -1612,9 +1630,9 @@ func (*EnterpriseManagementV1) NewGetAccountGroupOptions(accountGroupID string) } // SetAccountGroupID : Allow user to set AccountGroupID -func (options *GetAccountGroupOptions) SetAccountGroupID(accountGroupID string) *GetAccountGroupOptions { - options.AccountGroupID = core.StringPtr(accountGroupID) - return options +func (_options *GetAccountGroupOptions) SetAccountGroupID(accountGroupID string) *GetAccountGroupOptions { + _options.AccountGroupID = core.StringPtr(accountGroupID) + return _options } // SetHeaders : Allow user to set Headers @@ -1626,7 +1644,7 @@ func (options *GetAccountGroupOptions) SetHeaders(param map[string]string) *GetA // GetAccountOptions : The GetAccount options. type GetAccountOptions struct { // The ID of the account to retrieve. - AccountID *string `validate:"required,ne="` + AccountID *string `json:"account_id" validate:"required,ne="` // Allows users to set headers on API requests Headers map[string]string @@ -1640,9 +1658,9 @@ func (*EnterpriseManagementV1) NewGetAccountOptions(accountID string) *GetAccoun } // SetAccountID : Allow user to set AccountID -func (options *GetAccountOptions) SetAccountID(accountID string) *GetAccountOptions { - options.AccountID = core.StringPtr(accountID) - return options +func (_options *GetAccountOptions) SetAccountID(accountID string) *GetAccountOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } // SetHeaders : Allow user to set Headers @@ -1654,7 +1672,7 @@ func (options *GetAccountOptions) SetHeaders(param map[string]string) *GetAccoun // GetEnterpriseOptions : The GetEnterprise options. type GetEnterpriseOptions struct { // The ID of the enterprise to retrieve. - EnterpriseID *string `validate:"required,ne="` + EnterpriseID *string `json:"enterprise_id" validate:"required,ne="` // Allows users to set headers on API requests Headers map[string]string @@ -1668,9 +1686,9 @@ func (*EnterpriseManagementV1) NewGetEnterpriseOptions(enterpriseID string) *Get } // SetEnterpriseID : Allow user to set EnterpriseID -func (options *GetEnterpriseOptions) SetEnterpriseID(enterpriseID string) *GetEnterpriseOptions { - options.EnterpriseID = core.StringPtr(enterpriseID) - return options +func (_options *GetEnterpriseOptions) SetEnterpriseID(enterpriseID string) *GetEnterpriseOptions { + _options.EnterpriseID = core.StringPtr(enterpriseID) + return _options } // SetHeaders : Allow user to set Headers @@ -1682,18 +1700,18 @@ func (options *GetEnterpriseOptions) SetHeaders(param map[string]string) *GetEnt // ImportAccountToEnterpriseOptions : The ImportAccountToEnterprise options. type ImportAccountToEnterpriseOptions struct { // The ID of the enterprise to import the stand-alone account into. - EnterpriseID *string `validate:"required,ne="` + EnterpriseID *string `json:"enterprise_id" validate:"required,ne="` // The ID of the existing stand-alone account to be imported. - AccountID *string `validate:"required,ne="` + AccountID *string `json:"account_id" validate:"required,ne="` // The CRN of the expected parent of the imported account. The parent is the enterprise or account group that the // account is added to. - Parent *string + Parent *string `json:"parent,omitempty"` // The ID of the [billing unit](/apidocs/enterprise-apis/billing-unit) to use for billing this account in the // enterprise. - BillingUnitID *string + BillingUnitID *string `json:"billing_unit_id,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -1708,27 +1726,27 @@ func (*EnterpriseManagementV1) NewImportAccountToEnterpriseOptions(enterpriseID } // SetEnterpriseID : Allow user to set EnterpriseID -func (options *ImportAccountToEnterpriseOptions) SetEnterpriseID(enterpriseID string) *ImportAccountToEnterpriseOptions { - options.EnterpriseID = core.StringPtr(enterpriseID) - return options +func (_options *ImportAccountToEnterpriseOptions) SetEnterpriseID(enterpriseID string) *ImportAccountToEnterpriseOptions { + _options.EnterpriseID = core.StringPtr(enterpriseID) + return _options } // SetAccountID : Allow user to set AccountID -func (options *ImportAccountToEnterpriseOptions) SetAccountID(accountID string) *ImportAccountToEnterpriseOptions { - options.AccountID = core.StringPtr(accountID) - return options +func (_options *ImportAccountToEnterpriseOptions) SetAccountID(accountID string) *ImportAccountToEnterpriseOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } // SetParent : Allow user to set Parent -func (options *ImportAccountToEnterpriseOptions) SetParent(parent string) *ImportAccountToEnterpriseOptions { - options.Parent = core.StringPtr(parent) - return options +func (_options *ImportAccountToEnterpriseOptions) SetParent(parent string) *ImportAccountToEnterpriseOptions { + _options.Parent = core.StringPtr(parent) + return _options } // SetBillingUnitID : Allow user to set BillingUnitID -func (options *ImportAccountToEnterpriseOptions) SetBillingUnitID(billingUnitID string) *ImportAccountToEnterpriseOptions { - options.BillingUnitID = core.StringPtr(billingUnitID) - return options +func (_options *ImportAccountToEnterpriseOptions) SetBillingUnitID(billingUnitID string) *ImportAccountToEnterpriseOptions { + _options.BillingUnitID = core.StringPtr(billingUnitID) + return _options } // SetHeaders : Allow user to set Headers @@ -1740,20 +1758,20 @@ func (options *ImportAccountToEnterpriseOptions) SetHeaders(param map[string]str // ListAccountGroupsOptions : The ListAccountGroups options. type ListAccountGroupsOptions struct { // Get account groups that are either immediate children or are a part of the hierarchy for a given enterprise ID. - EnterpriseID *string + EnterpriseID *string `json:"enterprise_id,omitempty"` // Get account groups that are either immediate children or are a part of the hierarchy for a given account group ID. - ParentAccountGroupID *string + ParentAccountGroupID *string `json:"parent_account_group_id,omitempty"` // The first item to be returned in the page of results. This value can be obtained from the next_url property from the // previous call of the operation. If not specified, then the first page of results is returned. - NextDocid *string + NextDocid *string `json:"next_docid,omitempty"` // Get account groups that are either immediate children or are a part of the hierarchy for a given parent CRN. - Parent *string + Parent *string `json:"parent,omitempty"` // Return results up to this limit. Valid values are between `0` and `100`. - Limit *int64 + Limit *int64 `json:"limit,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -1765,33 +1783,33 @@ func (*EnterpriseManagementV1) NewListAccountGroupsOptions() *ListAccountGroupsO } // SetEnterpriseID : Allow user to set EnterpriseID -func (options *ListAccountGroupsOptions) SetEnterpriseID(enterpriseID string) *ListAccountGroupsOptions { - options.EnterpriseID = core.StringPtr(enterpriseID) - return options +func (_options *ListAccountGroupsOptions) SetEnterpriseID(enterpriseID string) *ListAccountGroupsOptions { + _options.EnterpriseID = core.StringPtr(enterpriseID) + return _options } // SetParentAccountGroupID : Allow user to set ParentAccountGroupID -func (options *ListAccountGroupsOptions) SetParentAccountGroupID(parentAccountGroupID string) *ListAccountGroupsOptions { - options.ParentAccountGroupID = core.StringPtr(parentAccountGroupID) - return options +func (_options *ListAccountGroupsOptions) SetParentAccountGroupID(parentAccountGroupID string) *ListAccountGroupsOptions { + _options.ParentAccountGroupID = core.StringPtr(parentAccountGroupID) + return _options } // SetNextDocid : Allow user to set NextDocid -func (options *ListAccountGroupsOptions) SetNextDocid(nextDocid string) *ListAccountGroupsOptions { - options.NextDocid = core.StringPtr(nextDocid) - return options +func (_options *ListAccountGroupsOptions) SetNextDocid(nextDocid string) *ListAccountGroupsOptions { + _options.NextDocid = core.StringPtr(nextDocid) + return _options } // SetParent : Allow user to set Parent -func (options *ListAccountGroupsOptions) SetParent(parent string) *ListAccountGroupsOptions { - options.Parent = core.StringPtr(parent) - return options +func (_options *ListAccountGroupsOptions) SetParent(parent string) *ListAccountGroupsOptions { + _options.Parent = core.StringPtr(parent) + return _options } // SetLimit : Allow user to set Limit -func (options *ListAccountGroupsOptions) SetLimit(limit int64) *ListAccountGroupsOptions { - options.Limit = core.Int64Ptr(limit) - return options +func (_options *ListAccountGroupsOptions) SetLimit(limit int64) *ListAccountGroupsOptions { + _options.Limit = core.Int64Ptr(limit) + return _options } // SetHeaders : Allow user to set Headers @@ -1831,23 +1849,35 @@ func UnmarshalListAccountGroupsResponse(m map[string]json.RawMessage, result int return } +// Retrieve the value to be passed to a request to access the next page of results +func (resp *ListAccountGroupsResponse) GetNextNextDocid() (*string, error) { + if core.IsNil(resp.NextURL) { + return nil, nil + } + next_docid, err := core.GetQueryParam(resp.NextURL, "next_docid") + if err != nil || next_docid == nil { + return nil, err + } + return next_docid, nil +} + // ListAccountsOptions : The ListAccounts options. type ListAccountsOptions struct { // Get accounts that are either immediate children or are a part of the hierarchy for a given enterprise ID. - EnterpriseID *string + EnterpriseID *string `json:"enterprise_id,omitempty"` // Get accounts that are either immediate children or are a part of the hierarchy for a given account group ID. - AccountGroupID *string + AccountGroupID *string `json:"account_group_id,omitempty"` // The first item to be returned in the page of results. This value can be obtained from the next_url property from the // previous call of the operation. If not specified, then the first page of results is returned. - NextDocid *string + NextDocid *string `json:"next_docid,omitempty"` // Get accounts that are either immediate children or are a part of the hierarchy for a given parent CRN. - Parent *string + Parent *string `json:"parent,omitempty"` // Return results up to this limit. Valid values are between `0` and `100`. - Limit *int64 + Limit *int64 `json:"limit,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -1859,33 +1889,33 @@ func (*EnterpriseManagementV1) NewListAccountsOptions() *ListAccountsOptions { } // SetEnterpriseID : Allow user to set EnterpriseID -func (options *ListAccountsOptions) SetEnterpriseID(enterpriseID string) *ListAccountsOptions { - options.EnterpriseID = core.StringPtr(enterpriseID) - return options +func (_options *ListAccountsOptions) SetEnterpriseID(enterpriseID string) *ListAccountsOptions { + _options.EnterpriseID = core.StringPtr(enterpriseID) + return _options } // SetAccountGroupID : Allow user to set AccountGroupID -func (options *ListAccountsOptions) SetAccountGroupID(accountGroupID string) *ListAccountsOptions { - options.AccountGroupID = core.StringPtr(accountGroupID) - return options +func (_options *ListAccountsOptions) SetAccountGroupID(accountGroupID string) *ListAccountsOptions { + _options.AccountGroupID = core.StringPtr(accountGroupID) + return _options } // SetNextDocid : Allow user to set NextDocid -func (options *ListAccountsOptions) SetNextDocid(nextDocid string) *ListAccountsOptions { - options.NextDocid = core.StringPtr(nextDocid) - return options +func (_options *ListAccountsOptions) SetNextDocid(nextDocid string) *ListAccountsOptions { + _options.NextDocid = core.StringPtr(nextDocid) + return _options } // SetParent : Allow user to set Parent -func (options *ListAccountsOptions) SetParent(parent string) *ListAccountsOptions { - options.Parent = core.StringPtr(parent) - return options +func (_options *ListAccountsOptions) SetParent(parent string) *ListAccountsOptions { + _options.Parent = core.StringPtr(parent) + return _options } // SetLimit : Allow user to set Limit -func (options *ListAccountsOptions) SetLimit(limit int64) *ListAccountsOptions { - options.Limit = core.Int64Ptr(limit) - return options +func (_options *ListAccountsOptions) SetLimit(limit int64) *ListAccountsOptions { + _options.Limit = core.Int64Ptr(limit) + return _options } // SetHeaders : Allow user to set Headers @@ -1925,23 +1955,35 @@ func UnmarshalListAccountsResponse(m map[string]json.RawMessage, result interfac return } +// Retrieve the value to be passed to a request to access the next page of results +func (resp *ListAccountsResponse) GetNextNextDocid() (*string, error) { + if core.IsNil(resp.NextURL) { + return nil, nil + } + next_docid, err := core.GetQueryParam(resp.NextURL, "next_docid") + if err != nil || next_docid == nil { + return nil, err + } + return next_docid, nil +} + // ListEnterprisesOptions : The ListEnterprises options. type ListEnterprisesOptions struct { // Get enterprises for a given enterprise account ID. - EnterpriseAccountID *string + EnterpriseAccountID *string `json:"enterprise_account_id,omitempty"` // Get enterprises for a given account group ID. - AccountGroupID *string + AccountGroupID *string `json:"account_group_id,omitempty"` // Get enterprises for a given account ID. - AccountID *string + AccountID *string `json:"account_id,omitempty"` // The first item to be returned in the page of results. This value can be obtained from the next_url property from the // previous call of the operation. If not specified, then the first page of results is returned. - NextDocid *string + NextDocid *string `json:"next_docid,omitempty"` // Return results up to this limit. Valid values are between `0` and `100`. - Limit *int64 + Limit *int64 `json:"limit,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -1953,33 +1995,33 @@ func (*EnterpriseManagementV1) NewListEnterprisesOptions() *ListEnterprisesOptio } // SetEnterpriseAccountID : Allow user to set EnterpriseAccountID -func (options *ListEnterprisesOptions) SetEnterpriseAccountID(enterpriseAccountID string) *ListEnterprisesOptions { - options.EnterpriseAccountID = core.StringPtr(enterpriseAccountID) - return options +func (_options *ListEnterprisesOptions) SetEnterpriseAccountID(enterpriseAccountID string) *ListEnterprisesOptions { + _options.EnterpriseAccountID = core.StringPtr(enterpriseAccountID) + return _options } // SetAccountGroupID : Allow user to set AccountGroupID -func (options *ListEnterprisesOptions) SetAccountGroupID(accountGroupID string) *ListEnterprisesOptions { - options.AccountGroupID = core.StringPtr(accountGroupID) - return options +func (_options *ListEnterprisesOptions) SetAccountGroupID(accountGroupID string) *ListEnterprisesOptions { + _options.AccountGroupID = core.StringPtr(accountGroupID) + return _options } // SetAccountID : Allow user to set AccountID -func (options *ListEnterprisesOptions) SetAccountID(accountID string) *ListEnterprisesOptions { - options.AccountID = core.StringPtr(accountID) - return options +func (_options *ListEnterprisesOptions) SetAccountID(accountID string) *ListEnterprisesOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } // SetNextDocid : Allow user to set NextDocid -func (options *ListEnterprisesOptions) SetNextDocid(nextDocid string) *ListEnterprisesOptions { - options.NextDocid = core.StringPtr(nextDocid) - return options +func (_options *ListEnterprisesOptions) SetNextDocid(nextDocid string) *ListEnterprisesOptions { + _options.NextDocid = core.StringPtr(nextDocid) + return _options } // SetLimit : Allow user to set Limit -func (options *ListEnterprisesOptions) SetLimit(limit int64) *ListEnterprisesOptions { - options.Limit = core.Int64Ptr(limit) - return options +func (_options *ListEnterprisesOptions) SetLimit(limit int64) *ListEnterprisesOptions { + _options.Limit = core.Int64Ptr(limit) + return _options } // SetHeaders : Allow user to set Headers @@ -2019,16 +2061,28 @@ func UnmarshalListEnterprisesResponse(m map[string]json.RawMessage, result inter return } +// Retrieve the value to be passed to a request to access the next page of results +func (resp *ListEnterprisesResponse) GetNextNextDocid() (*string, error) { + if core.IsNil(resp.NextURL) { + return nil, nil + } + next_docid, err := core.GetQueryParam(resp.NextURL, "next_docid") + if err != nil || next_docid == nil { + return nil, err + } + return next_docid, nil +} + // UpdateAccountGroupOptions : The UpdateAccountGroup options. type UpdateAccountGroupOptions struct { // The ID of the account group to retrieve. - AccountGroupID *string `validate:"required,ne="` + AccountGroupID *string `json:"account_group_id" validate:"required,ne="` // The new name of the account group. This field must have 3 - 60 characters. - Name *string + Name *string `json:"name,omitempty"` // The IAM ID of the user to be the new primary contact for the account group. - PrimaryContactIamID *string + PrimaryContactIamID *string `json:"primary_contact_iam_id,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -2042,21 +2096,21 @@ func (*EnterpriseManagementV1) NewUpdateAccountGroupOptions(accountGroupID strin } // SetAccountGroupID : Allow user to set AccountGroupID -func (options *UpdateAccountGroupOptions) SetAccountGroupID(accountGroupID string) *UpdateAccountGroupOptions { - options.AccountGroupID = core.StringPtr(accountGroupID) - return options +func (_options *UpdateAccountGroupOptions) SetAccountGroupID(accountGroupID string) *UpdateAccountGroupOptions { + _options.AccountGroupID = core.StringPtr(accountGroupID) + return _options } // SetName : Allow user to set Name -func (options *UpdateAccountGroupOptions) SetName(name string) *UpdateAccountGroupOptions { - options.Name = core.StringPtr(name) - return options +func (_options *UpdateAccountGroupOptions) SetName(name string) *UpdateAccountGroupOptions { + _options.Name = core.StringPtr(name) + return _options } // SetPrimaryContactIamID : Allow user to set PrimaryContactIamID -func (options *UpdateAccountGroupOptions) SetPrimaryContactIamID(primaryContactIamID string) *UpdateAccountGroupOptions { - options.PrimaryContactIamID = core.StringPtr(primaryContactIamID) - return options +func (_options *UpdateAccountGroupOptions) SetPrimaryContactIamID(primaryContactIamID string) *UpdateAccountGroupOptions { + _options.PrimaryContactIamID = core.StringPtr(primaryContactIamID) + return _options } // SetHeaders : Allow user to set Headers @@ -2068,10 +2122,10 @@ func (options *UpdateAccountGroupOptions) SetHeaders(param map[string]string) *U // UpdateAccountOptions : The UpdateAccount options. type UpdateAccountOptions struct { // The ID of the account to retrieve. - AccountID *string `validate:"required,ne="` + AccountID *string `json:"account_id" validate:"required,ne="` // The CRN of the new parent within the enterprise. - Parent *string `validate:"required"` + Parent *string `json:"parent" validate:"required"` // Allows users to set headers on API requests Headers map[string]string @@ -2086,15 +2140,15 @@ func (*EnterpriseManagementV1) NewUpdateAccountOptions(accountID string, parent } // SetAccountID : Allow user to set AccountID -func (options *UpdateAccountOptions) SetAccountID(accountID string) *UpdateAccountOptions { - options.AccountID = core.StringPtr(accountID) - return options +func (_options *UpdateAccountOptions) SetAccountID(accountID string) *UpdateAccountOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } // SetParent : Allow user to set Parent -func (options *UpdateAccountOptions) SetParent(parent string) *UpdateAccountOptions { - options.Parent = core.StringPtr(parent) - return options +func (_options *UpdateAccountOptions) SetParent(parent string) *UpdateAccountOptions { + _options.Parent = core.StringPtr(parent) + return _options } // SetHeaders : Allow user to set Headers @@ -2106,16 +2160,16 @@ func (options *UpdateAccountOptions) SetHeaders(param map[string]string) *Update // UpdateEnterpriseOptions : The UpdateEnterprise options. type UpdateEnterpriseOptions struct { // The ID of the enterprise to retrieve. - EnterpriseID *string `validate:"required,ne="` + EnterpriseID *string `json:"enterprise_id" validate:"required,ne="` // The new name of the enterprise. This field must have 3 - 60 characters. - Name *string + Name *string `json:"name,omitempty"` // The new domain of the enterprise. This field has a limit of 60 characters. - Domain *string + Domain *string `json:"domain,omitempty"` // The IAM ID of the user to be the new primary contact for the enterprise. - PrimaryContactIamID *string + PrimaryContactIamID *string `json:"primary_contact_iam_id,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -2129,27 +2183,27 @@ func (*EnterpriseManagementV1) NewUpdateEnterpriseOptions(enterpriseID string) * } // SetEnterpriseID : Allow user to set EnterpriseID -func (options *UpdateEnterpriseOptions) SetEnterpriseID(enterpriseID string) *UpdateEnterpriseOptions { - options.EnterpriseID = core.StringPtr(enterpriseID) - return options +func (_options *UpdateEnterpriseOptions) SetEnterpriseID(enterpriseID string) *UpdateEnterpriseOptions { + _options.EnterpriseID = core.StringPtr(enterpriseID) + return _options } // SetName : Allow user to set Name -func (options *UpdateEnterpriseOptions) SetName(name string) *UpdateEnterpriseOptions { - options.Name = core.StringPtr(name) - return options +func (_options *UpdateEnterpriseOptions) SetName(name string) *UpdateEnterpriseOptions { + _options.Name = core.StringPtr(name) + return _options } // SetDomain : Allow user to set Domain -func (options *UpdateEnterpriseOptions) SetDomain(domain string) *UpdateEnterpriseOptions { - options.Domain = core.StringPtr(domain) - return options +func (_options *UpdateEnterpriseOptions) SetDomain(domain string) *UpdateEnterpriseOptions { + _options.Domain = core.StringPtr(domain) + return _options } // SetPrimaryContactIamID : Allow user to set PrimaryContactIamID -func (options *UpdateEnterpriseOptions) SetPrimaryContactIamID(primaryContactIamID string) *UpdateEnterpriseOptions { - options.PrimaryContactIamID = core.StringPtr(primaryContactIamID) - return options +func (_options *UpdateEnterpriseOptions) SetPrimaryContactIamID(primaryContactIamID string) *UpdateEnterpriseOptions { + _options.PrimaryContactIamID = core.StringPtr(primaryContactIamID) + return _options } // SetHeaders : Allow user to set Headers @@ -2157,3 +2211,264 @@ func (options *UpdateEnterpriseOptions) SetHeaders(param map[string]string) *Upd options.Headers = param return options } + +// +// EnterprisesPager can be used to simplify the use of the "ListEnterprises" method. +// +type EnterprisesPager struct { + hasNext bool + options *ListEnterprisesOptions + client *EnterpriseManagementV1 + pageContext struct { + next *string + } +} + +// NewEnterprisesPager returns a new EnterprisesPager instance. +func (enterpriseManagement *EnterpriseManagementV1) NewEnterprisesPager(options *ListEnterprisesOptions) (pager *EnterprisesPager, err error) { + if options.NextDocid != nil && *options.NextDocid != "" { + err = fmt.Errorf("the 'options.NextDocid' field should not be set") + return + } + + var optionsCopy ListEnterprisesOptions = *options + pager = &EnterprisesPager{ + hasNext: true, + options: &optionsCopy, + client: enterpriseManagement, + } + return +} + +// HasNext returns true if there are potentially more results to be retrieved. +func (pager *EnterprisesPager) HasNext() bool { + return pager.hasNext +} + +// GetNextWithContext returns the next page of results using the specified Context. +func (pager *EnterprisesPager) GetNextWithContext(ctx context.Context) (page []Enterprise, err error) { + if !pager.HasNext() { + return nil, fmt.Errorf("no more results available") + } + + pager.options.NextDocid = pager.pageContext.next + + result, _, err := pager.client.ListEnterprisesWithContext(ctx, pager.options) + if err != nil { + return + } + + var next *string + if result.NextURL != nil { + var next_docid *string + next_docid, err = core.GetQueryParam(result.NextURL, "next_docid") + if err != nil { + err = fmt.Errorf("error retrieving 'next_docid' query parameter from URL '%s': %s", *result.NextURL, err.Error()) + return + } + next = next_docid + } + pager.pageContext.next = next + pager.hasNext = (pager.pageContext.next != nil) + page = result.Resources + + return +} + +// GetAllWithContext returns all results by invoking GetNextWithContext() repeatedly +// until all pages of results have been retrieved. +func (pager *EnterprisesPager) GetAllWithContext(ctx context.Context) (allItems []Enterprise, err error) { + for pager.HasNext() { + var nextPage []Enterprise + nextPage, err = pager.GetNextWithContext(ctx) + if err != nil { + return + } + allItems = append(allItems, nextPage...) + } + return +} + +// GetNext invokes GetNextWithContext() using context.Background() as the Context parameter. +func (pager *EnterprisesPager) GetNext() (page []Enterprise, err error) { + return pager.GetNextWithContext(context.Background()) +} + +// GetAll invokes GetAllWithContext() using context.Background() as the Context parameter. +func (pager *EnterprisesPager) GetAll() (allItems []Enterprise, err error) { + return pager.GetAllWithContext(context.Background()) +} + +// +// AccountsPager can be used to simplify the use of the "ListAccounts" method. +// +type AccountsPager struct { + hasNext bool + options *ListAccountsOptions + client *EnterpriseManagementV1 + pageContext struct { + next *string + } +} + +// NewAccountsPager returns a new AccountsPager instance. +func (enterpriseManagement *EnterpriseManagementV1) NewAccountsPager(options *ListAccountsOptions) (pager *AccountsPager, err error) { + if options.NextDocid != nil && *options.NextDocid != "" { + err = fmt.Errorf("the 'options.NextDocid' field should not be set") + return + } + + var optionsCopy ListAccountsOptions = *options + pager = &AccountsPager{ + hasNext: true, + options: &optionsCopy, + client: enterpriseManagement, + } + return +} + +// HasNext returns true if there are potentially more results to be retrieved. +func (pager *AccountsPager) HasNext() bool { + return pager.hasNext +} + +// GetNextWithContext returns the next page of results using the specified Context. +func (pager *AccountsPager) GetNextWithContext(ctx context.Context) (page []Account, err error) { + if !pager.HasNext() { + return nil, fmt.Errorf("no more results available") + } + + pager.options.NextDocid = pager.pageContext.next + + result, _, err := pager.client.ListAccountsWithContext(ctx, pager.options) + if err != nil { + return + } + + var next *string + if result.NextURL != nil { + var next_docid *string + next_docid, err = core.GetQueryParam(result.NextURL, "next_docid") + if err != nil { + err = fmt.Errorf("error retrieving 'next_docid' query parameter from URL '%s': %s", *result.NextURL, err.Error()) + return + } + next = next_docid + } + pager.pageContext.next = next + pager.hasNext = (pager.pageContext.next != nil) + page = result.Resources + + return +} + +// GetAllWithContext returns all results by invoking GetNextWithContext() repeatedly +// until all pages of results have been retrieved. +func (pager *AccountsPager) GetAllWithContext(ctx context.Context) (allItems []Account, err error) { + for pager.HasNext() { + var nextPage []Account + nextPage, err = pager.GetNextWithContext(ctx) + if err != nil { + return + } + allItems = append(allItems, nextPage...) + } + return +} + +// GetNext invokes GetNextWithContext() using context.Background() as the Context parameter. +func (pager *AccountsPager) GetNext() (page []Account, err error) { + return pager.GetNextWithContext(context.Background()) +} + +// GetAll invokes GetAllWithContext() using context.Background() as the Context parameter. +func (pager *AccountsPager) GetAll() (allItems []Account, err error) { + return pager.GetAllWithContext(context.Background()) +} + +// +// AccountGroupsPager can be used to simplify the use of the "ListAccountGroups" method. +// +type AccountGroupsPager struct { + hasNext bool + options *ListAccountGroupsOptions + client *EnterpriseManagementV1 + pageContext struct { + next *string + } +} + +// NewAccountGroupsPager returns a new AccountGroupsPager instance. +func (enterpriseManagement *EnterpriseManagementV1) NewAccountGroupsPager(options *ListAccountGroupsOptions) (pager *AccountGroupsPager, err error) { + if options.NextDocid != nil && *options.NextDocid != "" { + err = fmt.Errorf("the 'options.NextDocid' field should not be set") + return + } + + var optionsCopy ListAccountGroupsOptions = *options + pager = &AccountGroupsPager{ + hasNext: true, + options: &optionsCopy, + client: enterpriseManagement, + } + return +} + +// HasNext returns true if there are potentially more results to be retrieved. +func (pager *AccountGroupsPager) HasNext() bool { + return pager.hasNext +} + +// GetNextWithContext returns the next page of results using the specified Context. +func (pager *AccountGroupsPager) GetNextWithContext(ctx context.Context) (page []AccountGroup, err error) { + if !pager.HasNext() { + return nil, fmt.Errorf("no more results available") + } + + pager.options.NextDocid = pager.pageContext.next + + result, _, err := pager.client.ListAccountGroupsWithContext(ctx, pager.options) + if err != nil { + return + } + + var next *string + if result.NextURL != nil { + var next_docid *string + next_docid, err = core.GetQueryParam(result.NextURL, "next_docid") + if err != nil { + err = fmt.Errorf("error retrieving 'next_docid' query parameter from URL '%s': %s", *result.NextURL, err.Error()) + return + } + next = next_docid + } + pager.pageContext.next = next + pager.hasNext = (pager.pageContext.next != nil) + page = result.Resources + + return +} + +// GetAllWithContext returns all results by invoking GetNextWithContext() repeatedly +// until all pages of results have been retrieved. +func (pager *AccountGroupsPager) GetAllWithContext(ctx context.Context) (allItems []AccountGroup, err error) { + for pager.HasNext() { + var nextPage []AccountGroup + nextPage, err = pager.GetNextWithContext(ctx) + if err != nil { + return + } + allItems = append(allItems, nextPage...) + } + return +} + +// GetNext invokes GetNextWithContext() using context.Background() as the Context parameter. +func (pager *AccountGroupsPager) GetNext() (page []AccountGroup, err error) { + return pager.GetNextWithContext(context.Background()) +} + +// GetAll invokes GetAllWithContext() using context.Background() as the Context parameter. +func (pager *AccountGroupsPager) GetAll() (allItems []AccountGroup, err error) { + return pager.GetAllWithContext(context.Background()) +} diff --git a/enterprisemanagementv1/enterprise_management_v1_examples_test.go b/enterprisemanagementv1/enterprise_management_v1_examples_test.go index 5f2735f1..46fce269 100644 --- a/enterprisemanagementv1/enterprise_management_v1_examples_test.go +++ b/enterprisemanagementv1/enterprise_management_v1_examples_test.go @@ -2,7 +2,7 @@ // +build examples /** - * (C) Copyright IBM Corp. 2021. + * (C) Copyright IBM Corp. 2021, 2022. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -174,22 +174,26 @@ var _ = Describe(`EnterpriseManagementV1 Examples Tests`, func() { It(`ListAccountGroups request example`, func() { fmt.Println("\nListAccountGroups() result:") // begin-list_account_groups + listAccountGroupsOptions := &enterprisemanagementv1.ListAccountGroupsOptions{ + EnterpriseID: &enterpriseID, + } - listAccountGroupsOptions := enterpriseManagementService.NewListAccountGroupsOptions() - listAccountGroupsOptions.SetEnterpriseID(enterpriseID) - - listAccountGroupsResponse, response, err := enterpriseManagementService.ListAccountGroups(listAccountGroupsOptions) + pager, err := enterpriseManagementService.NewAccountGroupsPager(listAccountGroupsOptions) if err != nil { panic(err) } - b, _ := json.MarshalIndent(listAccountGroupsResponse, "", " ") - fmt.Println(string(b)) + var allResults []enterprisemanagementv1.AccountGroup + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + b, _ := json.MarshalIndent(allResults, "", " ") + fmt.Println(string(b)) // end-list_account_groups - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(listAccountGroupsResponse).ToNot(BeNil()) }) It(`GetAccountGroup request example`, func() { fmt.Println("\nGetAccountGroup() result:") @@ -282,22 +286,26 @@ var _ = Describe(`EnterpriseManagementV1 Examples Tests`, func() { It(`ListAccounts request example`, func() { fmt.Println("\nListAccounts() result:") // begin-list_accounts + listAccountsOptions := &enterprisemanagementv1.ListAccountsOptions{ + EnterpriseID: &enterpriseID, + } - listAccountsOptions := enterpriseManagementService.NewListAccountsOptions() - listAccountsOptions.SetEnterpriseID(enterpriseID) - - listAccountsResponse, response, err := enterpriseManagementService.ListAccounts(listAccountsOptions) + pager, err := enterpriseManagementService.NewAccountsPager(listAccountsOptions) if err != nil { panic(err) } - b, _ := json.MarshalIndent(listAccountsResponse, "", " ") - fmt.Println(string(b)) + var allResults []enterprisemanagementv1.Account + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + b, _ := json.MarshalIndent(allResults, "", " ") + fmt.Println(string(b)) // end-list_accounts - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(listAccountsResponse).ToNot(BeNil()) }) It(`GetAccount request example`, func() { fmt.Println("\nGetAccount() result:") @@ -372,22 +380,26 @@ var _ = Describe(`EnterpriseManagementV1 Examples Tests`, func() { It(`ListEnterprises request example`, func() { fmt.Println("\nListEnterprises() result:") // begin-list_enterprises + listEnterprisesOptions := &enterprisemanagementv1.ListEnterprisesOptions{ + EnterpriseAccountID: &enterpriseAccountID, + } - listEnterprisesOptions := enterpriseManagementService.NewListEnterprisesOptions() - listEnterprisesOptions.SetAccountID(enterpriseAccountID) - - listEnterprisesResponse, response, err := enterpriseManagementService.ListEnterprises(listEnterprisesOptions) + pager, err := enterpriseManagementService.NewEnterprisesPager(listEnterprisesOptions) if err != nil { panic(err) } - b, _ := json.MarshalIndent(listEnterprisesResponse, "", " ") - fmt.Println(string(b)) + var allResults []enterprisemanagementv1.Enterprise + for pager.HasNext() { + nextPage, err := pager.GetNext() + if err != nil { + panic(err) + } + allResults = append(allResults, nextPage...) + } + b, _ := json.MarshalIndent(allResults, "", " ") + fmt.Println(string(b)) // end-list_enterprises - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(listEnterprisesResponse).ToNot(BeNil()) }) It(`GetEnterprise request example`, func() { fmt.Println("\nGetEnterprise() result:") diff --git a/enterprisemanagementv1/enterprise_management_v1_integration_test.go b/enterprisemanagementv1/enterprise_management_v1_integration_test.go index c0aab8b9..50c57c7c 100644 --- a/enterprisemanagementv1/enterprise_management_v1_integration_test.go +++ b/enterprisemanagementv1/enterprise_management_v1_integration_test.go @@ -1,7 +1,8 @@ +//go:build integration // +build integration /** - * (C) Copyright IBM Corp. 2021. + * (C) Copyright IBM Corp. 2021, 2022. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -211,6 +212,36 @@ var _ = Describe(`EnterpriseManagementV1 Integration Tests`, func() { fmt.Printf("Received a total of %d account groups.", len(accountGroupList)) }) + It(`ListAccountGroups(listAccountGroupsOptions *ListAccountGroupsOptions) using AccountGroupsPager`, func() { + listAccountGroupsOptions := &enterprisemanagementv1.ListAccountGroupsOptions{ + EnterpriseID: &enterpriseID, + } + + // Test GetNext(). + pager, err := enterpriseManagementService.NewAccountGroupsPager(listAccountGroupsOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []enterprisemanagementv1.AccountGroup + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + + // Test GetAll(). + pager, err = enterpriseManagementService.NewAccountGroupsPager(listAccountGroupsOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allItems, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allItems).ToNot(BeNil()) + + Expect(len(allItems)).To(Equal(len(allResults))) + fmt.Fprintf(GinkgoWriter, "ListAccountGroups() returned a total of %d item(s) using AccountGroupsPager.\n", len(allResults)) + }) }) Describe(`GetAccountGroup - Get account group by ID`, func() { @@ -320,6 +351,36 @@ var _ = Describe(`EnterpriseManagementV1 Integration Tests`, func() { fmt.Printf("Received a total of %d accounts.", len(accountsList)) }) + It(`ListAccounts(listAccountsOptions *ListAccountsOptions) using AccountsPager`, func() { + listAccountsOptions := &enterprisemanagementv1.ListAccountsOptions{ + AccountGroupID: &accountGroupID, + } + + // Test GetNext(). + pager, err := enterpriseManagementService.NewAccountsPager(listAccountsOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []enterprisemanagementv1.Account + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + + // Test GetAll(). + pager, err = enterpriseManagementService.NewAccountsPager(listAccountsOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allItems, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allItems).ToNot(BeNil()) + + Expect(len(allItems)).To(Equal(len(allResults))) + fmt.Fprintf(GinkgoWriter, "ListAccounts() returned a total of %d item(s) using AccountsPager.\n", len(allResults)) + }) }) Describe(`GetAccount - Get account by ID`, func() { @@ -405,6 +466,36 @@ var _ = Describe(`EnterpriseManagementV1 Integration Tests`, func() { Expect(found).To(BeTrue()) fmt.Printf("Received a total of %d enterprises.", len(enterpriseList)) }) + It(`ListEnterprises(listEnterprisesOptions *ListEnterprisesOptions) using EnterprisesPager`, func() { + listEnterprisesOptions := &enterprisemanagementv1.ListEnterprisesOptions{ + AccountID: &accountID, + } + + // Test GetNext(). + pager, err := enterpriseManagementService.NewEnterprisesPager(listEnterprisesOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []enterprisemanagementv1.Enterprise + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + + // Test GetAll(). + pager, err = enterpriseManagementService.NewEnterprisesPager(listEnterprisesOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allItems, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allItems).ToNot(BeNil()) + + Expect(len(allItems)).To(Equal(len(allResults))) + fmt.Fprintf(GinkgoWriter, "ListEnterprises() returned a total of %d item(s) using EnterprisesPager.\n", len(allResults)) + }) }) Describe(`GetEnterprise - Get enterprise by ID`, func() { diff --git a/enterprisemanagementv1/enterprise_management_v1_test.go b/enterprisemanagementv1/enterprise_management_v1_test.go index 369e2a80..05c86da5 100644 --- a/enterprisemanagementv1/enterprise_management_v1_test.go +++ b/enterprisemanagementv1/enterprise_management_v1_test.go @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corp. 2021. + * (C) Copyright IBM Corp. 2022. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,13 +66,14 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Context(`Using external config, construct service client instances`, func() { // Map containing environment variables used in testing. var testEnvironment = map[string]string{ - "ENTERPRISE_MANAGEMENT_URL": "https://enterprisemanagementv1/api", + "ENTERPRISE_MANAGEMENT_URL": "https://enterprisemanagementv1/api", "ENTERPRISE_MANAGEMENT_AUTH_TYPE": "noauth", } It(`Create service client using external config successfully`, func() { SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{}) + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{ + }) Expect(enterpriseManagementService).ToNot(BeNil()) Expect(serviceErr).To(BeNil()) ClearTestEnvironment(testEnvironment) @@ -101,7 +102,8 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) It(`Create service client using external config and set url programatically successfully`, func() { SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{}) + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{ + }) err := enterpriseManagementService.SetServiceURL("https://testService/api") Expect(err).To(BeNil()) Expect(enterpriseManagementService).ToNot(BeNil()) @@ -119,12 +121,13 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { // Map containing environment variables used in testing. var testEnvironment = map[string]string{ - "ENTERPRISE_MANAGEMENT_URL": "https://enterprisemanagementv1/api", + "ENTERPRISE_MANAGEMENT_URL": "https://enterprisemanagementv1/api", "ENTERPRISE_MANAGEMENT_AUTH_TYPE": "someOtherAuth", } SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{}) + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{ + }) It(`Instantiate service client with error`, func() { Expect(enterpriseManagementService).To(BeNil()) @@ -135,7 +138,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Context(`Using external config, construct service client instances with error: Invalid URL`, func() { // Map containing environment variables used in testing. var testEnvironment = map[string]string{ - "ENTERPRISE_MANAGEMENT_AUTH_TYPE": "NOAuth", + "ENTERPRISE_MANAGEMENT_AUTH_TYPE": "NOAuth", } SetTestEnvironment(testEnvironment) @@ -162,7 +165,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) Describe(`CreateEnterprise(createEnterpriseOptions *CreateEnterpriseOptions) - Operation response error`, func() { createEnterprisePath := "/enterprises" - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with invalid JSON response`, func() { BeforeEach(func() { testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -172,7 +175,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.Method).To(Equal("POST")) res.Header().Set("Content-type", "application/json") res.WriteHeader(202) - fmt.Fprintf(res, `} this is not valid json {`) + fmt.Fprint(res, `} this is not valid json {`) })) }) It(`Invoke CreateEnterprise with error: Operation response processing error`, func() { @@ -208,7 +211,6 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) - Describe(`CreateEnterprise(createEnterpriseOptions *CreateEnterpriseOptions)`, func() { createEnterprisePath := "/enterprises" Context(`Using mock server endpoint with timeout`, func() { @@ -382,10 +384,47 @@ var _ = Describe(`EnterpriseManagementV1`, func() { testServer.Close() }) }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(202) + })) + }) + It(`Invoke CreateEnterprise successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + // Construct an instance of the CreateEnterpriseOptions model + createEnterpriseOptionsModel := new(enterprisemanagementv1.CreateEnterpriseOptions) + createEnterpriseOptionsModel.SourceAccountID = core.StringPtr("testString") + createEnterpriseOptionsModel.Name = core.StringPtr("testString") + createEnterpriseOptionsModel.PrimaryContactIamID = core.StringPtr("testString") + createEnterpriseOptionsModel.Domain = core.StringPtr("testString") + createEnterpriseOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := enterpriseManagementService.CreateEnterprise(createEnterpriseOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) }) Describe(`ListEnterprises(listEnterprisesOptions *ListEnterprisesOptions) - Operation response error`, func() { listEnterprisesPath := "/enterprises" - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with invalid JSON response`, func() { BeforeEach(func() { testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -397,10 +436,10 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.URL.Query()["account_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["next_docid"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) + fmt.Fprint(res, `} this is not valid json {`) })) }) It(`Invoke ListEnterprises with error: Operation response processing error`, func() { @@ -417,7 +456,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listEnterprisesOptionsModel.AccountGroupID = core.StringPtr("testString") listEnterprisesOptionsModel.AccountID = core.StringPtr("testString") listEnterprisesOptionsModel.NextDocid = core.StringPtr("testString") - listEnterprisesOptionsModel.Limit = core.Int64Ptr(int64(100)) + listEnterprisesOptionsModel.Limit = core.Int64Ptr(int64(10)) listEnterprisesOptionsModel.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 := enterpriseManagementService.ListEnterprises(listEnterprisesOptionsModel) @@ -437,7 +476,6 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) - Describe(`ListEnterprises(listEnterprisesOptions *ListEnterprisesOptions)`, func() { listEnterprisesPath := "/enterprises" Context(`Using mock server endpoint with timeout`, func() { @@ -453,7 +491,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.URL.Query()["account_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["next_docid"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) // Sleep a short time to support a timeout test time.Sleep(100 * time.Millisecond) @@ -478,7 +516,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listEnterprisesOptionsModel.AccountGroupID = core.StringPtr("testString") listEnterprisesOptionsModel.AccountID = core.StringPtr("testString") listEnterprisesOptionsModel.NextDocid = core.StringPtr("testString") - listEnterprisesOptionsModel.Limit = core.Int64Ptr(int64(100)) + listEnterprisesOptionsModel.Limit = core.Int64Ptr(int64(10)) listEnterprisesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with a Context to test a timeout error @@ -519,7 +557,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.URL.Query()["account_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["next_docid"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) @@ -546,7 +584,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listEnterprisesOptionsModel.AccountGroupID = core.StringPtr("testString") listEnterprisesOptionsModel.AccountID = core.StringPtr("testString") listEnterprisesOptionsModel.NextDocid = core.StringPtr("testString") - listEnterprisesOptionsModel.Limit = core.Int64Ptr(int64(100)) + listEnterprisesOptionsModel.Limit = core.Int64Ptr(int64(10)) listEnterprisesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with valid options model (positive test) @@ -570,7 +608,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listEnterprisesOptionsModel.AccountGroupID = core.StringPtr("testString") listEnterprisesOptionsModel.AccountID = core.StringPtr("testString") listEnterprisesOptionsModel.NextDocid = core.StringPtr("testString") - listEnterprisesOptionsModel.Limit = core.Int64Ptr(int64(100)) + listEnterprisesOptionsModel.Limit = core.Int64Ptr(int64(10)) listEnterprisesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := enterpriseManagementService.SetServiceURL("") @@ -585,10 +623,149 @@ var _ = Describe(`EnterpriseManagementV1`, func() { testServer.Close() }) }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ListEnterprises successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + // Construct an instance of the ListEnterprisesOptions model + listEnterprisesOptionsModel := new(enterprisemanagementv1.ListEnterprisesOptions) + listEnterprisesOptionsModel.EnterpriseAccountID = core.StringPtr("testString") + listEnterprisesOptionsModel.AccountGroupID = core.StringPtr("testString") + listEnterprisesOptionsModel.AccountID = core.StringPtr("testString") + listEnterprisesOptionsModel.NextDocid = core.StringPtr("testString") + listEnterprisesOptionsModel.Limit = core.Int64Ptr(int64(10)) + listEnterprisesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := enterpriseManagementService.ListEnterprises(listEnterprisesOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Test pagination helper method on response`, func() { + It(`Invoke GetNextNextDocid successfully`, func() { + responseObject := new(enterprisemanagementv1.ListEnterprisesResponse) + responseObject.NextURL = core.StringPtr("ibm.com?next_docid=abc-123") + + value, err := responseObject.GetNextNextDocid() + Expect(err).To(BeNil()) + Expect(value).To(Equal(core.StringPtr("abc-123"))) + }) + It(`Invoke GetNextNextDocid without a "NextURL" property in the response`, func() { + responseObject := new(enterprisemanagementv1.ListEnterprisesResponse) + + value, err := responseObject.GetNextNextDocid() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + It(`Invoke GetNextNextDocid without any query params in the "NextURL" URL`, func() { + responseObject := new(enterprisemanagementv1.ListEnterprisesResponse) + responseObject.NextURL = core.StringPtr("ibm.com") + + value, err := responseObject.GetNextNextDocid() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + }) + Context(`Using mock server endpoint - paginated response`, func() { + BeforeEach(func() { + var requestNumber int = 0 + 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(listEnterprisesPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + requestNumber++ + if requestNumber == 1 { + fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"next_url":"https://myhost.com/somePath?next_docid=1","resources":[{"url":"URL","id":"ID","enterprise_account_id":"EnterpriseAccountID","crn":"CRN","name":"Name","domain":"Domain","state":"State","primary_contact_iam_id":"PrimaryContactIamID","primary_contact_email":"PrimaryContactEmail","created_at":"2019-01-01T12:00:00.000Z","created_by":"CreatedBy","updated_at":"2019-01-01T12:00:00.000Z","updated_by":"UpdatedBy"}]}`) + } else if requestNumber == 2 { + fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"resources":[{"url":"URL","id":"ID","enterprise_account_id":"EnterpriseAccountID","crn":"CRN","name":"Name","domain":"Domain","state":"State","primary_contact_iam_id":"PrimaryContactIamID","primary_contact_email":"PrimaryContactEmail","created_at":"2019-01-01T12:00:00.000Z","created_by":"CreatedBy","updated_at":"2019-01-01T12:00:00.000Z","updated_by":"UpdatedBy"}]}`) + } else { + res.WriteHeader(400) + } + })) + }) + It(`Use EnterprisesPager.GetNext successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + listEnterprisesOptionsModel := &enterprisemanagementv1.ListEnterprisesOptions{ + EnterpriseAccountID: core.StringPtr("testString"), + AccountGroupID: core.StringPtr("testString"), + AccountID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(10)), + } + + pager, err := enterpriseManagementService.NewEnterprisesPager(listEnterprisesOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []enterprisemanagementv1.Enterprise + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + Expect(len(allResults)).To(Equal(2)) + }) + It(`Use EnterprisesPager.GetAll successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + listEnterprisesOptionsModel := &enterprisemanagementv1.ListEnterprisesOptions{ + EnterpriseAccountID: core.StringPtr("testString"), + AccountGroupID: core.StringPtr("testString"), + AccountID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(10)), + } + + pager, err := enterpriseManagementService.NewEnterprisesPager(listEnterprisesOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allResults, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allResults).ToNot(BeNil()) + Expect(len(allResults)).To(Equal(2)) + }) + }) }) Describe(`GetEnterprise(getEnterpriseOptions *GetEnterpriseOptions) - Operation response error`, func() { getEnterprisePath := "/enterprises/testString" - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with invalid JSON response`, func() { BeforeEach(func() { testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -598,7 +775,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.Method).To(Equal("GET")) res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) + fmt.Fprint(res, `} this is not valid json {`) })) }) It(`Invoke GetEnterprise with error: Operation response processing error`, func() { @@ -631,7 +808,6 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) - Describe(`GetEnterprise(getEnterpriseOptions *GetEnterpriseOptions)`, func() { getEnterprisePath := "/enterprises/testString" Context(`Using mock server endpoint with timeout`, func() { @@ -764,8 +940,41 @@ var _ = Describe(`EnterpriseManagementV1`, func() { testServer.Close() }) }) - }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetEnterprise successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + // Construct an instance of the GetEnterpriseOptions model + getEnterpriseOptionsModel := new(enterprisemanagementv1.GetEnterpriseOptions) + getEnterpriseOptionsModel.EnterpriseID = core.StringPtr("testString") + getEnterpriseOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := enterpriseManagementService.GetEnterprise(getEnterpriseOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) Describe(`UpdateEnterprise(updateEnterpriseOptions *UpdateEnterpriseOptions)`, func() { updateEnterprisePath := "/enterprises/testString" Context(`Using mock server endpoint`, func() { @@ -856,166 +1065,40 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) - Describe(`Service constructor tests`, func() { - It(`Instantiate service client`, func() { - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(enterpriseManagementService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - }) - It(`Instantiate service client with error: Invalid URL`, func() { - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ - URL: "{BAD_URL_STRING", - }) - Expect(enterpriseManagementService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - }) - It(`Instantiate service client with error: Invalid Auth`, func() { - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ - URL: "https://enterprisemanagementv1/api", - Authenticator: &core.BasicAuthenticator{ - Username: "", - Password: "", - }, - }) - Expect(enterpriseManagementService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - }) - }) - Describe(`Service constructor tests using external config`, func() { - Context(`Using external config, construct service client instances`, func() { - // Map containing environment variables used in testing. - var testEnvironment = map[string]string{ - "ENTERPRISE_MANAGEMENT_URL": "https://enterprisemanagementv1/api", - "ENTERPRISE_MANAGEMENT_AUTH_TYPE": "noauth", - } + Describe(`ImportAccountToEnterprise(importAccountToEnterpriseOptions *ImportAccountToEnterpriseOptions)`, func() { + importAccountToEnterprisePath := "/enterprises/testString/import/accounts/testString" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() - It(`Create service client using external config successfully`, func() { - SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{}) - Expect(enterpriseManagementService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - ClearTestEnvironment(testEnvironment) + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(importAccountToEnterprisePath)) + Expect(req.Method).To(Equal("PUT")) - clone := enterpriseManagementService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) + // 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()) + + res.WriteHeader(202) + })) }) - It(`Create service client using external config and set url from constructor successfully`, func() { - SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{ - URL: "https://testService/api", - }) - Expect(enterpriseManagementService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - Expect(enterpriseManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) - ClearTestEnvironment(testEnvironment) - - clone := enterpriseManagementService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) - }) - It(`Create service client using external config and set url programatically successfully`, func() { - SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{}) - err := enterpriseManagementService.SetServiceURL("https://testService/api") - Expect(err).To(BeNil()) - Expect(enterpriseManagementService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - Expect(enterpriseManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) - ClearTestEnvironment(testEnvironment) - - clone := enterpriseManagementService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) - }) - }) - Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { - // Map containing environment variables used in testing. - var testEnvironment = map[string]string{ - "ENTERPRISE_MANAGEMENT_URL": "https://enterprisemanagementv1/api", - "ENTERPRISE_MANAGEMENT_AUTH_TYPE": "someOtherAuth", - } - - SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{}) - - It(`Instantiate service client with error`, func() { - Expect(enterpriseManagementService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - ClearTestEnvironment(testEnvironment) - }) - }) - Context(`Using external config, construct service client instances with error: Invalid URL`, func() { - // Map containing environment variables used in testing. - var testEnvironment = map[string]string{ - "ENTERPRISE_MANAGEMENT_AUTH_TYPE": "NOAuth", - } - - SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{ - URL: "{BAD_URL_STRING", - }) - - It(`Instantiate service client with error`, func() { - Expect(enterpriseManagementService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - ClearTestEnvironment(testEnvironment) - }) - }) - }) - Describe(`Regional endpoint tests`, func() { - It(`GetServiceURLForRegion(region string)`, func() { - var url string - var err error - url, err = enterprisemanagementv1.GetServiceURLForRegion("INVALID_REGION") - Expect(url).To(BeEmpty()) - Expect(err).ToNot(BeNil()) - fmt.Fprintf(GinkgoWriter, "Expected error: %s\n", err.Error()) - }) - }) - - Describe(`ImportAccountToEnterprise(importAccountToEnterpriseOptions *ImportAccountToEnterpriseOptions)`, func() { - importAccountToEnterprisePath := "/enterprises/testString/import/accounts/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(importAccountToEnterprisePath)) - Expect(req.Method).To(Equal("PUT")) - - // 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()) - - res.WriteHeader(202) - })) - }) - It(`Invoke ImportAccountToEnterprise successfully`, func() { - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, + It(`Invoke ImportAccountToEnterprise successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, }) Expect(serviceErr).To(BeNil()) Expect(enterpriseManagementService).ToNot(BeNil()) @@ -1074,7 +1157,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) Describe(`CreateAccount(createAccountOptions *CreateAccountOptions) - Operation response error`, func() { createAccountPath := "/accounts" - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with invalid JSON response`, func() { BeforeEach(func() { testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -1084,7 +1167,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.Method).To(Equal("POST")) res.Header().Set("Content-type", "application/json") res.WriteHeader(201) - fmt.Fprintf(res, `} this is not valid json {`) + fmt.Fprint(res, `} this is not valid json {`) })) }) It(`Invoke CreateAccount with error: Operation response processing error`, func() { @@ -1119,7 +1202,6 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) - Describe(`CreateAccount(createAccountOptions *CreateAccountOptions)`, func() { createAccountPath := "/accounts" Context(`Using mock server endpoint with timeout`, func() { @@ -1290,10 +1372,46 @@ var _ = Describe(`EnterpriseManagementV1`, func() { testServer.Close() }) }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(201) + })) + }) + It(`Invoke CreateAccount successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + // Construct an instance of the CreateAccountOptions model + createAccountOptionsModel := new(enterprisemanagementv1.CreateAccountOptions) + createAccountOptionsModel.Parent = core.StringPtr("testString") + createAccountOptionsModel.Name = core.StringPtr("testString") + createAccountOptionsModel.OwnerIamID = core.StringPtr("testString") + createAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := enterpriseManagementService.CreateAccount(createAccountOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) }) Describe(`ListAccounts(listAccountsOptions *ListAccountsOptions) - Operation response error`, func() { listAccountsPath := "/accounts" - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with invalid JSON response`, func() { BeforeEach(func() { testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -1305,10 +1423,10 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.URL.Query()["account_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["next_docid"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["parent"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) + fmt.Fprint(res, `} this is not valid json {`) })) }) It(`Invoke ListAccounts with error: Operation response processing error`, func() { @@ -1325,7 +1443,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listAccountsOptionsModel.AccountGroupID = core.StringPtr("testString") listAccountsOptionsModel.NextDocid = core.StringPtr("testString") listAccountsOptionsModel.Parent = core.StringPtr("testString") - listAccountsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listAccountsOptionsModel.Limit = core.Int64Ptr(int64(10)) listAccountsOptionsModel.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 := enterpriseManagementService.ListAccounts(listAccountsOptionsModel) @@ -1345,7 +1463,6 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) - Describe(`ListAccounts(listAccountsOptions *ListAccountsOptions)`, func() { listAccountsPath := "/accounts" Context(`Using mock server endpoint with timeout`, func() { @@ -1361,7 +1478,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.URL.Query()["account_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["next_docid"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["parent"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) // Sleep a short time to support a timeout test time.Sleep(100 * time.Millisecond) @@ -1386,7 +1503,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listAccountsOptionsModel.AccountGroupID = core.StringPtr("testString") listAccountsOptionsModel.NextDocid = core.StringPtr("testString") listAccountsOptionsModel.Parent = core.StringPtr("testString") - listAccountsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listAccountsOptionsModel.Limit = core.Int64Ptr(int64(10)) listAccountsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with a Context to test a timeout error @@ -1427,7 +1544,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.URL.Query()["account_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["next_docid"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["parent"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) @@ -1454,7 +1571,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listAccountsOptionsModel.AccountGroupID = core.StringPtr("testString") listAccountsOptionsModel.NextDocid = core.StringPtr("testString") listAccountsOptionsModel.Parent = core.StringPtr("testString") - listAccountsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listAccountsOptionsModel.Limit = core.Int64Ptr(int64(10)) listAccountsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with valid options model (positive test) @@ -1478,7 +1595,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listAccountsOptionsModel.AccountGroupID = core.StringPtr("testString") listAccountsOptionsModel.NextDocid = core.StringPtr("testString") listAccountsOptionsModel.Parent = core.StringPtr("testString") - listAccountsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listAccountsOptionsModel.Limit = core.Int64Ptr(int64(10)) listAccountsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := enterpriseManagementService.SetServiceURL("") @@ -1493,10 +1610,149 @@ var _ = Describe(`EnterpriseManagementV1`, func() { testServer.Close() }) }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ListAccounts successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + // Construct an instance of the ListAccountsOptions model + listAccountsOptionsModel := new(enterprisemanagementv1.ListAccountsOptions) + listAccountsOptionsModel.EnterpriseID = core.StringPtr("testString") + listAccountsOptionsModel.AccountGroupID = core.StringPtr("testString") + listAccountsOptionsModel.NextDocid = core.StringPtr("testString") + listAccountsOptionsModel.Parent = core.StringPtr("testString") + listAccountsOptionsModel.Limit = core.Int64Ptr(int64(10)) + listAccountsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := enterpriseManagementService.ListAccounts(listAccountsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Test pagination helper method on response`, func() { + It(`Invoke GetNextNextDocid successfully`, func() { + responseObject := new(enterprisemanagementv1.ListAccountsResponse) + responseObject.NextURL = core.StringPtr("ibm.com?next_docid=abc-123") + + value, err := responseObject.GetNextNextDocid() + Expect(err).To(BeNil()) + Expect(value).To(Equal(core.StringPtr("abc-123"))) + }) + It(`Invoke GetNextNextDocid without a "NextURL" property in the response`, func() { + responseObject := new(enterprisemanagementv1.ListAccountsResponse) + + value, err := responseObject.GetNextNextDocid() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + It(`Invoke GetNextNextDocid without any query params in the "NextURL" URL`, func() { + responseObject := new(enterprisemanagementv1.ListAccountsResponse) + responseObject.NextURL = core.StringPtr("ibm.com") + + value, err := responseObject.GetNextNextDocid() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + }) + Context(`Using mock server endpoint - paginated response`, func() { + BeforeEach(func() { + var requestNumber int = 0 + 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(listAccountsPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + requestNumber++ + if requestNumber == 1 { + fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"next_url":"https://myhost.com/somePath?next_docid=1","resources":[{"url":"URL","id":"ID","crn":"CRN","parent":"Parent","enterprise_account_id":"EnterpriseAccountID","enterprise_id":"EnterpriseID","enterprise_path":"EnterprisePath","name":"Name","state":"State","owner_iam_id":"OwnerIamID","paid":true,"owner_email":"OwnerEmail","is_enterprise_account":false,"created_at":"2019-01-01T12:00:00.000Z","created_by":"CreatedBy","updated_at":"2019-01-01T12:00:00.000Z","updated_by":"UpdatedBy"}]}`) + } else if requestNumber == 2 { + fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"resources":[{"url":"URL","id":"ID","crn":"CRN","parent":"Parent","enterprise_account_id":"EnterpriseAccountID","enterprise_id":"EnterpriseID","enterprise_path":"EnterprisePath","name":"Name","state":"State","owner_iam_id":"OwnerIamID","paid":true,"owner_email":"OwnerEmail","is_enterprise_account":false,"created_at":"2019-01-01T12:00:00.000Z","created_by":"CreatedBy","updated_at":"2019-01-01T12:00:00.000Z","updated_by":"UpdatedBy"}]}`) + } else { + res.WriteHeader(400) + } + })) + }) + It(`Use AccountsPager.GetNext successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + listAccountsOptionsModel := &enterprisemanagementv1.ListAccountsOptions{ + EnterpriseID: core.StringPtr("testString"), + AccountGroupID: core.StringPtr("testString"), + Parent: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(10)), + } + + pager, err := enterpriseManagementService.NewAccountsPager(listAccountsOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []enterprisemanagementv1.Account + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + Expect(len(allResults)).To(Equal(2)) + }) + It(`Use AccountsPager.GetAll successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + listAccountsOptionsModel := &enterprisemanagementv1.ListAccountsOptions{ + EnterpriseID: core.StringPtr("testString"), + AccountGroupID: core.StringPtr("testString"), + Parent: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(10)), + } + + pager, err := enterpriseManagementService.NewAccountsPager(listAccountsOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allResults, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allResults).ToNot(BeNil()) + Expect(len(allResults)).To(Equal(2)) + }) + }) }) Describe(`GetAccount(getAccountOptions *GetAccountOptions) - Operation response error`, func() { getAccountPath := "/accounts/testString" - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with invalid JSON response`, func() { BeforeEach(func() { testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -1506,7 +1762,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.Method).To(Equal("GET")) res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) + fmt.Fprint(res, `} this is not valid json {`) })) }) It(`Invoke GetAccount with error: Operation response processing error`, func() { @@ -1539,7 +1795,6 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) - Describe(`GetAccount(getAccountOptions *GetAccountOptions)`, func() { getAccountPath := "/accounts/testString" Context(`Using mock server endpoint with timeout`, func() { @@ -1672,8 +1927,41 @@ var _ = Describe(`EnterpriseManagementV1`, func() { testServer.Close() }) }) - }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetAccount successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + // Construct an instance of the GetAccountOptions model + getAccountOptionsModel := new(enterprisemanagementv1.GetAccountOptions) + getAccountOptionsModel.AccountID = core.StringPtr("testString") + getAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := enterpriseManagementService.GetAccount(getAccountOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) Describe(`UpdateAccount(updateAccountOptions *UpdateAccountOptions)`, func() { updateAccountPath := "/accounts/testString" Context(`Using mock server endpoint`, func() { @@ -1700,194 +1988,69 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(err).To(BeNil()) } fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) - - res.WriteHeader(202) - })) - }) - It(`Invoke UpdateAccount successfully`, func() { - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(enterpriseManagementService).ToNot(BeNil()) - - // Invoke operation with nil options model (negative test) - response, operationErr := enterpriseManagementService.UpdateAccount(nil) - Expect(operationErr).NotTo(BeNil()) - Expect(response).To(BeNil()) - - // Construct an instance of the UpdateAccountOptions model - updateAccountOptionsModel := new(enterprisemanagementv1.UpdateAccountOptions) - updateAccountOptionsModel.AccountID = core.StringPtr("testString") - updateAccountOptionsModel.Parent = core.StringPtr("testString") - updateAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - - // Invoke operation with valid options model (positive test) - response, operationErr = enterpriseManagementService.UpdateAccount(updateAccountOptionsModel) - Expect(operationErr).To(BeNil()) - Expect(response).ToNot(BeNil()) - }) - It(`Invoke UpdateAccount with error: Operation validation and request error`, func() { - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ - URL: testServer.URL, - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(serviceErr).To(BeNil()) - Expect(enterpriseManagementService).ToNot(BeNil()) - - // Construct an instance of the UpdateAccountOptions model - updateAccountOptionsModel := new(enterprisemanagementv1.UpdateAccountOptions) - updateAccountOptionsModel.AccountID = core.StringPtr("testString") - updateAccountOptionsModel.Parent = core.StringPtr("testString") - updateAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - // Invoke operation with empty URL (negative test) - err := enterpriseManagementService.SetServiceURL("") - Expect(err).To(BeNil()) - response, operationErr := enterpriseManagementService.UpdateAccount(updateAccountOptionsModel) - Expect(operationErr).ToNot(BeNil()) - Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) - Expect(response).To(BeNil()) - // Construct a second instance of the UpdateAccountOptions model with no property values - updateAccountOptionsModelNew := new(enterprisemanagementv1.UpdateAccountOptions) - // Invoke operation with invalid model (negative test) - response, operationErr = enterpriseManagementService.UpdateAccount(updateAccountOptionsModelNew) - Expect(operationErr).ToNot(BeNil()) - Expect(response).To(BeNil()) - }) - AfterEach(func() { - testServer.Close() - }) - }) - }) - Describe(`Service constructor tests`, func() { - It(`Instantiate service client`, func() { - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(enterpriseManagementService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - }) - It(`Instantiate service client with error: Invalid URL`, func() { - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ - URL: "{BAD_URL_STRING", - }) - Expect(enterpriseManagementService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - }) - It(`Instantiate service client with error: Invalid Auth`, func() { - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ - URL: "https://enterprisemanagementv1/api", - Authenticator: &core.BasicAuthenticator{ - Username: "", - Password: "", - }, - }) - Expect(enterpriseManagementService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - }) - }) - Describe(`Service constructor tests using external config`, func() { - Context(`Using external config, construct service client instances`, func() { - // Map containing environment variables used in testing. - var testEnvironment = map[string]string{ - "ENTERPRISE_MANAGEMENT_URL": "https://enterprisemanagementv1/api", - "ENTERPRISE_MANAGEMENT_AUTH_TYPE": "noauth", - } - - It(`Create service client using external config successfully`, func() { - SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{}) - Expect(enterpriseManagementService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - ClearTestEnvironment(testEnvironment) - - clone := enterpriseManagementService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) + + res.WriteHeader(202) + })) }) - It(`Create service client using external config and set url from constructor successfully`, func() { - SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{ - URL: "https://testService/api", + It(`Invoke UpdateAccount successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, }) - Expect(enterpriseManagementService).ToNot(BeNil()) Expect(serviceErr).To(BeNil()) - Expect(enterpriseManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) - ClearTestEnvironment(testEnvironment) - - clone := enterpriseManagementService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) - }) - It(`Create service client using external config and set url programatically successfully`, func() { - SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{}) - err := enterpriseManagementService.SetServiceURL("https://testService/api") - Expect(err).To(BeNil()) Expect(enterpriseManagementService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - Expect(enterpriseManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) - ClearTestEnvironment(testEnvironment) - clone := enterpriseManagementService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != enterpriseManagementService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(enterpriseManagementService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(enterpriseManagementService.Service.Options.Authenticator)) - }) - }) - Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { - // Map containing environment variables used in testing. - var testEnvironment = map[string]string{ - "ENTERPRISE_MANAGEMENT_URL": "https://enterprisemanagementv1/api", - "ENTERPRISE_MANAGEMENT_AUTH_TYPE": "someOtherAuth", - } + // Invoke operation with nil options model (negative test) + response, operationErr := enterpriseManagementService.UpdateAccount(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) - SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{}) + // Construct an instance of the UpdateAccountOptions model + updateAccountOptionsModel := new(enterprisemanagementv1.UpdateAccountOptions) + updateAccountOptionsModel.AccountID = core.StringPtr("testString") + updateAccountOptionsModel.Parent = core.StringPtr("testString") + updateAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} - It(`Instantiate service client with error`, func() { - Expect(enterpriseManagementService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - ClearTestEnvironment(testEnvironment) + // Invoke operation with valid options model (positive test) + response, operationErr = enterpriseManagementService.UpdateAccount(updateAccountOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) }) - }) - Context(`Using external config, construct service client instances with error: Invalid URL`, func() { - // Map containing environment variables used in testing. - var testEnvironment = map[string]string{ - "ENTERPRISE_MANAGEMENT_AUTH_TYPE": "NOAuth", - } + It(`Invoke UpdateAccount with error: Operation validation and request error`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) - SetTestEnvironment(testEnvironment) - enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1UsingExternalConfig(&enterprisemanagementv1.EnterpriseManagementV1Options{ - URL: "{BAD_URL_STRING", + // Construct an instance of the UpdateAccountOptions model + updateAccountOptionsModel := new(enterprisemanagementv1.UpdateAccountOptions) + updateAccountOptionsModel.AccountID = core.StringPtr("testString") + updateAccountOptionsModel.Parent = core.StringPtr("testString") + updateAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := enterpriseManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := enterpriseManagementService.UpdateAccount(updateAccountOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the UpdateAccountOptions model with no property values + updateAccountOptionsModelNew := new(enterprisemanagementv1.UpdateAccountOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = enterpriseManagementService.UpdateAccount(updateAccountOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) }) - - It(`Instantiate service client with error`, func() { - Expect(enterpriseManagementService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - ClearTestEnvironment(testEnvironment) + AfterEach(func() { + testServer.Close() }) }) }) - Describe(`Regional endpoint tests`, func() { - It(`GetServiceURLForRegion(region string)`, func() { - var url string - var err error - url, err = enterprisemanagementv1.GetServiceURLForRegion("INVALID_REGION") - Expect(url).To(BeEmpty()) - Expect(err).ToNot(BeNil()) - fmt.Fprintf(GinkgoWriter, "Expected error: %s\n", err.Error()) - }) - }) Describe(`CreateAccountGroup(createAccountGroupOptions *CreateAccountGroupOptions) - Operation response error`, func() { createAccountGroupPath := "/account-groups" - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with invalid JSON response`, func() { BeforeEach(func() { testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -1897,7 +2060,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.Method).To(Equal("POST")) res.Header().Set("Content-type", "application/json") res.WriteHeader(201) - fmt.Fprintf(res, `} this is not valid json {`) + fmt.Fprint(res, `} this is not valid json {`) })) }) It(`Invoke CreateAccountGroup with error: Operation response processing error`, func() { @@ -1932,7 +2095,6 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) - Describe(`CreateAccountGroup(createAccountGroupOptions *CreateAccountGroupOptions)`, func() { createAccountGroupPath := "/account-groups" Context(`Using mock server endpoint with timeout`, func() { @@ -2103,10 +2265,46 @@ var _ = Describe(`EnterpriseManagementV1`, func() { testServer.Close() }) }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(201) + })) + }) + It(`Invoke CreateAccountGroup successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + // Construct an instance of the CreateAccountGroupOptions model + createAccountGroupOptionsModel := new(enterprisemanagementv1.CreateAccountGroupOptions) + createAccountGroupOptionsModel.Parent = core.StringPtr("testString") + createAccountGroupOptionsModel.Name = core.StringPtr("testString") + createAccountGroupOptionsModel.PrimaryContactIamID = core.StringPtr("testString") + createAccountGroupOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := enterpriseManagementService.CreateAccountGroup(createAccountGroupOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) }) Describe(`ListAccountGroups(listAccountGroupsOptions *ListAccountGroupsOptions) - Operation response error`, func() { listAccountGroupsPath := "/account-groups" - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with invalid JSON response`, func() { BeforeEach(func() { testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -2118,10 +2316,10 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.URL.Query()["parent_account_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["next_docid"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["parent"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) + fmt.Fprint(res, `} this is not valid json {`) })) }) It(`Invoke ListAccountGroups with error: Operation response processing error`, func() { @@ -2138,7 +2336,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listAccountGroupsOptionsModel.ParentAccountGroupID = core.StringPtr("testString") listAccountGroupsOptionsModel.NextDocid = core.StringPtr("testString") listAccountGroupsOptionsModel.Parent = core.StringPtr("testString") - listAccountGroupsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listAccountGroupsOptionsModel.Limit = core.Int64Ptr(int64(10)) listAccountGroupsOptionsModel.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 := enterpriseManagementService.ListAccountGroups(listAccountGroupsOptionsModel) @@ -2158,7 +2356,6 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) - Describe(`ListAccountGroups(listAccountGroupsOptions *ListAccountGroupsOptions)`, func() { listAccountGroupsPath := "/account-groups" Context(`Using mock server endpoint with timeout`, func() { @@ -2174,7 +2371,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.URL.Query()["parent_account_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["next_docid"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["parent"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) // Sleep a short time to support a timeout test time.Sleep(100 * time.Millisecond) @@ -2199,7 +2396,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listAccountGroupsOptionsModel.ParentAccountGroupID = core.StringPtr("testString") listAccountGroupsOptionsModel.NextDocid = core.StringPtr("testString") listAccountGroupsOptionsModel.Parent = core.StringPtr("testString") - listAccountGroupsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listAccountGroupsOptionsModel.Limit = core.Int64Ptr(int64(10)) listAccountGroupsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with a Context to test a timeout error @@ -2240,7 +2437,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.URL.Query()["parent_account_group_id"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["next_docid"]).To(Equal([]string{"testString"})) Expect(req.URL.Query()["parent"]).To(Equal([]string{"testString"})) - Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(100))})) + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(10))})) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) @@ -2267,7 +2464,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listAccountGroupsOptionsModel.ParentAccountGroupID = core.StringPtr("testString") listAccountGroupsOptionsModel.NextDocid = core.StringPtr("testString") listAccountGroupsOptionsModel.Parent = core.StringPtr("testString") - listAccountGroupsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listAccountGroupsOptionsModel.Limit = core.Int64Ptr(int64(10)) listAccountGroupsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with valid options model (positive test) @@ -2291,7 +2488,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listAccountGroupsOptionsModel.ParentAccountGroupID = core.StringPtr("testString") listAccountGroupsOptionsModel.NextDocid = core.StringPtr("testString") listAccountGroupsOptionsModel.Parent = core.StringPtr("testString") - listAccountGroupsOptionsModel.Limit = core.Int64Ptr(int64(100)) + listAccountGroupsOptionsModel.Limit = core.Int64Ptr(int64(10)) listAccountGroupsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := enterpriseManagementService.SetServiceURL("") @@ -2306,10 +2503,149 @@ var _ = Describe(`EnterpriseManagementV1`, func() { testServer.Close() }) }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke ListAccountGroups successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + // Construct an instance of the ListAccountGroupsOptions model + listAccountGroupsOptionsModel := new(enterprisemanagementv1.ListAccountGroupsOptions) + listAccountGroupsOptionsModel.EnterpriseID = core.StringPtr("testString") + listAccountGroupsOptionsModel.ParentAccountGroupID = core.StringPtr("testString") + listAccountGroupsOptionsModel.NextDocid = core.StringPtr("testString") + listAccountGroupsOptionsModel.Parent = core.StringPtr("testString") + listAccountGroupsOptionsModel.Limit = core.Int64Ptr(int64(10)) + listAccountGroupsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := enterpriseManagementService.ListAccountGroups(listAccountGroupsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + Context(`Test pagination helper method on response`, func() { + It(`Invoke GetNextNextDocid successfully`, func() { + responseObject := new(enterprisemanagementv1.ListAccountGroupsResponse) + responseObject.NextURL = core.StringPtr("ibm.com?next_docid=abc-123") + + value, err := responseObject.GetNextNextDocid() + Expect(err).To(BeNil()) + Expect(value).To(Equal(core.StringPtr("abc-123"))) + }) + It(`Invoke GetNextNextDocid without a "NextURL" property in the response`, func() { + responseObject := new(enterprisemanagementv1.ListAccountGroupsResponse) + + value, err := responseObject.GetNextNextDocid() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + It(`Invoke GetNextNextDocid without any query params in the "NextURL" URL`, func() { + responseObject := new(enterprisemanagementv1.ListAccountGroupsResponse) + responseObject.NextURL = core.StringPtr("ibm.com") + + value, err := responseObject.GetNextNextDocid() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + }) + Context(`Using mock server endpoint - paginated response`, func() { + BeforeEach(func() { + var requestNumber int = 0 + 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(listAccountGroupsPath)) + Expect(req.Method).To(Equal("GET")) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + requestNumber++ + if requestNumber == 1 { + fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"next_url":"https://myhost.com/somePath?next_docid=1","resources":[{"url":"URL","id":"ID","crn":"CRN","parent":"Parent","enterprise_account_id":"EnterpriseAccountID","enterprise_id":"EnterpriseID","enterprise_path":"EnterprisePath","name":"Name","state":"State","primary_contact_iam_id":"PrimaryContactIamID","primary_contact_email":"PrimaryContactEmail","created_at":"2019-01-01T12:00:00.000Z","created_by":"CreatedBy","updated_at":"2019-01-01T12:00:00.000Z","updated_by":"UpdatedBy"}]}`) + } else if requestNumber == 2 { + fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"resources":[{"url":"URL","id":"ID","crn":"CRN","parent":"Parent","enterprise_account_id":"EnterpriseAccountID","enterprise_id":"EnterpriseID","enterprise_path":"EnterprisePath","name":"Name","state":"State","primary_contact_iam_id":"PrimaryContactIamID","primary_contact_email":"PrimaryContactEmail","created_at":"2019-01-01T12:00:00.000Z","created_by":"CreatedBy","updated_at":"2019-01-01T12:00:00.000Z","updated_by":"UpdatedBy"}]}`) + } else { + res.WriteHeader(400) + } + })) + }) + It(`Use AccountGroupsPager.GetNext successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + listAccountGroupsOptionsModel := &enterprisemanagementv1.ListAccountGroupsOptions{ + EnterpriseID: core.StringPtr("testString"), + ParentAccountGroupID: core.StringPtr("testString"), + Parent: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(10)), + } + + pager, err := enterpriseManagementService.NewAccountGroupsPager(listAccountGroupsOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []enterprisemanagementv1.AccountGroup + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + Expect(len(allResults)).To(Equal(2)) + }) + It(`Use AccountGroupsPager.GetAll successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + listAccountGroupsOptionsModel := &enterprisemanagementv1.ListAccountGroupsOptions{ + EnterpriseID: core.StringPtr("testString"), + ParentAccountGroupID: core.StringPtr("testString"), + Parent: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(10)), + } + + pager, err := enterpriseManagementService.NewAccountGroupsPager(listAccountGroupsOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + allResults, err := pager.GetAll() + Expect(err).To(BeNil()) + Expect(allResults).ToNot(BeNil()) + Expect(len(allResults)).To(Equal(2)) + }) + }) }) Describe(`GetAccountGroup(getAccountGroupOptions *GetAccountGroupOptions) - Operation response error`, func() { getAccountGroupPath := "/account-groups/testString" - Context(`Using mock server endpoint`, func() { + Context(`Using mock server endpoint with invalid JSON response`, func() { BeforeEach(func() { testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { defer GinkgoRecover() @@ -2319,7 +2655,7 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(req.Method).To(Equal("GET")) res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, `} this is not valid json {`) + fmt.Fprint(res, `} this is not valid json {`) })) }) It(`Invoke GetAccountGroup with error: Operation response processing error`, func() { @@ -2352,7 +2688,6 @@ var _ = Describe(`EnterpriseManagementV1`, func() { }) }) }) - Describe(`GetAccountGroup(getAccountGroupOptions *GetAccountGroupOptions)`, func() { getAccountGroupPath := "/account-groups/testString" Context(`Using mock server endpoint with timeout`, func() { @@ -2485,8 +2820,41 @@ var _ = Describe(`EnterpriseManagementV1`, func() { testServer.Close() }) }) - }) + Context(`Using mock server endpoint with missing response body`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Set success status code with no respoonse body + res.WriteHeader(200) + })) + }) + It(`Invoke GetAccountGroup successfully`, func() { + enterpriseManagementService, serviceErr := enterprisemanagementv1.NewEnterpriseManagementV1(&enterprisemanagementv1.EnterpriseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseManagementService).ToNot(BeNil()) + + // Construct an instance of the GetAccountGroupOptions model + getAccountGroupOptionsModel := new(enterprisemanagementv1.GetAccountGroupOptions) + getAccountGroupOptionsModel.AccountGroupID = core.StringPtr("testString") + getAccountGroupOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := enterpriseManagementService.GetAccountGroup(getAccountGroupOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) Describe(`UpdateAccountGroup(updateAccountGroupOptions *UpdateAccountGroupOptions)`, func() { updateAccountGroupPath := "/account-groups/testString" Context(`Using mock server endpoint`, func() { @@ -2685,14 +3053,14 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listAccountGroupsOptionsModel.SetParentAccountGroupID("testString") listAccountGroupsOptionsModel.SetNextDocid("testString") listAccountGroupsOptionsModel.SetParent("testString") - listAccountGroupsOptionsModel.SetLimit(int64(100)) + listAccountGroupsOptionsModel.SetLimit(int64(10)) listAccountGroupsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(listAccountGroupsOptionsModel).ToNot(BeNil()) Expect(listAccountGroupsOptionsModel.EnterpriseID).To(Equal(core.StringPtr("testString"))) Expect(listAccountGroupsOptionsModel.ParentAccountGroupID).To(Equal(core.StringPtr("testString"))) Expect(listAccountGroupsOptionsModel.NextDocid).To(Equal(core.StringPtr("testString"))) Expect(listAccountGroupsOptionsModel.Parent).To(Equal(core.StringPtr("testString"))) - Expect(listAccountGroupsOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(100)))) + Expect(listAccountGroupsOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(10)))) Expect(listAccountGroupsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewListAccountsOptions successfully`, func() { @@ -2702,14 +3070,14 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listAccountsOptionsModel.SetAccountGroupID("testString") listAccountsOptionsModel.SetNextDocid("testString") listAccountsOptionsModel.SetParent("testString") - listAccountsOptionsModel.SetLimit(int64(100)) + listAccountsOptionsModel.SetLimit(int64(10)) listAccountsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(listAccountsOptionsModel).ToNot(BeNil()) Expect(listAccountsOptionsModel.EnterpriseID).To(Equal(core.StringPtr("testString"))) Expect(listAccountsOptionsModel.AccountGroupID).To(Equal(core.StringPtr("testString"))) Expect(listAccountsOptionsModel.NextDocid).To(Equal(core.StringPtr("testString"))) Expect(listAccountsOptionsModel.Parent).To(Equal(core.StringPtr("testString"))) - Expect(listAccountsOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(100)))) + Expect(listAccountsOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(10)))) Expect(listAccountsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewListEnterprisesOptions successfully`, func() { @@ -2719,14 +3087,14 @@ var _ = Describe(`EnterpriseManagementV1`, func() { listEnterprisesOptionsModel.SetAccountGroupID("testString") listEnterprisesOptionsModel.SetAccountID("testString") listEnterprisesOptionsModel.SetNextDocid("testString") - listEnterprisesOptionsModel.SetLimit(int64(100)) + listEnterprisesOptionsModel.SetLimit(int64(10)) listEnterprisesOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(listEnterprisesOptionsModel).ToNot(BeNil()) Expect(listEnterprisesOptionsModel.EnterpriseAccountID).To(Equal(core.StringPtr("testString"))) Expect(listEnterprisesOptionsModel.AccountGroupID).To(Equal(core.StringPtr("testString"))) Expect(listEnterprisesOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) Expect(listEnterprisesOptionsModel.NextDocid).To(Equal(core.StringPtr("testString"))) - Expect(listEnterprisesOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(100)))) + Expect(listEnterprisesOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(10)))) Expect(listEnterprisesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewUpdateAccountGroupOptions successfully`, func() { @@ -2788,11 +3156,11 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(mockReader).ToNot(BeNil()) }) It(`Invoke CreateMockDate() successfully`, func() { - mockDate := CreateMockDate() + mockDate := CreateMockDate("2019-01-01") Expect(mockDate).ToNot(BeNil()) }) It(`Invoke CreateMockDateTime() successfully`, func() { - mockDateTime := CreateMockDateTime() + mockDateTime := CreateMockDateTime("2019-01-01T12:00:00.000Z") Expect(mockDateTime).ToNot(BeNil()) }) }) @@ -2817,13 +3185,19 @@ func CreateMockReader(mockData string) io.ReadCloser { return io.NopCloser(bytes.NewReader([]byte(mockData))) } -func CreateMockDate() *strfmt.Date { - d := strfmt.Date(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) +func CreateMockDate(mockData string) *strfmt.Date { + d, err := core.ParseDate(mockData) + if err != nil { + return nil + } return &d } -func CreateMockDateTime() *strfmt.DateTime { - d := strfmt.DateTime(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) +func CreateMockDateTime(mockData string) *strfmt.DateTime { + d, err := core.ParseDateTime(mockData) + if err != nil { + return nil + } return &d }