Skip to content

Commit

Permalink
fix(Example Service): re-gen service after traits schema change (#250)
Browse files Browse the repository at this point in the history
Signed-off-by: namratabhadauriya <[email protected]>
  • Loading branch information
namratabhadauriya authored Apr 27, 2023
1 parent e698d62 commit 92d698c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
23 changes: 21 additions & 2 deletions enterprisemanagementv1/enterprise_management_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ type CreateAccountOptions struct {

// The traits object can be used to opt-out of Multi-Factor Authentication setting when creating a child account in the
// enterprise. This is an optional field.
Traits map[string]interface{} `json:"traits,omitempty"`
Traits *CreateAccountRequestTraits `json:"traits,omitempty"`

// Allows users to set headers on API requests
Headers map[string]string
Expand Down Expand Up @@ -1520,7 +1520,7 @@ func (_options *CreateAccountOptions) SetOwnerIamID(ownerIamID string) *CreateAc
}

// SetTraits : Allow user to set Traits
func (_options *CreateAccountOptions) SetTraits(traits map[string]interface{}) *CreateAccountOptions {
func (_options *CreateAccountOptions) SetTraits(traits *CreateAccountRequestTraits) *CreateAccountOptions {
_options.Traits = traits
return _options
}
Expand All @@ -1531,6 +1531,25 @@ func (options *CreateAccountOptions) SetHeaders(param map[string]string) *Create
return options
}

// CreateAccountRequestTraits : The traits object can be used to opt-out of Multi-Factor Authentication setting when creating a child account in the
// enterprise. This is an optional field.
type CreateAccountRequestTraits struct {
// By default MFA will be set on the account. To opt out, pass the traits object with the mfa field set to empty
// string.
Mfa *string `json:"mfa,omitempty"`
}

// UnmarshalCreateAccountRequestTraits unmarshals an instance of CreateAccountRequestTraits from the specified map of raw messages.
func UnmarshalCreateAccountRequestTraits(m map[string]json.RawMessage, result interface{}) (err error) {
obj := new(CreateAccountRequestTraits)
err = core.UnmarshalPrimitive(m, "mfa", &obj.Mfa)
if err != nil {
return
}
reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj))
return
}

// CreateAccountResponse : A newly-created account.
type CreateAccountResponse struct {
// The ID of the account entity that was created.
Expand Down
40 changes: 33 additions & 7 deletions enterprisemanagementv1/enterprise_management_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,12 +1178,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() {
Expect(serviceErr).To(BeNil())
Expect(enterpriseManagementService).ToNot(BeNil())

// Construct an instance of the CreateAccountRequestTraits model
createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits)
createAccountRequestTraitsModel.Mfa = core.StringPtr("testString")

// Construct an instance of the CreateAccountOptions model
createAccountOptionsModel := new(enterprisemanagementv1.CreateAccountOptions)
createAccountOptionsModel.Parent = core.StringPtr("testString")
createAccountOptionsModel.Name = core.StringPtr("testString")
createAccountOptionsModel.OwnerIamID = core.StringPtr("testString")
createAccountOptionsModel.Traits = map[string]interface{}{"anyKey": "anyValue"}
createAccountOptionsModel.Traits = createAccountRequestTraitsModel
createAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
// Expect response parsing to fail since we are receiving a text/plain response
result, response, operationErr := enterpriseManagementService.CreateAccount(createAccountOptionsModel)
Expand Down Expand Up @@ -1248,12 +1252,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() {
Expect(enterpriseManagementService).ToNot(BeNil())
enterpriseManagementService.EnableRetries(0, 0)

// Construct an instance of the CreateAccountRequestTraits model
createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits)
createAccountRequestTraitsModel.Mfa = core.StringPtr("testString")

// Construct an instance of the CreateAccountOptions model
createAccountOptionsModel := new(enterprisemanagementv1.CreateAccountOptions)
createAccountOptionsModel.Parent = core.StringPtr("testString")
createAccountOptionsModel.Name = core.StringPtr("testString")
createAccountOptionsModel.OwnerIamID = core.StringPtr("testString")
createAccountOptionsModel.Traits = map[string]interface{}{"anyKey": "anyValue"}
createAccountOptionsModel.Traits = createAccountRequestTraitsModel
createAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation with a Context to test a timeout error
Expand Down Expand Up @@ -1326,12 +1334,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() {
Expect(response).To(BeNil())
Expect(result).To(BeNil())

// Construct an instance of the CreateAccountRequestTraits model
createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits)
createAccountRequestTraitsModel.Mfa = core.StringPtr("testString")

// Construct an instance of the CreateAccountOptions model
createAccountOptionsModel := new(enterprisemanagementv1.CreateAccountOptions)
createAccountOptionsModel.Parent = core.StringPtr("testString")
createAccountOptionsModel.Name = core.StringPtr("testString")
createAccountOptionsModel.OwnerIamID = core.StringPtr("testString")
createAccountOptionsModel.Traits = map[string]interface{}{"anyKey": "anyValue"}
createAccountOptionsModel.Traits = createAccountRequestTraitsModel
createAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation with valid options model (positive test)
Expand All @@ -1349,12 +1361,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() {
Expect(serviceErr).To(BeNil())
Expect(enterpriseManagementService).ToNot(BeNil())

// Construct an instance of the CreateAccountRequestTraits model
createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits)
createAccountRequestTraitsModel.Mfa = core.StringPtr("testString")

// Construct an instance of the CreateAccountOptions model
createAccountOptionsModel := new(enterprisemanagementv1.CreateAccountOptions)
createAccountOptionsModel.Parent = core.StringPtr("testString")
createAccountOptionsModel.Name = core.StringPtr("testString")
createAccountOptionsModel.OwnerIamID = core.StringPtr("testString")
createAccountOptionsModel.Traits = map[string]interface{}{"anyKey": "anyValue"}
createAccountOptionsModel.Traits = createAccountRequestTraitsModel
createAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}
// Invoke operation with empty URL (negative test)
err := enterpriseManagementService.SetServiceURL("")
Expand Down Expand Up @@ -1393,12 +1409,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() {
Expect(serviceErr).To(BeNil())
Expect(enterpriseManagementService).ToNot(BeNil())

// Construct an instance of the CreateAccountRequestTraits model
createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits)
createAccountRequestTraitsModel.Mfa = core.StringPtr("testString")

