From fc4128f84f8933b8f1e81dbf76557933368f089a Mon Sep 17 00:00:00 2001 From: Phil Adams Date: Mon, 7 Nov 2022 09:23:58 -0500 Subject: [PATCH] fix(User Management): re-gen service to get new Pagers (#219) This commit contains a re-gen of the User Management service to leverage the new Pagers emitted by the SDK generator. Signed-off-by: Phil Adams --- .secrets.baseline | 2 +- usermanagementv1/user_management_v1.go | 648 +++++++++++++----- .../user_management_v1_examples_test.go | 30 +- .../user_management_v1_integration_test.go | 65 +- usermanagementv1/user_management_v1_test.go | 648 +++++++++++++----- 5 files changed, 1023 insertions(+), 370 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 3116ed80..845ddfef 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-03T17:59:31Z", + "generated_at": "2022-11-04T16:22:52Z", "plugins_used": [ { "name": "AWSKeyDetector" diff --git a/usermanagementv1/user_management_v1.go b/usermanagementv1/user_management_v1.go index c3a01165..258a9e23 100644 --- a/usermanagementv1/user_management_v1.go +++ b/usermanagementv1/user_management_v1.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. @@ -15,7 +15,7 @@ */ /* - * IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-7b3ab37f-20210218-191409 + * IBM OpenAPI SDK Code Generator Version: 3.60.2-95dc7721-20221102-203229 */ // Package usermanagementv1 : Operations and models for the UserManagementV1 service @@ -35,7 +35,7 @@ import ( // UserManagementV1 : Manage the lifecycle of your users using User Management APIs. // -// Version: 1.0 +// API Version: 1.0 type UserManagementV1 struct { Service *core.BaseService } @@ -204,15 +204,15 @@ func (userManagement *UserManagementV1) ListUsersWithContext(ctx context.Context } builder.AddHeader("Accept", "application/json") - if listUsersOptions.State != nil { - builder.AddQuery("state", fmt.Sprint(*listUsersOptions.State)) - } if listUsersOptions.Limit != nil { builder.AddQuery("limit", fmt.Sprint(*listUsersOptions.Limit)) } if listUsersOptions.Start != nil { builder.AddQuery("_start", fmt.Sprint(*listUsersOptions.Start)) } + if listUsersOptions.UserID != nil { + builder.AddQuery("user_id", fmt.Sprint(*listUsersOptions.UserID)) + } request, err := builder.Build() if err != nil { @@ -224,11 +224,13 @@ func (userManagement *UserManagementV1) ListUsersWithContext(ctx context.Context if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalUserList) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalUserList) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -306,11 +308,13 @@ func (userManagement *UserManagementV1) InviteUsersWithContext(ctx context.Conte if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalInvitedUserList) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalInvitedUserList) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -336,7 +340,7 @@ func (userManagement *UserManagementV1) GetUserProfileWithContext(ctx context.Co pathParamsMap := map[string]string{ "account_id": *getUserProfileOptions.AccountID, - "iam_id": *getUserProfileOptions.IamID, + "iam_id": *getUserProfileOptions.IamID, } builder := core.NewRequestBuilder(core.GET) @@ -357,6 +361,10 @@ func (userManagement *UserManagementV1) GetUserProfileWithContext(ctx context.Co } builder.AddHeader("Accept", "application/json") + if getUserProfileOptions.IncludeActivity != nil { + builder.AddQuery("include_activity", fmt.Sprint(*getUserProfileOptions.IncludeActivity)) + } + request, err := builder.Build() if err != nil { return @@ -367,11 +375,13 @@ func (userManagement *UserManagementV1) GetUserProfileWithContext(ctx context.Co if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalUserProfile) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalUserProfile) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -400,7 +410,7 @@ func (userManagement *UserManagementV1) UpdateUserProfileWithContext(ctx context pathParamsMap := map[string]string{ "account_id": *updateUserProfileOptions.AccountID, - "iam_id": *updateUserProfileOptions.IamID, + "iam_id": *updateUserProfileOptions.IamID, } builder := core.NewRequestBuilder(core.PATCH) @@ -421,6 +431,10 @@ func (userManagement *UserManagementV1) UpdateUserProfileWithContext(ctx context } builder.AddHeader("Content-Type", "application/json") + if updateUserProfileOptions.IncludeActivity != nil { + builder.AddQuery("include_activity", fmt.Sprint(*updateUserProfileOptions.IncludeActivity)) + } + body := make(map[string]interface{}) if updateUserProfileOptions.Firstname != nil { body["firstname"] = updateUserProfileOptions.Firstname @@ -480,7 +494,7 @@ func (userManagement *UserManagementV1) RemoveUserWithContext(ctx context.Contex pathParamsMap := map[string]string{ "account_id": *removeUserOptions.AccountID, - "iam_id": *removeUserOptions.IamID, + "iam_id": *removeUserOptions.IamID, } builder := core.NewRequestBuilder(core.DELETE) @@ -500,6 +514,115 @@ func (userManagement *UserManagementV1) RemoveUserWithContext(ctx context.Contex builder.AddHeader(headerName, headerValue) } + if removeUserOptions.IncludeActivity != nil { + builder.AddQuery("include_activity", fmt.Sprint(*removeUserOptions.IncludeActivity)) + } + + request, err := builder.Build() + if err != nil { + return + } + + response, err = userManagement.Service.Request(request, nil) + + return +} + +// Accept : Accept an invitation +// Accept a user invitation to an account. You can use the user's token for authorization. To use this method, the +// requesting user must provide the account ID for the account that they are accepting an invitation for. If the user +// already accepted the invitation request, it returns 204 with no response body. +func (userManagement *UserManagementV1) Accept(acceptOptions *AcceptOptions) (response *core.DetailedResponse, err error) { + return userManagement.AcceptWithContext(context.Background(), acceptOptions) +} + +// AcceptWithContext is an alternate form of the Accept method which supports a Context parameter +func (userManagement *UserManagementV1) AcceptWithContext(ctx context.Context, acceptOptions *AcceptOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateStruct(acceptOptions, "acceptOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.POST) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = userManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(userManagement.Service.Options.URL, `/v2/users/accept`, nil) + if err != nil { + return + } + + for headerName, headerValue := range acceptOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("user_management", "V1", "Accept") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if acceptOptions.AccountID != nil { + body["account_id"] = acceptOptions.AccountID + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + response, err = userManagement.Service.Request(request, nil) + + return +} + +// V3RemoveUser : Remove user from account (Asynchronous) +// Remove users from an account by using the user's IAM ID. You must use a user token for authorization. Service IDs +// can't remove users from an account. If removing the user fails it will set the user's state to ERROR_WHILE_DELETING. +// To use this method, the requesting user must have the editor or administrator role on the User Management service. +// For more information, see the [Removing users](https://cloud.ibm.com/docs/account?topic=account-remove) +// documentation. +func (userManagement *UserManagementV1) V3RemoveUser(v3RemoveUserOptions *V3RemoveUserOptions) (response *core.DetailedResponse, err error) { + return userManagement.V3RemoveUserWithContext(context.Background(), v3RemoveUserOptions) +} + +// V3RemoveUserWithContext is an alternate form of the V3RemoveUser method which supports a Context parameter +func (userManagement *UserManagementV1) V3RemoveUserWithContext(ctx context.Context, v3RemoveUserOptions *V3RemoveUserOptions) (response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(v3RemoveUserOptions, "v3RemoveUserOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(v3RemoveUserOptions, "v3RemoveUserOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "account_id": *v3RemoveUserOptions.AccountID, + "iam_id": *v3RemoveUserOptions.IamID, + } + + builder := core.NewRequestBuilder(core.DELETE) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = userManagement.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(userManagement.Service.Options.URL, `/v3/accounts/{account_id}/users/{iam_id}`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range v3RemoveUserOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("user_management", "V1", "V3RemoveUser") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + request, err := builder.Build() if err != nil { return @@ -536,7 +659,7 @@ func (userManagement *UserManagementV1) GetUserSettingsWithContext(ctx context.C pathParamsMap := map[string]string{ "account_id": *getUserSettingsOptions.AccountID, - "iam_id": *getUserSettingsOptions.IamID, + "iam_id": *getUserSettingsOptions.IamID, } builder := core.NewRequestBuilder(core.GET) @@ -567,11 +690,13 @@ func (userManagement *UserManagementV1) GetUserSettingsWithContext(ctx context.C if err != nil { return } - err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalUserSettings) - if err != nil { - return + if rawResponse != nil { + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalUserSettings) + if err != nil { + return + } + response.Result = result } - response.Result = result return } @@ -598,7 +723,7 @@ func (userManagement *UserManagementV1) UpdateUserSettingsWithContext(ctx contex pathParamsMap := map[string]string{ "account_id": *updateUserSettingsOptions.AccountID, - "iam_id": *updateUserSettingsOptions.IamID, + "iam_id": *updateUserSettingsOptions.IamID, } builder := core.NewRequestBuilder(core.PATCH) @@ -647,13 +772,42 @@ func (userManagement *UserManagementV1) UpdateUserSettingsWithContext(ctx contex return } +// AcceptOptions : The Accept options. +type AcceptOptions struct { + // The account ID. + AccountID *string `json:"account_id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewAcceptOptions : Instantiate AcceptOptions +func (*UserManagementV1) NewAcceptOptions() *AcceptOptions { + return &AcceptOptions{} +} + +// SetAccountID : Allow user to set AccountID +func (_options *AcceptOptions) SetAccountID(accountID string) *AcceptOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *AcceptOptions) SetHeaders(param map[string]string) *AcceptOptions { + options.Headers = param + return options +} + // GetUserProfileOptions : The GetUserProfile options. type GetUserProfileOptions struct { - // The account ID. - AccountID *string `validate:"required,ne="` + // The account ID of the specified user. + AccountID *string `json:"account_id" validate:"required,ne="` // The user's IAM ID. - IamID *string `validate:"required,ne="` + IamID *string `json:"iam_id" validate:"required,ne="` + + // Include activity information of the user, such as the last authentication timestamp. + IncludeActivity *string `json:"include_activity,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -663,20 +817,26 @@ type GetUserProfileOptions struct { func (*UserManagementV1) NewGetUserProfileOptions(accountID string, iamID string) *GetUserProfileOptions { return &GetUserProfileOptions{ AccountID: core.StringPtr(accountID), - IamID: core.StringPtr(iamID), + IamID: core.StringPtr(iamID), } } // SetAccountID : Allow user to set AccountID -func (options *GetUserProfileOptions) SetAccountID(accountID string) *GetUserProfileOptions { - options.AccountID = core.StringPtr(accountID) - return options +func (_options *GetUserProfileOptions) SetAccountID(accountID string) *GetUserProfileOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } // SetIamID : Allow user to set IamID -func (options *GetUserProfileOptions) SetIamID(iamID string) *GetUserProfileOptions { - options.IamID = core.StringPtr(iamID) - return options +func (_options *GetUserProfileOptions) SetIamID(iamID string) *GetUserProfileOptions { + _options.IamID = core.StringPtr(iamID) + return _options +} + +// SetIncludeActivity : Allow user to set IncludeActivity +func (_options *GetUserProfileOptions) SetIncludeActivity(includeActivity string) *GetUserProfileOptions { + _options.IncludeActivity = core.StringPtr(includeActivity) + return _options } // SetHeaders : Allow user to set Headers @@ -687,11 +847,11 @@ func (options *GetUserProfileOptions) SetHeaders(param map[string]string) *GetUs // GetUserSettingsOptions : The GetUserSettings options. type GetUserSettingsOptions struct { - // The account ID. - AccountID *string `validate:"required,ne="` + // The account ID of the specified user. + AccountID *string `json:"account_id" validate:"required,ne="` // The user's IAM ID. - IamID *string `validate:"required,ne="` + IamID *string `json:"iam_id" validate:"required,ne="` // Allows users to set headers on API requests Headers map[string]string @@ -701,20 +861,20 @@ type GetUserSettingsOptions struct { func (*UserManagementV1) NewGetUserSettingsOptions(accountID string, iamID string) *GetUserSettingsOptions { return &GetUserSettingsOptions{ AccountID: core.StringPtr(accountID), - IamID: core.StringPtr(iamID), + IamID: core.StringPtr(iamID), } } // SetAccountID : Allow user to set AccountID -func (options *GetUserSettingsOptions) SetAccountID(accountID string) *GetUserSettingsOptions { - options.AccountID = core.StringPtr(accountID) - return options +func (_options *GetUserSettingsOptions) SetAccountID(accountID string) *GetUserSettingsOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } // SetIamID : Allow user to set IamID -func (options *GetUserSettingsOptions) SetIamID(iamID string) *GetUserSettingsOptions { - options.IamID = core.StringPtr(iamID) - return options +func (_options *GetUserSettingsOptions) SetIamID(iamID string) *GetUserSettingsOptions { + _options.IamID = core.StringPtr(iamID) + return _options } // SetHeaders : Allow user to set Headers @@ -725,17 +885,17 @@ func (options *GetUserSettingsOptions) SetHeaders(param map[string]string) *GetU // InviteUsersOptions : The InviteUsers options. type InviteUsersOptions struct { - // The account ID. - AccountID *string `validate:"required,ne="` + // The account ID of the specified user. + AccountID *string `json:"account_id" validate:"required,ne="` // A list of users to be invited. - Users []InviteUser + Users []InviteUser `json:"users,omitempty"` // A list of IAM policies. - IamPolicy []InviteUserIamPolicy + IamPolicy []InviteUserIamPolicy `json:"iam_policy,omitempty"` // A list of access groups. - AccessGroups []string + AccessGroups []string `json:"access_groups,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -749,27 +909,27 @@ func (*UserManagementV1) NewInviteUsersOptions(accountID string) *InviteUsersOpt } // SetAccountID : Allow user to set AccountID -func (options *InviteUsersOptions) SetAccountID(accountID string) *InviteUsersOptions { - options.AccountID = core.StringPtr(accountID) - return options +func (_options *InviteUsersOptions) SetAccountID(accountID string) *InviteUsersOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } // SetUsers : Allow user to set Users -func (options *InviteUsersOptions) SetUsers(users []InviteUser) *InviteUsersOptions { - options.Users = users - return options +func (_options *InviteUsersOptions) SetUsers(users []InviteUser) *InviteUsersOptions { + _options.Users = users + return _options } // SetIamPolicy : Allow user to set IamPolicy -func (options *InviteUsersOptions) SetIamPolicy(iamPolicy []InviteUserIamPolicy) *InviteUsersOptions { - options.IamPolicy = iamPolicy - return options +func (_options *InviteUsersOptions) SetIamPolicy(iamPolicy []InviteUserIamPolicy) *InviteUsersOptions { + _options.IamPolicy = iamPolicy + return _options } // SetAccessGroups : Allow user to set AccessGroups -func (options *InviteUsersOptions) SetAccessGroups(accessGroups []string) *InviteUsersOptions { - options.AccessGroups = accessGroups - return options +func (_options *InviteUsersOptions) SetAccessGroups(accessGroups []string) *InviteUsersOptions { + _options.AccessGroups = accessGroups + return _options } // SetHeaders : Allow user to set Headers @@ -828,18 +988,18 @@ func UnmarshalInvitedUserList(m map[string]json.RawMessage, result interface{}) // ListUsersOptions : The ListUsers options. type ListUsersOptions struct { - // The account ID. - AccountID *string `validate:"required,ne="` - - // The state of the user. - State *string + // The account ID of the specified user. + AccountID *string `json:"account_id" validate:"required,ne="` // The number of results to be returned. - Limit *int64 + Limit *int64 `json:"limit,omitempty"` // An optional token that indicates the beginning of the page of results to be returned. If omitted, the first page of // results is returned. This value is obtained from the 'next_url' field of the operation response. - Start *string + Start *string `json:"_start,omitempty"` + + // Filter users based on their user ID. + UserID *string `json:"user_id,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -853,27 +1013,27 @@ func (*UserManagementV1) NewListUsersOptions(accountID string) *ListUsersOptions } // SetAccountID : Allow user to set AccountID -func (options *ListUsersOptions) SetAccountID(accountID string) *ListUsersOptions { - options.AccountID = core.StringPtr(accountID) - return options -} - -// SetState : Allow user to set State -func (options *ListUsersOptions) SetState(state string) *ListUsersOptions { - options.State = core.StringPtr(state) - return options +func (_options *ListUsersOptions) SetAccountID(accountID string) *ListUsersOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } // SetLimit : Allow user to set Limit -func (options *ListUsersOptions) SetLimit(limit int64) *ListUsersOptions { - options.Limit = core.Int64Ptr(limit) - return options +func (_options *ListUsersOptions) SetLimit(limit int64) *ListUsersOptions { + _options.Limit = core.Int64Ptr(limit) + return _options } // SetStart : Allow user to set Start -func (options *ListUsersOptions) SetStart(start string) *ListUsersOptions { - options.Start = core.StringPtr(start) - return options +func (_options *ListUsersOptions) SetStart(start string) *ListUsersOptions { + _options.Start = core.StringPtr(start) + return _options +} + +// SetUserID : Allow user to set UserID +func (_options *ListUsersOptions) SetUserID(userID string) *ListUsersOptions { + _options.UserID = core.StringPtr(userID) + return _options } // SetHeaders : Allow user to set Headers @@ -884,11 +1044,14 @@ func (options *ListUsersOptions) SetHeaders(param map[string]string) *ListUsersO // RemoveUserOptions : The RemoveUser options. type RemoveUserOptions struct { - // The account ID. - AccountID *string `validate:"required,ne="` + // The account ID of the specified user. + AccountID *string `json:"account_id" validate:"required,ne="` // The user's IAM ID. - IamID *string `validate:"required,ne="` + IamID *string `json:"iam_id" validate:"required,ne="` + + // Include activity information of the user, such as the last authentication timestamp. + IncludeActivity *string `json:"include_activity,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -898,20 +1061,26 @@ type RemoveUserOptions struct { func (*UserManagementV1) NewRemoveUserOptions(accountID string, iamID string) *RemoveUserOptions { return &RemoveUserOptions{ AccountID: core.StringPtr(accountID), - IamID: core.StringPtr(iamID), + IamID: core.StringPtr(iamID), } } // SetAccountID : Allow user to set AccountID -func (options *RemoveUserOptions) SetAccountID(accountID string) *RemoveUserOptions { - options.AccountID = core.StringPtr(accountID) - return options +func (_options *RemoveUserOptions) SetAccountID(accountID string) *RemoveUserOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } // SetIamID : Allow user to set IamID -func (options *RemoveUserOptions) SetIamID(iamID string) *RemoveUserOptions { - options.IamID = core.StringPtr(iamID) - return options +func (_options *RemoveUserOptions) SetIamID(iamID string) *RemoveUserOptions { + _options.IamID = core.StringPtr(iamID) + return _options +} + +// SetIncludeActivity : Allow user to set IncludeActivity +func (_options *RemoveUserOptions) SetIncludeActivity(includeActivity string) *RemoveUserOptions { + _options.IncludeActivity = core.StringPtr(includeActivity) + return _options } // SetHeaders : Allow user to set Headers @@ -922,33 +1091,36 @@ func (options *RemoveUserOptions) SetHeaders(param map[string]string) *RemoveUse // UpdateUserProfileOptions : The UpdateUserProfile options. type UpdateUserProfileOptions struct { - // The account ID. - AccountID *string `validate:"required,ne="` + // The account ID of the specified user. + AccountID *string `json:"account_id" validate:"required,ne="` // The user's IAM ID. - IamID *string `validate:"required,ne="` + IamID *string `json:"iam_id" validate:"required,ne="` // The first name of the user. - Firstname *string + Firstname *string `json:"firstname,omitempty"` // The last name of the user. - Lastname *string + Lastname *string `json:"lastname,omitempty"` // The state of the user. Possible values are `PROCESSING`, `PENDING`, `ACTIVE`, `DISABLED_CLASSIC_INFRASTRUCTURE`, and // `VPN_ONLY`. - State *string + State *string `json:"state,omitempty"` // The email address of the user. - Email *string + Email *string `json:"email,omitempty"` // The phone number of the user. - Phonenumber *string + Phonenumber *string `json:"phonenumber,omitempty"` // The alternative phone number of the user. - Altphonenumber *string + Altphonenumber *string `json:"altphonenumber,omitempty"` // A link to a photo of the user. - Photo *string + Photo *string `json:"photo,omitempty"` + + // Include activity information of the user, such as the last authentication timestamp. + IncludeActivity *string `json:"include_activity,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -958,62 +1130,68 @@ type UpdateUserProfileOptions struct { func (*UserManagementV1) NewUpdateUserProfileOptions(accountID string, iamID string) *UpdateUserProfileOptions { return &UpdateUserProfileOptions{ AccountID: core.StringPtr(accountID), - IamID: core.StringPtr(iamID), + IamID: core.StringPtr(iamID), } } // SetAccountID : Allow user to set AccountID -func (options *UpdateUserProfileOptions) SetAccountID(accountID string) *UpdateUserProfileOptions { - options.AccountID = core.StringPtr(accountID) - return options +func (_options *UpdateUserProfileOptions) SetAccountID(accountID string) *UpdateUserProfileOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } // SetIamID : Allow user to set IamID -func (options *UpdateUserProfileOptions) SetIamID(iamID string) *UpdateUserProfileOptions { - options.IamID = core.StringPtr(iamID) - return options +func (_options *UpdateUserProfileOptions) SetIamID(iamID string) *UpdateUserProfileOptions { + _options.IamID = core.StringPtr(iamID) + return _options } // SetFirstname : Allow user to set Firstname -func (options *UpdateUserProfileOptions) SetFirstname(firstname string) *UpdateUserProfileOptions { - options.Firstname = core.StringPtr(firstname) - return options +func (_options *UpdateUserProfileOptions) SetFirstname(firstname string) *UpdateUserProfileOptions { + _options.Firstname = core.StringPtr(firstname) + return _options } // SetLastname : Allow user to set Lastname -func (options *UpdateUserProfileOptions) SetLastname(lastname string) *UpdateUserProfileOptions { - options.Lastname = core.StringPtr(lastname) - return options +func (_options *UpdateUserProfileOptions) SetLastname(lastname string) *UpdateUserProfileOptions { + _options.Lastname = core.StringPtr(lastname) + return _options } // SetState : Allow user to set State -func (options *UpdateUserProfileOptions) SetState(state string) *UpdateUserProfileOptions { - options.State = core.StringPtr(state) - return options +func (_options *UpdateUserProfileOptions) SetState(state string) *UpdateUserProfileOptions { + _options.State = core.StringPtr(state) + return _options } // SetEmail : Allow user to set Email -func (options *UpdateUserProfileOptions) SetEmail(email string) *UpdateUserProfileOptions { - options.Email = core.StringPtr(email) - return options +func (_options *UpdateUserProfileOptions) SetEmail(email string) *UpdateUserProfileOptions { + _options.Email = core.StringPtr(email) + return _options } // SetPhonenumber : Allow user to set Phonenumber -func (options *UpdateUserProfileOptions) SetPhonenumber(phonenumber string) *UpdateUserProfileOptions { - options.Phonenumber = core.StringPtr(phonenumber) - return options +func (_options *UpdateUserProfileOptions) SetPhonenumber(phonenumber string) *UpdateUserProfileOptions { + _options.Phonenumber = core.StringPtr(phonenumber) + return _options } // SetAltphonenumber : Allow user to set Altphonenumber -func (options *UpdateUserProfileOptions) SetAltphonenumber(altphonenumber string) *UpdateUserProfileOptions { - options.Altphonenumber = core.StringPtr(altphonenumber) - return options +func (_options *UpdateUserProfileOptions) SetAltphonenumber(altphonenumber string) *UpdateUserProfileOptions { + _options.Altphonenumber = core.StringPtr(altphonenumber) + return _options } // SetPhoto : Allow user to set Photo -func (options *UpdateUserProfileOptions) SetPhoto(photo string) *UpdateUserProfileOptions { - options.Photo = core.StringPtr(photo) - return options +func (_options *UpdateUserProfileOptions) SetPhoto(photo string) *UpdateUserProfileOptions { + _options.Photo = core.StringPtr(photo) + return _options +} + +// SetIncludeActivity : Allow user to set IncludeActivity +func (_options *UpdateUserProfileOptions) SetIncludeActivity(includeActivity string) *UpdateUserProfileOptions { + _options.IncludeActivity = core.StringPtr(includeActivity) + return _options } // SetHeaders : Allow user to set Headers @@ -1024,23 +1202,23 @@ func (options *UpdateUserProfileOptions) SetHeaders(param map[string]string) *Up // UpdateUserSettingsOptions : The UpdateUserSettings options. type UpdateUserSettingsOptions struct { - // The account ID. - AccountID *string `validate:"required,ne="` + // The account ID of the specified user. + AccountID *string `json:"account_id" validate:"required,ne="` // The user's IAM ID. - IamID *string `validate:"required,ne="` + IamID *string `json:"iam_id" validate:"required,ne="` // The console UI language. By default, this field is empty. - Language *string + Language *string `json:"language,omitempty"` // The language for email and phone notifications. By default, this field is empty. - NotificationLanguage *string + NotificationLanguage *string `json:"notification_language,omitempty"` // A comma-separated list of IP addresses. - AllowedIPAddresses *string + AllowedIPAddresses *string `json:"allowed_ip_addresses,omitempty"` // Whether user managed login is enabled. The default value is `false`. - SelfManage *bool + SelfManage *bool `json:"self_manage,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -1050,44 +1228,44 @@ type UpdateUserSettingsOptions struct { func (*UserManagementV1) NewUpdateUserSettingsOptions(accountID string, iamID string) *UpdateUserSettingsOptions { return &UpdateUserSettingsOptions{ AccountID: core.StringPtr(accountID), - IamID: core.StringPtr(iamID), + IamID: core.StringPtr(iamID), } } // SetAccountID : Allow user to set AccountID -func (options *UpdateUserSettingsOptions) SetAccountID(accountID string) *UpdateUserSettingsOptions { - options.AccountID = core.StringPtr(accountID) - return options +func (_options *UpdateUserSettingsOptions) SetAccountID(accountID string) *UpdateUserSettingsOptions { + _options.AccountID = core.StringPtr(accountID) + return _options } // SetIamID : Allow user to set IamID -func (options *UpdateUserSettingsOptions) SetIamID(iamID string) *UpdateUserSettingsOptions { - options.IamID = core.StringPtr(iamID) - return options +func (_options *UpdateUserSettingsOptions) SetIamID(iamID string) *UpdateUserSettingsOptions { + _options.IamID = core.StringPtr(iamID) + return _options } // SetLanguage : Allow user to set Language -func (options *UpdateUserSettingsOptions) SetLanguage(language string) *UpdateUserSettingsOptions { - options.Language = core.StringPtr(language) - return options +func (_options *UpdateUserSettingsOptions) SetLanguage(language string) *UpdateUserSettingsOptions { + _options.Language = core.StringPtr(language) + return _options } // SetNotificationLanguage : Allow user to set NotificationLanguage -func (options *UpdateUserSettingsOptions) SetNotificationLanguage(notificationLanguage string) *UpdateUserSettingsOptions { - options.NotificationLanguage = core.StringPtr(notificationLanguage) - return options +func (_options *UpdateUserSettingsOptions) SetNotificationLanguage(notificationLanguage string) *UpdateUserSettingsOptions { + _options.NotificationLanguage = core.StringPtr(notificationLanguage) + return _options } // SetAllowedIPAddresses : Allow user to set AllowedIPAddresses -func (options *UpdateUserSettingsOptions) SetAllowedIPAddresses(allowedIPAddresses string) *UpdateUserSettingsOptions { - options.AllowedIPAddresses = core.StringPtr(allowedIPAddresses) - return options +func (_options *UpdateUserSettingsOptions) SetAllowedIPAddresses(allowedIPAddresses string) *UpdateUserSettingsOptions { + _options.AllowedIPAddresses = core.StringPtr(allowedIPAddresses) + return _options } // SetSelfManage : Allow user to set SelfManage -func (options *UpdateUserSettingsOptions) SetSelfManage(selfManage bool) *UpdateUserSettingsOptions { - options.SelfManage = core.BoolPtr(selfManage) - return options +func (_options *UpdateUserSettingsOptions) SetSelfManage(selfManage bool) *UpdateUserSettingsOptions { + _options.SelfManage = core.BoolPtr(selfManage) + return _options } // SetHeaders : Allow user to set Headers @@ -1141,6 +1319,18 @@ func UnmarshalUserList(m map[string]json.RawMessage, result interface{}) (err er return } +// Retrieve the value to be passed to a request to access the next page of results +func (resp *UserList) GetNextStart() (*string, error) { + if core.IsNil(resp.NextURL) { + return nil, nil + } + _start, err := core.GetQueryParam(resp.NextURL, "_start") + if err != nil || _start == nil { + return nil, err + } + return _start, nil +} + // UserProfile : Returned the user profile. type UserProfile struct { // An alphanumeric value identifying the user profile. @@ -1179,6 +1369,9 @@ type UserProfile struct { // An alphanumeric value identifying the account ID. AccountID *string `json:"account_id,omitempty"` + + // The timestamp for when the user was added to the account. + AddedOn *string `json:"added_on,omitempty"` } // UnmarshalUserProfile unmarshals an instance of UserProfile from the specified map of raw messages. @@ -1232,6 +1425,10 @@ func UnmarshalUserProfile(m map[string]json.RawMessage, result interface{}) (err if err != nil { return } + err = core.UnmarshalPrimitive(m, "added_on", &obj.AddedOn) + if err != nil { + return + } reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) return } @@ -1274,6 +1471,44 @@ func UnmarshalUserSettings(m map[string]json.RawMessage, result interface{}) (er return } +// V3RemoveUserOptions : The V3RemoveUser options. +type V3RemoveUserOptions struct { + // The account ID of the specified user. + AccountID *string `json:"account_id" validate:"required,ne="` + + // The user's IAM ID. + IamID *string `json:"iam_id" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewV3RemoveUserOptions : Instantiate V3RemoveUserOptions +func (*UserManagementV1) NewV3RemoveUserOptions(accountID string, iamID string) *V3RemoveUserOptions { + return &V3RemoveUserOptions{ + AccountID: core.StringPtr(accountID), + IamID: core.StringPtr(iamID), + } +} + +// SetAccountID : Allow user to set AccountID +func (_options *V3RemoveUserOptions) SetAccountID(accountID string) *V3RemoveUserOptions { + _options.AccountID = core.StringPtr(accountID) + return _options +} + +// SetIamID : Allow user to set IamID +func (_options *V3RemoveUserOptions) SetIamID(iamID string) *V3RemoveUserOptions { + _options.IamID = core.StringPtr(iamID) + return _options +} + +// SetHeaders : Allow user to set Headers +func (options *V3RemoveUserOptions) SetHeaders(param map[string]string) *V3RemoveUserOptions { + options.Headers = param + return options +} + // Attribute : An attribute/value pair. type Attribute struct { // The name of the attribute. @@ -1335,11 +1570,11 @@ type InviteUserIamPolicy struct { } // NewInviteUserIamPolicy : Instantiate InviteUserIamPolicy (Generic Model Constructor) -func (*UserManagementV1) NewInviteUserIamPolicy(typeVar string) (model *InviteUserIamPolicy, err error) { - model = &InviteUserIamPolicy{ +func (*UserManagementV1) NewInviteUserIamPolicy(typeVar string) (_model *InviteUserIamPolicy, err error) { + _model = &InviteUserIamPolicy{ Type: core.StringPtr(typeVar), } - err = core.ValidateStruct(model, "required parameters") + err = core.ValidateStruct(_model, "required parameters") return } @@ -1395,3 +1630,90 @@ func UnmarshalRole(m map[string]json.RawMessage, result interface{}) (err error) reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) return } + +// +// UsersPager can be used to simplify the use of the "ListUsers" method. +// +type UsersPager struct { + hasNext bool + options *ListUsersOptions + client *UserManagementV1 + pageContext struct { + next *string + } +} + +// NewUsersPager returns a new UsersPager instance. +func (userManagement *UserManagementV1) NewUsersPager(options *ListUsersOptions) (pager *UsersPager, err error) { + if options.Start != nil && *options.Start != "" { + err = fmt.Errorf("the 'options.Start' field should not be set") + return + } + + var optionsCopy ListUsersOptions = *options + pager = &UsersPager{ + hasNext: true, + options: &optionsCopy, + client: userManagement, + } + return +} + +// HasNext returns true if there are potentially more results to be retrieved. +func (pager *UsersPager) HasNext() bool { + return pager.hasNext +} + +// GetNextWithContext returns the next page of results using the specified Context. +func (pager *UsersPager) GetNextWithContext(ctx context.Context) (page []UserProfile, err error) { + if !pager.HasNext() { + return nil, fmt.Errorf("no more results available") + } + + pager.options.Start = pager.pageContext.next + + result, _, err := pager.client.ListUsersWithContext(ctx, pager.options) + if err != nil { + return + } + + var next *string + if result.NextURL != nil { + var _start *string + _start, err = core.GetQueryParam(result.NextURL, "_start") + if err != nil { + err = fmt.Errorf("error retrieving '_start' query parameter from URL '%s': %s", *result.NextURL, err.Error()) + return + } + next = _start + } + 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 *UsersPager) GetAllWithContext(ctx context.Context) (allItems []UserProfile, err error) { + for pager.HasNext() { + var nextPage []UserProfile + 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 *UsersPager) GetNext() (page []UserProfile, err error) { + return pager.GetNextWithContext(context.Background()) +} + +// GetAll invokes GetAllWithContext() using context.Background() as the Context parameter. +func (pager *UsersPager) GetAll() (allItems []UserProfile, err error) { + return pager.GetAllWithContext(context.Background()) +} diff --git a/usermanagementv1/user_management_v1_examples_test.go b/usermanagementv1/user_management_v1_examples_test.go index 80ce4648..1ed03c6d 100644 --- a/usermanagementv1/user_management_v1_examples_test.go +++ b/usermanagementv1/user_management_v1_examples_test.go @@ -189,30 +189,28 @@ var _ = Describe(`UserManagementV1 Examples Tests`, func() { } }) It(`ListUsers request example`, func() { - Expect(accountID).ToNot(BeEmpty()) - fmt.Println("\nListUsers() result:") // begin-list_users + listUsersOptions := &usermanagementv1.ListUsersOptions{ + AccountID: &accountID, + } - listUsersOptions := userManagementService.NewListUsersOptions( - accountID, - ) - listUsersOptions.SetState("ACTIVE") - listUsersOptions.SetLimit(100) - - userList, response, err := userManagementService.ListUsers(listUsersOptions) + pager, err := userManagementService.NewUsersPager(listUsersOptions) if err != nil { panic(err) } - b, _ := json.MarshalIndent(userList, "", " ") - fmt.Println(string(b)) + var allResults []usermanagementv1.UserProfile + 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_users - - Expect(err).To(BeNil()) - Expect(response.StatusCode).To(Equal(200)) - Expect(userList).ToNot(BeNil()) - }) It(`RemoveUser request example`, func() { Expect(accountID).ToNot(BeEmpty()) diff --git a/usermanagementv1/user_management_v1_integration_test.go b/usermanagementv1/user_management_v1_integration_test.go index 874d5c98..7c7193cf 100644 --- a/usermanagementv1/user_management_v1_integration_test.go +++ b/usermanagementv1/user_management_v1_integration_test.go @@ -22,7 +22,6 @@ package usermanagementv1_test import ( "fmt" "log" - "net/url" "os" "time" @@ -197,7 +196,8 @@ var _ = Describe(`UserManagementV1 Integration Tests`, func() { results = append(results, result.Resources...) if result.NextURL != nil { - pageStart = getStartTokenFromURL(result.NextURL) + pageStart, err = core.GetQueryParam(result.NextURL, "_start") + Expect(err).To(BeNil()) } else { moreResults = false } @@ -205,6 +205,36 @@ var _ = Describe(`UserManagementV1 Integration Tests`, func() { fmt.Fprintf(GinkgoWriter, "Received a total of %d user profiles.\n", len(results)) }) + It(`ListUsers(listUsersOptions *ListUsersOptions) using UsersPager`, func() { + listUsersOptions := &usermanagementv1.ListUsersOptions{ + AccountID: &accountID, + } + + // Test GetNext(). + pager, err := userManagementService.NewUsersPager(listUsersOptions) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []usermanagementv1.UserProfile + for pager.HasNext() { + nextPage, err := pager.GetNext() + Expect(err).To(BeNil()) + Expect(nextPage).ToNot(BeNil()) + allResults = append(allResults, nextPage...) + } + + // Test GetAll(). + pager, err = userManagementService.NewUsersPager(listUsersOptions) + 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, "ListUsers() returned a total of %d item(s) using UsersPager.\n", len(allResults)) + }) }) Describe(`InviteUsers - Invite users`, func() { @@ -321,34 +351,3 @@ var _ = Describe(`UserManagementV1 Integration Tests`, func() { }) }) }) - -func getStartTokenFromURL(sptr *string) *string { - if sptr == nil { - return nil - } - - s := *sptr - if s == "" { - return nil - } - - u, err := url.Parse(s) - if err != nil { - return nil - } - - if u.RawQuery == "" { - return nil - } - - q, err := url.ParseQuery(u.RawQuery) - if err != nil { - return nil - } - - token := q.Get("_start") - if token == "" { - return nil - } - return &token -} diff --git a/usermanagementv1/user_management_v1_test.go b/usermanagementv1/user_management_v1_test.go index 938b092e..5b96bcc8 100644 --- a/usermanagementv1/user_management_v1_test.go +++ b/usermanagementv1/user_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(`UserManagementV1`, func() { Context(`Using external config, construct service client instances`, func() { // Map containing environment variables used in testing. var testEnvironment = map[string]string{ - "USER_MANAGEMENT_URL": "https://usermanagementv1/api", + "USER_MANAGEMENT_URL": "https://usermanagementv1/api", "USER_MANAGEMENT_AUTH_TYPE": "noauth", } It(`Create service client using external config successfully`, func() { SetTestEnvironment(testEnvironment) - userManagementService, serviceErr := usermanagementv1.NewUserManagementV1UsingExternalConfig(&usermanagementv1.UserManagementV1Options{}) + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1UsingExternalConfig(&usermanagementv1.UserManagementV1Options{ + }) Expect(userManagementService).ToNot(BeNil()) Expect(serviceErr).To(BeNil()) ClearTestEnvironment(testEnvironment) @@ -101,7 +102,8 @@ var _ = Describe(`UserManagementV1`, func() { }) It(`Create service client using external config and set url programatically successfully`, func() { SetTestEnvironment(testEnvironment) - userManagementService, serviceErr := usermanagementv1.NewUserManagementV1UsingExternalConfig(&usermanagementv1.UserManagementV1Options{}) + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1UsingExternalConfig(&usermanagementv1.UserManagementV1Options{ + }) err := userManagementService.SetServiceURL("https://testService/api") Expect(err).To(BeNil()) Expect(userManagementService).ToNot(BeNil()) @@ -119,12 +121,13 @@ var _ = Describe(`UserManagementV1`, 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{ - "USER_MANAGEMENT_URL": "https://usermanagementv1/api", + "USER_MANAGEMENT_URL": "https://usermanagementv1/api", "USER_MANAGEMENT_AUTH_TYPE": "someOtherAuth", } SetTestEnvironment(testEnvironment) - userManagementService, serviceErr := usermanagementv1.NewUserManagementV1UsingExternalConfig(&usermanagementv1.UserManagementV1Options{}) + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1UsingExternalConfig(&usermanagementv1.UserManagementV1Options{ + }) It(`Instantiate service client with error`, func() { Expect(userManagementService).To(BeNil()) @@ -135,7 +138,7 @@ var _ = Describe(`UserManagementV1`, 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{ - "USER_MANAGEMENT_AUTH_TYPE": "NOAuth", + "USER_MANAGEMENT_AUTH_TYPE": "NOAuth", } SetTestEnvironment(testEnvironment) @@ -162,7 +165,7 @@ var _ = Describe(`UserManagementV1`, func() { }) Describe(`ListUsers(listUsersOptions *ListUsersOptions) - Operation response error`, func() { listUsersPath := "/v2/accounts/testString/users" - 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() @@ -170,12 +173,12 @@ var _ = Describe(`UserManagementV1`, func() { // Verify the contents of the request Expect(req.URL.EscapedPath()).To(Equal(listUsersPath)) Expect(req.Method).To(Equal("GET")) - Expect(req.URL.Query()["state"]).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))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["user_id"]).To(Equal([]string{"testString"})) 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 ListUsers with error: Operation response processing error`, func() { @@ -189,9 +192,9 @@ var _ = Describe(`UserManagementV1`, func() { // Construct an instance of the ListUsersOptions model listUsersOptionsModel := new(usermanagementv1.ListUsersOptions) listUsersOptionsModel.AccountID = core.StringPtr("testString") - listUsersOptionsModel.State = core.StringPtr("testString") - listUsersOptionsModel.Limit = core.Int64Ptr(int64(100)) + listUsersOptionsModel.Limit = core.Int64Ptr(int64(10)) listUsersOptionsModel.Start = core.StringPtr("testString") + listUsersOptionsModel.UserID = core.StringPtr("testString") listUsersOptionsModel.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 := userManagementService.ListUsers(listUsersOptionsModel) @@ -211,7 +214,6 @@ var _ = Describe(`UserManagementV1`, func() { }) }) }) - Describe(`ListUsers(listUsersOptions *ListUsersOptions)`, func() { listUsersPath := "/v2/accounts/testString/users" Context(`Using mock server endpoint with timeout`, func() { @@ -223,16 +225,16 @@ var _ = Describe(`UserManagementV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(listUsersPath)) Expect(req.Method).To(Equal("GET")) - Expect(req.URL.Query()["state"]).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))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["user_id"]).To(Equal([]string{"testString"})) // Sleep a short time to support a timeout test time.Sleep(100 * time.Millisecond) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"total_results": 12, "limit": 5, "first_url": "FirstURL", "next_url": "NextURL", "resources": [{"id": "ID", "iam_id": "IamID", "realm": "Realm", "user_id": "UserID", "firstname": "Firstname", "lastname": "Lastname", "state": "State", "email": "Email", "phonenumber": "Phonenumber", "altphonenumber": "Altphonenumber", "photo": "Photo", "account_id": "AccountID"}]}`) + fmt.Fprintf(res, "%s", `{"total_results": 12, "limit": 5, "first_url": "FirstURL", "next_url": "NextURL", "resources": [{"id": "ID", "iam_id": "IamID", "realm": "Realm", "user_id": "UserID", "firstname": "Firstname", "lastname": "Lastname", "state": "State", "email": "Email", "phonenumber": "Phonenumber", "altphonenumber": "Altphonenumber", "photo": "Photo", "account_id": "AccountID", "added_on": "AddedOn"}]}`) })) }) It(`Invoke ListUsers successfully with retries`, func() { @@ -247,9 +249,9 @@ var _ = Describe(`UserManagementV1`, func() { // Construct an instance of the ListUsersOptions model listUsersOptionsModel := new(usermanagementv1.ListUsersOptions) listUsersOptionsModel.AccountID = core.StringPtr("testString") - listUsersOptionsModel.State = core.StringPtr("testString") - listUsersOptionsModel.Limit = core.Int64Ptr(int64(100)) + listUsersOptionsModel.Limit = core.Int64Ptr(int64(10)) listUsersOptionsModel.Start = core.StringPtr("testString") + listUsersOptionsModel.UserID = core.StringPtr("testString") listUsersOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with a Context to test a timeout error @@ -286,13 +288,13 @@ var _ = Describe(`UserManagementV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(listUsersPath)) Expect(req.Method).To(Equal("GET")) - Expect(req.URL.Query()["state"]).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))})) Expect(req.URL.Query()["_start"]).To(Equal([]string{"testString"})) + Expect(req.URL.Query()["user_id"]).To(Equal([]string{"testString"})) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"total_results": 12, "limit": 5, "first_url": "FirstURL", "next_url": "NextURL", "resources": [{"id": "ID", "iam_id": "IamID", "realm": "Realm", "user_id": "UserID", "firstname": "Firstname", "lastname": "Lastname", "state": "State", "email": "Email", "phonenumber": "Phonenumber", "altphonenumber": "Altphonenumber", "photo": "Photo", "account_id": "AccountID"}]}`) + fmt.Fprintf(res, "%s", `{"total_results": 12, "limit": 5, "first_url": "FirstURL", "next_url": "NextURL", "resources": [{"id": "ID", "iam_id": "IamID", "realm": "Realm", "user_id": "UserID", "firstname": "Firstname", "lastname": "Lastname", "state": "State", "email": "Email", "phonenumber": "Phonenumber", "altphonenumber": "Altphonenumber", "photo": "Photo", "account_id": "AccountID", "added_on": "AddedOn"}]}`) })) }) It(`Invoke ListUsers successfully`, func() { @@ -312,9 +314,9 @@ var _ = Describe(`UserManagementV1`, func() { // Construct an instance of the ListUsersOptions model listUsersOptionsModel := new(usermanagementv1.ListUsersOptions) listUsersOptionsModel.AccountID = core.StringPtr("testString") - listUsersOptionsModel.State = core.StringPtr("testString") - listUsersOptionsModel.Limit = core.Int64Ptr(int64(100)) + listUsersOptionsModel.Limit = core.Int64Ptr(int64(10)) listUsersOptionsModel.Start = core.StringPtr("testString") + listUsersOptionsModel.UserID = core.StringPtr("testString") listUsersOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with valid options model (positive test) @@ -335,9 +337,9 @@ var _ = Describe(`UserManagementV1`, func() { // Construct an instance of the ListUsersOptions model listUsersOptionsModel := new(usermanagementv1.ListUsersOptions) listUsersOptionsModel.AccountID = core.StringPtr("testString") - listUsersOptionsModel.State = core.StringPtr("testString") - listUsersOptionsModel.Limit = core.Int64Ptr(int64(100)) + listUsersOptionsModel.Limit = core.Int64Ptr(int64(10)) listUsersOptionsModel.Start = core.StringPtr("testString") + listUsersOptionsModel.UserID = core.StringPtr("testString") listUsersOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := userManagementService.SetServiceURL("") @@ -359,10 +361,146 @@ var _ = Describe(`UserManagementV1`, 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 ListUsers successfully`, func() { + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(userManagementService).ToNot(BeNil()) + + // Construct an instance of the ListUsersOptions model + listUsersOptionsModel := new(usermanagementv1.ListUsersOptions) + listUsersOptionsModel.AccountID = core.StringPtr("testString") + listUsersOptionsModel.Limit = core.Int64Ptr(int64(10)) + listUsersOptionsModel.Start = core.StringPtr("testString") + listUsersOptionsModel.UserID = core.StringPtr("testString") + listUsersOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := userManagementService.ListUsers(listUsersOptionsModel) + 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 GetNextStart successfully`, func() { + responseObject := new(usermanagementv1.UserList) + responseObject.NextURL = core.StringPtr("ibm.com?_start=abc-123") + + value, err := responseObject.GetNextStart() + Expect(err).To(BeNil()) + Expect(value).To(Equal(core.StringPtr("abc-123"))) + }) + It(`Invoke GetNextStart without a "NextURL" property in the response`, func() { + responseObject := new(usermanagementv1.UserList) + + value, err := responseObject.GetNextStart() + Expect(err).To(BeNil()) + Expect(value).To(BeNil()) + }) + It(`Invoke GetNextStart without any query params in the "NextURL" URL`, func() { + responseObject := new(usermanagementv1.UserList) + responseObject.NextURL = core.StringPtr("ibm.com") + + value, err := responseObject.GetNextStart() + 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(listUsersPath)) + 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?_start=1","resources":[{"id":"ID","iam_id":"IamID","realm":"Realm","user_id":"UserID","firstname":"Firstname","lastname":"Lastname","state":"State","email":"Email","phonenumber":"Phonenumber","altphonenumber":"Altphonenumber","photo":"Photo","account_id":"AccountID","added_on":"AddedOn"}]}`) + } else if requestNumber == 2 { + fmt.Fprintf(res, "%s", `{"total_count":2,"limit":1,"resources":[{"id":"ID","iam_id":"IamID","realm":"Realm","user_id":"UserID","firstname":"Firstname","lastname":"Lastname","state":"State","email":"Email","phonenumber":"Phonenumber","altphonenumber":"Altphonenumber","photo":"Photo","account_id":"AccountID","added_on":"AddedOn"}]}`) + } else { + res.WriteHeader(400) + } + })) + }) + It(`Use UsersPager.GetNext successfully`, func() { + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(userManagementService).ToNot(BeNil()) + + listUsersOptionsModel := &usermanagementv1.ListUsersOptions{ + AccountID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(10)), + UserID: core.StringPtr("testString"), + } + + pager, err := userManagementService.NewUsersPager(listUsersOptionsModel) + Expect(err).To(BeNil()) + Expect(pager).ToNot(BeNil()) + + var allResults []usermanagementv1.UserProfile + 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 UsersPager.GetAll successfully`, func() { + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(userManagementService).ToNot(BeNil()) + + listUsersOptionsModel := &usermanagementv1.ListUsersOptions{ + AccountID: core.StringPtr("testString"), + Limit: core.Int64Ptr(int64(10)), + UserID: core.StringPtr("testString"), + } + + pager, err := userManagementService.NewUsersPager(listUsersOptionsModel) + 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(`InviteUsers(inviteUsersOptions *InviteUsersOptions) - Operation response error`, func() { inviteUsersPath := "/v2/accounts/testString/users" - 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() @@ -372,7 +510,7 @@ var _ = Describe(`UserManagementV1`, 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 InviteUsers with error: Operation response processing error`, func() { @@ -432,7 +570,6 @@ var _ = Describe(`UserManagementV1`, func() { }) }) }) - Describe(`InviteUsers(inviteUsersOptions *InviteUsersOptions)`, func() { inviteUsersPath := "/v2/accounts/testString/users" Context(`Using mock server endpoint with timeout`, func() { @@ -678,10 +815,71 @@ var _ = Describe(`UserManagementV1`, 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 InviteUsers successfully`, func() { + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(userManagementService).ToNot(BeNil()) + + // Construct an instance of the InviteUser model + inviteUserModel := new(usermanagementv1.InviteUser) + inviteUserModel.Email = core.StringPtr("testString") + inviteUserModel.AccountRole = core.StringPtr("testString") + + // Construct an instance of the Role model + roleModel := new(usermanagementv1.Role) + roleModel.RoleID = core.StringPtr("testString") + + // Construct an instance of the Attribute model + attributeModel := new(usermanagementv1.Attribute) + attributeModel.Name = core.StringPtr("testString") + attributeModel.Value = core.StringPtr("testString") + + // Construct an instance of the Resource model + resourceModel := new(usermanagementv1.Resource) + resourceModel.Attributes = []usermanagementv1.Attribute{*attributeModel} + + // Construct an instance of the InviteUserIamPolicy model + inviteUserIamPolicyModel := new(usermanagementv1.InviteUserIamPolicy) + inviteUserIamPolicyModel.Type = core.StringPtr("testString") + inviteUserIamPolicyModel.Roles = []usermanagementv1.Role{*roleModel} + inviteUserIamPolicyModel.Resources = []usermanagementv1.Resource{*resourceModel} + + // Construct an instance of the InviteUsersOptions model + inviteUsersOptionsModel := new(usermanagementv1.InviteUsersOptions) + inviteUsersOptionsModel.AccountID = core.StringPtr("testString") + inviteUsersOptionsModel.Users = []usermanagementv1.InviteUser{*inviteUserModel} + inviteUsersOptionsModel.IamPolicy = []usermanagementv1.InviteUserIamPolicy{*inviteUserIamPolicyModel} + inviteUsersOptionsModel.AccessGroups = []string{"testString"} + inviteUsersOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := userManagementService.InviteUsers(inviteUsersOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) }) Describe(`GetUserProfile(getUserProfileOptions *GetUserProfileOptions) - Operation response error`, func() { getUserProfilePath := "/v2/accounts/testString/users/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() @@ -689,9 +887,10 @@ var _ = Describe(`UserManagementV1`, func() { // Verify the contents of the request Expect(req.URL.EscapedPath()).To(Equal(getUserProfilePath)) Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["include_activity"]).To(Equal([]string{"testString"})) 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 GetUserProfile with error: Operation response processing error`, func() { @@ -706,6 +905,7 @@ var _ = Describe(`UserManagementV1`, func() { getUserProfileOptionsModel := new(usermanagementv1.GetUserProfileOptions) getUserProfileOptionsModel.AccountID = core.StringPtr("testString") getUserProfileOptionsModel.IamID = core.StringPtr("testString") + getUserProfileOptionsModel.IncludeActivity = core.StringPtr("testString") getUserProfileOptionsModel.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 := userManagementService.GetUserProfile(getUserProfileOptionsModel) @@ -725,7 +925,6 @@ var _ = Describe(`UserManagementV1`, func() { }) }) }) - Describe(`GetUserProfile(getUserProfileOptions *GetUserProfileOptions)`, func() { getUserProfilePath := "/v2/accounts/testString/users/testString" Context(`Using mock server endpoint with timeout`, func() { @@ -737,13 +936,14 @@ var _ = Describe(`UserManagementV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(getUserProfilePath)) Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["include_activity"]).To(Equal([]string{"testString"})) // Sleep a short time to support a timeout test time.Sleep(100 * time.Millisecond) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "iam_id": "IamID", "realm": "Realm", "user_id": "UserID", "firstname": "Firstname", "lastname": "Lastname", "state": "State", "email": "Email", "phonenumber": "Phonenumber", "altphonenumber": "Altphonenumber", "photo": "Photo", "account_id": "AccountID"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "iam_id": "IamID", "realm": "Realm", "user_id": "UserID", "firstname": "Firstname", "lastname": "Lastname", "state": "State", "email": "Email", "phonenumber": "Phonenumber", "altphonenumber": "Altphonenumber", "photo": "Photo", "account_id": "AccountID", "added_on": "AddedOn"}`) })) }) It(`Invoke GetUserProfile successfully with retries`, func() { @@ -759,6 +959,7 @@ var _ = Describe(`UserManagementV1`, func() { getUserProfileOptionsModel := new(usermanagementv1.GetUserProfileOptions) getUserProfileOptionsModel.AccountID = core.StringPtr("testString") getUserProfileOptionsModel.IamID = core.StringPtr("testString") + getUserProfileOptionsModel.IncludeActivity = core.StringPtr("testString") getUserProfileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with a Context to test a timeout error @@ -795,10 +996,11 @@ var _ = Describe(`UserManagementV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(getUserProfilePath)) Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["include_activity"]).To(Equal([]string{"testString"})) // Set mock response res.Header().Set("Content-type", "application/json") res.WriteHeader(200) - fmt.Fprintf(res, "%s", `{"id": "ID", "iam_id": "IamID", "realm": "Realm", "user_id": "UserID", "firstname": "Firstname", "lastname": "Lastname", "state": "State", "email": "Email", "phonenumber": "Phonenumber", "altphonenumber": "Altphonenumber", "photo": "Photo", "account_id": "AccountID"}`) + fmt.Fprintf(res, "%s", `{"id": "ID", "iam_id": "IamID", "realm": "Realm", "user_id": "UserID", "firstname": "Firstname", "lastname": "Lastname", "state": "State", "email": "Email", "phonenumber": "Phonenumber", "altphonenumber": "Altphonenumber", "photo": "Photo", "account_id": "AccountID", "added_on": "AddedOn"}`) })) }) It(`Invoke GetUserProfile successfully`, func() { @@ -819,6 +1021,7 @@ var _ = Describe(`UserManagementV1`, func() { getUserProfileOptionsModel := new(usermanagementv1.GetUserProfileOptions) getUserProfileOptionsModel.AccountID = core.StringPtr("testString") getUserProfileOptionsModel.IamID = core.StringPtr("testString") + getUserProfileOptionsModel.IncludeActivity = core.StringPtr("testString") getUserProfileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with valid options model (positive test) @@ -840,6 +1043,7 @@ var _ = Describe(`UserManagementV1`, func() { getUserProfileOptionsModel := new(usermanagementv1.GetUserProfileOptions) getUserProfileOptionsModel.AccountID = core.StringPtr("testString") getUserProfileOptionsModel.IamID = core.StringPtr("testString") + getUserProfileOptionsModel.IncludeActivity = core.StringPtr("testString") getUserProfileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := userManagementService.SetServiceURL("") @@ -861,8 +1065,43 @@ var _ = Describe(`UserManagementV1`, 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 GetUserProfile successfully`, func() { + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(userManagementService).ToNot(BeNil()) + + // Construct an instance of the GetUserProfileOptions model + getUserProfileOptionsModel := new(usermanagementv1.GetUserProfileOptions) + getUserProfileOptionsModel.AccountID = core.StringPtr("testString") + getUserProfileOptionsModel.IamID = core.StringPtr("testString") + getUserProfileOptionsModel.IncludeActivity = core.StringPtr("testString") + getUserProfileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := userManagementService.GetUserProfile(getUserProfileOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) Describe(`UpdateUserProfile(updateUserProfileOptions *UpdateUserProfileOptions)`, func() { updateUserProfilePath := "/v2/accounts/testString/users/testString" Context(`Using mock server endpoint`, func() { @@ -890,6 +1129,7 @@ var _ = Describe(`UserManagementV1`, func() { } fmt.Fprintf(GinkgoWriter, " Request body: %s", bodyBuf.String()) + Expect(req.URL.Query()["include_activity"]).To(Equal([]string{"testString"})) res.WriteHeader(204) })) }) @@ -917,6 +1157,7 @@ var _ = Describe(`UserManagementV1`, func() { updateUserProfileOptionsModel.Phonenumber = core.StringPtr("testString") updateUserProfileOptionsModel.Altphonenumber = core.StringPtr("testString") updateUserProfileOptionsModel.Photo = core.StringPtr("testString") + updateUserProfileOptionsModel.IncludeActivity = core.StringPtr("testString") updateUserProfileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with valid options model (positive test) @@ -943,6 +1184,7 @@ var _ = Describe(`UserManagementV1`, func() { updateUserProfileOptionsModel.Phonenumber = core.StringPtr("testString") updateUserProfileOptionsModel.Altphonenumber = core.StringPtr("testString") updateUserProfileOptionsModel.Photo = core.StringPtr("testString") + updateUserProfileOptionsModel.IncludeActivity = core.StringPtr("testString") updateUserProfileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := userManagementService.SetServiceURL("") @@ -963,7 +1205,6 @@ var _ = Describe(`UserManagementV1`, func() { }) }) }) - Describe(`RemoveUser(removeUserOptions *RemoveUserOptions)`, func() { removeUserPath := "/v2/accounts/testString/users/testString" Context(`Using mock server endpoint`, func() { @@ -975,6 +1216,7 @@ var _ = Describe(`UserManagementV1`, func() { Expect(req.URL.EscapedPath()).To(Equal(removeUserPath)) Expect(req.Method).To(Equal("DELETE")) + Expect(req.URL.Query()["include_activity"]).To(Equal([]string{"testString"})) res.WriteHeader(204) })) }) @@ -995,6 +1237,7 @@ var _ = Describe(`UserManagementV1`, func() { removeUserOptionsModel := new(usermanagementv1.RemoveUserOptions) removeUserOptionsModel.AccountID = core.StringPtr("testString") removeUserOptionsModel.IamID = core.StringPtr("testString") + removeUserOptionsModel.IncludeActivity = core.StringPtr("testString") removeUserOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with valid options model (positive test) @@ -1014,6 +1257,7 @@ var _ = Describe(`UserManagementV1`, func() { removeUserOptionsModel := new(usermanagementv1.RemoveUserOptions) removeUserOptionsModel.AccountID = core.StringPtr("testString") removeUserOptionsModel.IamID = core.StringPtr("testString") + removeUserOptionsModel.IncludeActivity = core.StringPtr("testString") removeUserOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := userManagementService.SetServiceURL("") @@ -1034,134 +1278,157 @@ var _ = Describe(`UserManagementV1`, func() { }) }) }) - Describe(`Service constructor tests`, func() { - It(`Instantiate service client`, func() { - userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ - Authenticator: &core.NoAuthAuthenticator{}, - }) - Expect(userManagementService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - }) - It(`Instantiate service client with error: Invalid URL`, func() { - userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ - URL: "{BAD_URL_STRING", - }) - Expect(userManagementService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - }) - It(`Instantiate service client with error: Invalid Auth`, func() { - userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ - URL: "https://usermanagementv1/api", - Authenticator: &core.BasicAuthenticator{ - Username: "", - Password: "", - }, - }) - Expect(userManagementService).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{ - "USER_MANAGEMENT_URL": "https://usermanagementv1/api", - "USER_MANAGEMENT_AUTH_TYPE": "noauth", - } + Describe(`Accept(acceptOptions *AcceptOptions)`, func() { + acceptPath := "/v2/users/accept" + 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) - userManagementService, serviceErr := usermanagementv1.NewUserManagementV1UsingExternalConfig(&usermanagementv1.UserManagementV1Options{}) - Expect(userManagementService).ToNot(BeNil()) - Expect(serviceErr).To(BeNil()) - ClearTestEnvironment(testEnvironment) + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(acceptPath)) + Expect(req.Method).To(Equal("POST")) - clone := userManagementService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != userManagementService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(userManagementService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(userManagementService.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) - userManagementService, serviceErr := usermanagementv1.NewUserManagementV1UsingExternalConfig(&usermanagementv1.UserManagementV1Options{ - URL: "https://testService/api", + It(`Invoke Accept successfully`, func() { + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, }) - Expect(userManagementService).ToNot(BeNil()) Expect(serviceErr).To(BeNil()) - Expect(userManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) - ClearTestEnvironment(testEnvironment) + Expect(userManagementService).ToNot(BeNil()) - clone := userManagementService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != userManagementService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(userManagementService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(userManagementService.Service.Options.Authenticator)) + // Invoke operation with nil options model (negative test) + response, operationErr := userManagementService.Accept(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the AcceptOptions model + acceptOptionsModel := new(usermanagementv1.AcceptOptions) + acceptOptionsModel.AccountID = core.StringPtr("testString") + acceptOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = userManagementService.Accept(acceptOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) }) - It(`Create service client using external config and set url programatically successfully`, func() { - SetTestEnvironment(testEnvironment) - userManagementService, serviceErr := usermanagementv1.NewUserManagementV1UsingExternalConfig(&usermanagementv1.UserManagementV1Options{}) - err := userManagementService.SetServiceURL("https://testService/api") - Expect(err).To(BeNil()) - Expect(userManagementService).ToNot(BeNil()) + It(`Invoke Accept with error: Operation request error`, func() { + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) Expect(serviceErr).To(BeNil()) - Expect(userManagementService.Service.GetServiceURL()).To(Equal("https://testService/api")) - ClearTestEnvironment(testEnvironment) + Expect(userManagementService).ToNot(BeNil()) - clone := userManagementService.Clone() - Expect(clone).ToNot(BeNil()) - Expect(clone.Service != userManagementService.Service).To(BeTrue()) - Expect(clone.GetServiceURL()).To(Equal(userManagementService.GetServiceURL())) - Expect(clone.Service.Options.Authenticator).To(Equal(userManagementService.Service.Options.Authenticator)) + // Construct an instance of the AcceptOptions model + acceptOptionsModel := new(usermanagementv1.AcceptOptions) + acceptOptionsModel.AccountID = core.StringPtr("testString") + acceptOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := userManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := userManagementService.Accept(acceptOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() }) }) - 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{ - "USER_MANAGEMENT_URL": "https://usermanagementv1/api", - "USER_MANAGEMENT_AUTH_TYPE": "someOtherAuth", - } + }) + Describe(`V3RemoveUser(v3RemoveUserOptions *V3RemoveUserOptions)`, func() { + v3RemoveUserPath := "/v3/accounts/testString/users/testString" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() - SetTestEnvironment(testEnvironment) - userManagementService, serviceErr := usermanagementv1.NewUserManagementV1UsingExternalConfig(&usermanagementv1.UserManagementV1Options{}) + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(v3RemoveUserPath)) + Expect(req.Method).To(Equal("DELETE")) - It(`Instantiate service client with error`, func() { - Expect(userManagementService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - ClearTestEnvironment(testEnvironment) + res.WriteHeader(202) + })) }) - }) - 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{ - "USER_MANAGEMENT_AUTH_TYPE": "NOAuth", - } + It(`Invoke V3RemoveUser successfully`, func() { + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(userManagementService).ToNot(BeNil()) - SetTestEnvironment(testEnvironment) - userManagementService, serviceErr := usermanagementv1.NewUserManagementV1UsingExternalConfig(&usermanagementv1.UserManagementV1Options{ - URL: "{BAD_URL_STRING", + // Invoke operation with nil options model (negative test) + response, operationErr := userManagementService.V3RemoveUser(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + + // Construct an instance of the V3RemoveUserOptions model + v3RemoveUserOptionsModel := new(usermanagementv1.V3RemoveUserOptions) + v3RemoveUserOptionsModel.AccountID = core.StringPtr("testString") + v3RemoveUserOptionsModel.IamID = core.StringPtr("testString") + v3RemoveUserOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + response, operationErr = userManagementService.V3RemoveUser(v3RemoveUserOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) }) + It(`Invoke V3RemoveUser with error: Operation validation and request error`, func() { + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(userManagementService).ToNot(BeNil()) - It(`Instantiate service client with error`, func() { - Expect(userManagementService).To(BeNil()) - Expect(serviceErr).ToNot(BeNil()) - ClearTestEnvironment(testEnvironment) + // Construct an instance of the V3RemoveUserOptions model + v3RemoveUserOptionsModel := new(usermanagementv1.V3RemoveUserOptions) + v3RemoveUserOptionsModel.AccountID = core.StringPtr("testString") + v3RemoveUserOptionsModel.IamID = core.StringPtr("testString") + v3RemoveUserOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := userManagementService.SetServiceURL("") + Expect(err).To(BeNil()) + response, operationErr := userManagementService.V3RemoveUser(v3RemoveUserOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + // Construct a second instance of the V3RemoveUserOptions model with no property values + v3RemoveUserOptionsModelNew := new(usermanagementv1.V3RemoveUserOptions) + // Invoke operation with invalid model (negative test) + response, operationErr = userManagementService.V3RemoveUser(v3RemoveUserOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() }) - }) - }) - Describe(`Regional endpoint tests`, func() { - It(`GetServiceURLForRegion(region string)`, func() { - var url string - var err error - url, err = usermanagementv1.GetServiceURLForRegion("INVALID_REGION") - Expect(url).To(BeEmpty()) - Expect(err).ToNot(BeNil()) - fmt.Fprintf(GinkgoWriter, "Expected error: %s\n", err.Error()) }) }) Describe(`GetUserSettings(getUserSettingsOptions *GetUserSettingsOptions) - Operation response error`, func() { getUserSettingsPath := "/v2/accounts/testString/users/testString/settings" - 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() @@ -1171,7 +1438,7 @@ var _ = Describe(`UserManagementV1`, 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 GetUserSettings with error: Operation response processing error`, func() { @@ -1205,7 +1472,6 @@ var _ = Describe(`UserManagementV1`, func() { }) }) }) - Describe(`GetUserSettings(getUserSettingsOptions *GetUserSettingsOptions)`, func() { getUserSettingsPath := "/v2/accounts/testString/users/testString/settings" Context(`Using mock server endpoint with timeout`, func() { @@ -1341,8 +1607,42 @@ var _ = Describe(`UserManagementV1`, 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 GetUserSettings successfully`, func() { + userManagementService, serviceErr := usermanagementv1.NewUserManagementV1(&usermanagementv1.UserManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(userManagementService).ToNot(BeNil()) + // Construct an instance of the GetUserSettingsOptions model + getUserSettingsOptionsModel := new(usermanagementv1.GetUserSettingsOptions) + getUserSettingsOptionsModel.AccountID = core.StringPtr("testString") + getUserSettingsOptionsModel.IamID = core.StringPtr("testString") + getUserSettingsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation + result, response, operationErr := userManagementService.GetUserSettings(getUserSettingsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + + // Verify a nil result + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) Describe(`UpdateUserSettings(updateUserSettingsOptions *UpdateUserSettingsOptions)`, func() { updateUserSettingsPath := "/v2/accounts/testString/users/testString/settings" Context(`Using mock server endpoint`, func() { @@ -1443,6 +1743,15 @@ var _ = Describe(`UserManagementV1`, func() { URL: "http://usermanagementv1modelgenerator.com", Authenticator: &core.NoAuthAuthenticator{}, }) + It(`Invoke NewAcceptOptions successfully`, func() { + // Construct an instance of the AcceptOptions model + acceptOptionsModel := userManagementService.NewAcceptOptions() + acceptOptionsModel.SetAccountID("testString") + acceptOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(acceptOptionsModel).ToNot(BeNil()) + Expect(acceptOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) + Expect(acceptOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewGetUserProfileOptions successfully`, func() { // Construct an instance of the GetUserProfileOptions model accountID := "testString" @@ -1450,10 +1759,12 @@ var _ = Describe(`UserManagementV1`, func() { getUserProfileOptionsModel := userManagementService.NewGetUserProfileOptions(accountID, iamID) getUserProfileOptionsModel.SetAccountID("testString") getUserProfileOptionsModel.SetIamID("testString") + getUserProfileOptionsModel.SetIncludeActivity("testString") getUserProfileOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(getUserProfileOptionsModel).ToNot(BeNil()) Expect(getUserProfileOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) Expect(getUserProfileOptionsModel.IamID).To(Equal(core.StringPtr("testString"))) + Expect(getUserProfileOptionsModel.IncludeActivity).To(Equal(core.StringPtr("testString"))) Expect(getUserProfileOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewGetUserSettingsOptions successfully`, func() { @@ -1528,15 +1839,15 @@ var _ = Describe(`UserManagementV1`, func() { accountID := "testString" listUsersOptionsModel := userManagementService.NewListUsersOptions(accountID) listUsersOptionsModel.SetAccountID("testString") - listUsersOptionsModel.SetState("testString") - listUsersOptionsModel.SetLimit(int64(100)) + listUsersOptionsModel.SetLimit(int64(10)) listUsersOptionsModel.SetStart("testString") + listUsersOptionsModel.SetUserID("testString") listUsersOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(listUsersOptionsModel).ToNot(BeNil()) Expect(listUsersOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) - Expect(listUsersOptionsModel.State).To(Equal(core.StringPtr("testString"))) - Expect(listUsersOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(100)))) + Expect(listUsersOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(10)))) Expect(listUsersOptionsModel.Start).To(Equal(core.StringPtr("testString"))) + Expect(listUsersOptionsModel.UserID).To(Equal(core.StringPtr("testString"))) Expect(listUsersOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewRemoveUserOptions successfully`, func() { @@ -1546,10 +1857,12 @@ var _ = Describe(`UserManagementV1`, func() { removeUserOptionsModel := userManagementService.NewRemoveUserOptions(accountID, iamID) removeUserOptionsModel.SetAccountID("testString") removeUserOptionsModel.SetIamID("testString") + removeUserOptionsModel.SetIncludeActivity("testString") removeUserOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(removeUserOptionsModel).ToNot(BeNil()) Expect(removeUserOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) Expect(removeUserOptionsModel.IamID).To(Equal(core.StringPtr("testString"))) + Expect(removeUserOptionsModel.IncludeActivity).To(Equal(core.StringPtr("testString"))) Expect(removeUserOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewUpdateUserProfileOptions successfully`, func() { @@ -1566,6 +1879,7 @@ var _ = Describe(`UserManagementV1`, func() { updateUserProfileOptionsModel.SetPhonenumber("testString") updateUserProfileOptionsModel.SetAltphonenumber("testString") updateUserProfileOptionsModel.SetPhoto("testString") + updateUserProfileOptionsModel.SetIncludeActivity("testString") updateUserProfileOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(updateUserProfileOptionsModel).ToNot(BeNil()) Expect(updateUserProfileOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) @@ -1577,6 +1891,7 @@ var _ = Describe(`UserManagementV1`, func() { Expect(updateUserProfileOptionsModel.Phonenumber).To(Equal(core.StringPtr("testString"))) Expect(updateUserProfileOptionsModel.Altphonenumber).To(Equal(core.StringPtr("testString"))) Expect(updateUserProfileOptionsModel.Photo).To(Equal(core.StringPtr("testString"))) + Expect(updateUserProfileOptionsModel.IncludeActivity).To(Equal(core.StringPtr("testString"))) Expect(updateUserProfileOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewUpdateUserSettingsOptions successfully`, func() { @@ -1600,10 +1915,23 @@ var _ = Describe(`UserManagementV1`, func() { Expect(updateUserSettingsOptionsModel.SelfManage).To(Equal(core.BoolPtr(true))) Expect(updateUserSettingsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) + It(`Invoke NewV3RemoveUserOptions successfully`, func() { + // Construct an instance of the V3RemoveUserOptions model + accountID := "testString" + iamID := "testString" + v3RemoveUserOptionsModel := userManagementService.NewV3RemoveUserOptions(accountID, iamID) + v3RemoveUserOptionsModel.SetAccountID("testString") + v3RemoveUserOptionsModel.SetIamID("testString") + v3RemoveUserOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(v3RemoveUserOptionsModel).ToNot(BeNil()) + Expect(v3RemoveUserOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) + Expect(v3RemoveUserOptionsModel.IamID).To(Equal(core.StringPtr("testString"))) + Expect(v3RemoveUserOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) It(`Invoke NewInviteUserIamPolicy successfully`, func() { typeVar := "testString" - model, err := userManagementService.NewInviteUserIamPolicy(typeVar) - Expect(model).ToNot(BeNil()) + _model, err := userManagementService.NewInviteUserIamPolicy(typeVar) + Expect(_model).ToNot(BeNil()) Expect(err).To(BeNil()) }) }) @@ -1622,11 +1950,11 @@ var _ = Describe(`UserManagementV1`, 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()) }) }) @@ -1651,13 +1979,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 }