@@ -3,6 +3,7 @@ package github
33import (
44 "encoding/base64"
55 "fmt"
6+ "reflect"
67 "strings"
78 "testing"
89
@@ -553,3 +554,52 @@ func TestGithubActionsSecretIssue964Solution(t *testing.T) {
553554 t .Logf ("SUCCESS: Issue #964 solved - secret with destroy_on_drift=false does not get recreated on external changes" )
554555 })
555556}
557+
558+ func testResourceGithubActionsSecretInstanceStateDataV0 () map [string ]any {
559+ return map [string ]any {
560+ "id" : "test-secret" ,
561+ "repository" : "test-repo" ,
562+ "secret_name" : "test-secret" ,
563+ "created_at" : "2023-01-01T00:00:00Z" ,
564+ "updated_at" : "2023-01-01T00:00:00Z" ,
565+ "plaintext_value" : "secret-value" ,
566+ }
567+ }
568+
569+ func testResourceGithubActionsSecretInstanceStateDataV0_WithDrift () map [string ]any {
570+ v0 := testResourceGithubActionsSecretInstanceStateDataV0 ()
571+ v0 ["destroy_on_drift" ] = false
572+ return v0
573+ }
574+
575+ func testResourceGithubActionsSecretInstanceStateDataV1 () map [string ]any {
576+ v0 := testResourceGithubActionsSecretInstanceStateDataV0 ()
577+ v0 ["destroy_on_drift" ] = true
578+ return v0
579+ }
580+
581+ func TestGithub_MigrateActionsSecretStateV0toV1 (t * testing.T ) {
582+ t .Run ("without destroy_on_drift" , func (t * testing.T ) {
583+ expected := testResourceGithubActionsSecretInstanceStateDataV1 ()
584+ actual , err := resourceGithubActionsSecretInstanceStateUpgradeV0 (t .Context (), testResourceGithubActionsSecretInstanceStateDataV0 (), nil )
585+ if err != nil {
586+ t .Fatalf ("error migrating state: %s" , err )
587+ }
588+
589+ if ! reflect .DeepEqual (expected , actual ) {
590+ t .Fatalf ("\n \n expected:\n \n %#v\n \n got:\n \n %#v\n \n " , expected , actual )
591+ }
592+ })
593+
594+ t .Run ("with destroy_on_drift" , func (t * testing.T ) {
595+ expected := testResourceGithubActionsSecretInstanceStateDataV0_WithDrift ()
596+ actual , err := resourceGithubActionsSecretInstanceStateUpgradeV0 (t .Context (), testResourceGithubActionsSecretInstanceStateDataV0_WithDrift (), nil )
597+ if err != nil {
598+ t .Fatalf ("error migrating state: %s" , err )
599+ }
600+
601+ if ! reflect .DeepEqual (expected , actual ) {
602+ t .Fatalf ("\n \n expected:\n \n %#v\n \n got:\n \n %#v\n \n " , expected , actual )
603+ }
604+ })
605+ }
0 commit comments