// Construct an instance of the CreateAccountOptions model
createAccountOptionsModel := new(enterprisemanagementv1.CreateAccountOptions)
createAccountOptionsModel.Parent = core.StringPtr("testString")
createAccountOptionsModel.Name = core.StringPtr("testString")
createAccountOptionsModel.OwnerIamID = core.StringPtr("testString")
createAccountOptionsModel.Traits = map[string]interface{}{"anyKey": "anyValue"}
createAccountOptionsModel.Traits = createAccountRequestTraitsModel
createAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"}

// Invoke operation
Expand Down Expand Up @@ -3127,6 +3147,12 @@ var _ = Describe(`EnterpriseManagementV1`, func() {
Expect(createAccountGroupOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"}))
})
It(`Invoke NewCreateAccountOptions successfully`, func() {
// Construct an instance of the CreateAccountRequestTraits model
createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits)
Expect(createAccountRequestTraitsModel).ToNot(BeNil())
createAccountRequestTraitsModel.Mfa = core.StringPtr("testString")
Expect(createAccountRequestTraitsModel.Mfa).To(Equal(core.StringPtr("testString")))

// Construct an instance of the CreateAccountOptions model
createAccountOptionsParent := "testString"
createAccountOptionsName := "testString"
Expand All @@ -3135,13 +3161,13 @@ var _ = Describe(`EnterpriseManagementV1`, func() {
createAccountOptionsModel.SetParent("testString")
createAccountOptionsModel.SetName("testString")
createAccountOptionsModel.SetOwnerIamID("testString")
createAccountOptionsModel.SetTraits(map[string]interface{}{"anyKey": "anyValue"})
createAccountOptionsModel.SetTraits(createAccountRequestTraitsModel)
createAccountOptionsModel.SetHeaders(map[string]string{"foo": "bar"})
Expect(createAccountOptionsModel).ToNot(BeNil())
Expect(createAccountOptionsModel.Parent).To(Equal(core.StringPtr("testString")))
Expect(createAccountOptionsModel.Name).To(Equal(core.StringPtr("testString")))
Expect(createAccountOptionsModel.OwnerIamID).To(Equal(core.StringPtr("testString")))
Expect(createAccountOptionsModel.Traits).To(Equal(map[string]interface{}{"anyKey": "anyValue"}))
Expect(createAccountOptionsModel.Traits).To(Equal(createAccountRequestTraitsModel))
Expect(createAccountOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"}))
})
It(`Invoke NewCreateEnterpriseOptions successfully`, func() {
Expand Down

0 comments on commit 92d698c

Please sign in to comment.