-
Notifications
You must be signed in to change notification settings - Fork 960
Expand file tree
/
Copy pathmigrate_github_actions_secret_test.go
More file actions
69 lines (61 loc) · 1.95 KB
/
migrate_github_actions_secret_test.go
File metadata and controls
69 lines (61 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package github
import (
"reflect"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func TestMigrateGithubActionsSecretStateV0toV1(t *testing.T) {
// Secret without destroy_on_drift should get default value
oldAttributes := map[string]string{
"id": "test-secret",
"repository": "test-repo",
"secret_name": "test-secret",
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T00:00:00Z",
"plaintext_value": "secret-value",
}
newState, err := migrateGithubActionsSecretStateV0toV1(&terraform.InstanceState{
ID: "test-secret",
Attributes: oldAttributes,
})
if err != nil {
t.Fatal(err)
}
expectedAttributes := map[string]string{
"id": "test-secret",
"repository": "test-repo",
"secret_name": "test-secret",
"created_at": "2023-01-01T00:00:00Z",
"updated_at": "2023-01-01T00:00:00Z",
"plaintext_value": "secret-value",
"destroy_on_drift": "true",
}
if !reflect.DeepEqual(newState.Attributes, expectedAttributes) {
t.Fatalf("Expected attributes:\n%#v\n\nGiven:\n%#v\n",
expectedAttributes, newState.Attributes)
}
// Secret with existing destroy_on_drift should be preserved
oldAttributesWithDrift := map[string]string{
"id": "test-secret",
"repository": "test-repo",
"secret_name": "test-secret",
"destroy_on_drift": "false",
}
newState2, err := migrateGithubActionsSecretStateV0toV1(&terraform.InstanceState{
ID: "test-secret",
Attributes: oldAttributesWithDrift,
})
if err != nil {
t.Fatal(err)
}
expectedAttributesWithDrift := map[string]string{
"id": "test-secret",
"repository": "test-repo",
"secret_name": "test-secret",
"destroy_on_drift": "false",
}
if !reflect.DeepEqual(newState2.Attributes, expectedAttributesWithDrift) {
t.Fatalf("Expected attributes:\n%#v\n\nGiven:\n%#v\n",
expectedAttributesWithDrift, newState2.Attributes)
}
}