Skip to content

Commit fec8fd7

Browse files
committed
Fix github_branch_protection migration test to be a unit test
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent 52ca878 commit fec8fd7

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package github
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func testGithubBranchProtectionStateDataV1() map[string]any {
9+
return map[string]any{
10+
"blocks_creations": true,
11+
"push_restrictions": [...]string{"/example-user"},
12+
}
13+
}
14+
15+
func testGithubBranchProtectionStateDataV2() map[string]any {
16+
restrictions := []any{map[string]any{
17+
"blocks_creations": true,
18+
"push_allowances": [...]string{"/example-user"},
19+
}}
20+
return map[string]any{
21+
"restrict_pushes": restrictions,
22+
}
23+
}
24+
25+
func Test_resourceGithubBranchProtectionStateUpgradeV1(t *testing.T) {
26+
expected := testGithubBranchProtectionStateDataV2()
27+
actual, err := resourceGithubBranchProtectionUpgradeV1(t.Context(), testGithubBranchProtectionStateDataV1(), nil)
28+
if err != nil {
29+
t.Fatalf("error migrating state: %s", err)
30+
}
31+
32+
if !reflect.DeepEqual(expected, actual) {
33+
t.Fatalf("\n\nexpected:\n\n%#v\n\ngot:\n\n%#v\n\n", expected, actual)
34+
}
35+
}

github/resource_github_branch_protection_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package github
22

33
import (
4-
"context"
54
"fmt"
6-
"reflect"
75
"regexp"
86
"testing"
97

@@ -749,32 +747,3 @@ func importBranchProtectionByRepoID(repoLogicalName, pattern string) resource.Im
749747
return fmt.Sprintf("%s:%s", repoID, pattern), nil
750748
}
751749
}
752-
753-
func testGithubBranchProtectionStateDataV1() map[string]any {
754-
return map[string]any{
755-
"blocks_creations": true,
756-
"push_restrictions": [...]string{"/example-user"},
757-
}
758-
}
759-
760-
func testGithubBranchProtectionStateDataV2() map[string]any {
761-
restrictions := []any{map[string]any{
762-
"blocks_creations": true,
763-
"push_allowances": [...]string{"/example-user"},
764-
}}
765-
return map[string]any{
766-
"restrict_pushes": restrictions,
767-
}
768-
}
769-
770-
func TestAccGithubBranchProtectionV4StateUpgradeV1(t *testing.T) {
771-
expected := testGithubBranchProtectionStateDataV2()
772-
actual, err := resourceGithubBranchProtectionUpgradeV1(context.Background(), testGithubBranchProtectionStateDataV1(), nil)
773-
if err != nil {
774-
t.Fatalf("error migrating state: %s", err)
775-
}
776-
777-
if !reflect.DeepEqual(expected, actual) {
778-
t.Fatalf("\n\nexpected:\n\n%#v\n\ngot:\n\n%#v\n\n", expected, actual)
779-
}
780-
}

0 commit comments

Comments
 (0)