From 2512bf08ddeb3bbcba74dce9f643a8116cf31cf2 Mon Sep 17 00:00:00 2001 From: Siddhu Warrier Date: Wed, 30 Aug 2023 12:34:22 +0100 Subject: [PATCH] fix(LH-69113): Use queueTriggerState instead of state when updating ASA credentials (#27) * fix(LH-69113): Use queueTriggerState instead of state when updating ASA credentials Using state to trigger a state machine can cause errors if there's already a state machine running. We should be using queueTriggerState instead. * test(LH-69113): Fix broken tests --- client/device/asa/asaconfig/update.go | 9 +++++---- client/device/asa/asaconfig/update_test.go | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/client/device/asa/asaconfig/update.go b/client/device/asa/asaconfig/update.go index 996a4e8e..fd4fe5ce 100644 --- a/client/device/asa/asaconfig/update.go +++ b/client/device/asa/asaconfig/update.go @@ -3,9 +3,10 @@ package asaconfig import ( "context" "encoding/json" + "strings" + "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/crypto" "github.com/CiscoDevnet/terraform-provider-cdo/go-client/model" - "strings" "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http" "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/url" @@ -129,7 +130,7 @@ func makeUpdateCredentialsReqBody(isWaitForUserToUpdateCreds bool, creds []byte) } } else { return &updateCredentialsBodyWithState{ - State: "WAIT_FOR_USER_TO_UPDATE_CREDS", + QueueTriggerState: "WAIT_FOR_USER_TO_UPDATE_CREDS", SmContext: SmContext{ Credentials: string(creds), }, @@ -143,8 +144,8 @@ type updateBody struct { } type updateCredentialsBodyWithState struct { - State string `json:"state"` - SmContext SmContext `json:"stateMachineContext"` + QueueTriggerState string `json:"queueTriggerState"` + SmContext SmContext `json:"stateMachineContext"` } type updateCredentialsBody struct { diff --git a/client/device/asa/asaconfig/update_test.go b/client/device/asa/asaconfig/update_test.go index 0f8053d7..6ede699a 100644 --- a/client/device/asa/asaconfig/update_test.go +++ b/client/device/asa/asaconfig/update_test.go @@ -5,13 +5,14 @@ import ( "crypto/rand" "crypto/rsa" "fmt" - "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/crypto" - "github.com/CiscoDevnet/terraform-provider-cdo/go-client/model" - "github.com/stretchr/testify/assert" "net/http" "testing" "time" + "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/crypto" + "github.com/CiscoDevnet/terraform-provider-cdo/go-client/model" + "github.com/stretchr/testify/assert" + internalHttp "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/http" "github.com/CiscoDevnet/terraform-provider-cdo/go-client/internal/jsonutil" "github.com/jarcoal/httpmock" @@ -205,7 +206,7 @@ func TestAsaConfigUpdateCredentials(t *testing.T) { assert.Nil(t, err) expectedBody := updateCredentialsBodyWithState{ - State: "WAIT_FOR_USER_TO_UPDATE_CREDS", + QueueTriggerState: "WAIT_FOR_USER_TO_UPDATE_CREDS", SmContext: SmContext{ Credentials: fmt.Sprintf(`{"username":"%s","password":"%s"}`, input.Username, input.Password), }, @@ -246,7 +247,7 @@ func TestAsaConfigUpdateCredentials(t *testing.T) { assert.Nil(t, err) expectedState := "WAIT_FOR_USER_TO_UPDATE_CREDS" - assert.Equal(t, requestBody.State, expectedState) + assert.Equal(t, requestBody.QueueTriggerState, expectedState) credentials, err := jsonutil.UnmarshalStruct[model.Credentials]([]byte(requestBody.SmContext.Credentials)) assert.Nil(t, err)