forked from integrations/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource_github_repository_file_migration_test.go
More file actions
112 lines (106 loc) · 3.3 KB
/
resource_github_repository_file_migration_test.go
File metadata and controls
112 lines (106 loc) · 3.3 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package github
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
)
func Test_resourceGithubRepositoryFileStateUpgradeV0(t *testing.T) {
t.Parallel()
for _, d := range []struct {
testName string
rawState map[string]any
want map[string]any
shouldError bool
}{
{
testName: "preserves_existing_branch",
rawState: map[string]any{
"id": "test-repo/path/to/file.txt",
"repository": "test-repo",
"file": "path/to/file.txt",
"content": "file content",
"branch": "main",
"commit_sha": "abc123",
"sha": "def456",
"overwrite_on_create": false,
},
want: map[string]any{
"id": "test-repo/path/to/file.txt:main",
"repository": "test-repo",
"file": "path/to/file.txt",
"content": "file content",
"branch": "main",
"commit_sha": "abc123",
"sha": "def456",
"overwrite_on_create": false,
},
shouldError: false,
},
{
testName: "preserves_custom_branch",
rawState: map[string]any{
"id": "test-repo/README.md",
"repository": "test-repo",
"file": "README.md",
"content": "# README",
"branch": "develop",
},
want: map[string]any{
"id": "test-repo/README.md:develop",
"repository": "test-repo",
"file": "README.md",
"content": "# README",
"branch": "develop",
},
shouldError: false,
},
// TODO: Enable this test once we have a pattern to create a mock client for the test.
// {
// testName: "migrates_with_missing_branch",
// rawState: map[string]any{
// "id": "test-repo/path/to/file.txt",
// "repository": "test-repo",
// "file": "path/to/file.txt",
// "content": "file content",
// },
// want: map[string]any{
// "id": "test-repo/path/to/file.txt:main",
// "repository": "test-repo",
// "file": "path/to/file.txt",
// "content": "file content",
// "branch": "main", // fetched from API
// },
// shouldError: false,
// },
// TODO: Enable this test once we have a pattern to create a mock client for the test.
// {
// testName: "migrates_with_empty_branch",
// rawState: map[string]any{
// "id": "test-repo/path/to/file.txt",
// "repository": "test-repo",
// "file": "path/to/file.txt",
// "content": "file content",
// "branch": "",
// },
// want: map[string]any{
// "id": "test-repo/path/to/file.txt:main",
// "repository": "test-repo",
// "file": "path/to/file.txt",
// "content": "file content",
// "branch": "main", // fetched from API
// },
// shouldError: false,
// },
} {
t.Run(d.testName, func(t *testing.T) {
t.Parallel()
got, err := resourceGithubRepositoryFileStateUpgradeV0(context.Background(), d.rawState, nil)
if (err != nil) != d.shouldError {
t.Fatalf("unexpected error state: got error %v, shouldError %v", err, d.shouldError)
}
if diff := cmp.Diff(got, d.want); diff != "" && !d.shouldError {
t.Fatalf("got %+v, want %+v, diff %s", got, d.want, diff)
}
})
}
}