Skip to content

Commit 37db1fd

Browse files
committed
test: Add validation tests for GitHub branch resource schema
1 parent ac3540b commit 37db1fd

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package github
2+
3+
import "testing"
4+
5+
func TestGithubBranchIsUpdatedWhenBranchChanges(t *testing.T) {
6+
resource := resourceGithubBranch()
7+
8+
branchSchema := resource.Schema["branch"]
9+
if branchSchema == nil {
10+
t.Fatal("branch field should exist in schema")
11+
}
12+
if branchSchema.ForceNew {
13+
t.Error("branch field should not be ForceNew so renames are handled via update")
14+
}
15+
}
16+
17+
func TestGithubBranchIsRecreatedWhenRepositoryChanges(t *testing.T) {
18+
resource := resourceGithubBranch()
19+
20+
repositorySchema := resource.Schema["repository"]
21+
if repositorySchema == nil {
22+
t.Fatal("repository field should exist in schema")
23+
}
24+
if !repositorySchema.ForceNew {
25+
t.Error("repository field should be ForceNew so changes recreate the resource")
26+
}
27+
}
28+
29+
func TestGithubBranchIsRecreatedWhenSourceBranchChanges(t *testing.T) {
30+
resource := resourceGithubBranch()
31+
32+
sourceBranchSchema := resource.Schema["source_branch"]
33+
if sourceBranchSchema == nil {
34+
t.Fatal("source_branch field should exist in schema")
35+
}
36+
if !sourceBranchSchema.ForceNew {
37+
t.Error("source_branch field should be ForceNew so changes recreate the resource")
38+
}
39+
}
40+
41+
func TestGithubBranchIsRecreatedWhenSourceSHAChanges(t *testing.T) {
42+
resource := resourceGithubBranch()
43+
44+
sourceSHASchema := resource.Schema["source_sha"]
45+
if sourceSHASchema == nil {
46+
t.Fatal("source_sha field should exist in schema")
47+
}
48+
if !sourceSHASchema.ForceNew {
49+
t.Error("source_sha field should be ForceNew so changes recreate the resource")
50+
}
51+
}

0 commit comments

Comments
 (0)