Skip to content

Commit 5e4e2fb

Browse files
committed
Update tests to use ConfigStateChecks
Signed-off-by: Timo Sand <[email protected]>
1 parent 17f777f commit 5e4e2fb

1 file changed

Lines changed: 24 additions & 28 deletions

File tree

github/resource_github_branch_default_test.go

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,18 @@ func TestAccGithubBranchDefault(t *testing.T) {
3030
}
3131
`, repoName)
3232

33-
check := resource.ComposeTestCheckFunc(
34-
resource.TestCheckResourceAttr(
35-
"github_branch_default.test", "branch",
36-
"main",
37-
),
38-
resource.TestCheckResourceAttr(
39-
"github_branch_default.test", "repository",
40-
repoName,
41-
),
42-
)
43-
4433
resource.Test(t, resource.TestCase{
4534
PreCheck: func() { skipUnauthenticated(t) },
4635
ProviderFactories: providerFactories,
4736
Steps: []resource.TestStep{
4837
{
4938
Config: config,
50-
Check: check,
39+
ConfigStateChecks: []statecheck.StateCheck{
40+
statecheck.CompareValuePairs("github_branch_default.test", tfjsonpath.New("repository"), "github_repository.test", tfjsonpath.New("name"), compare.ValuesSame()),
41+
statecheck.CompareValuePairs("github_branch_default.test", tfjsonpath.New("branch"), "github_repository.test", tfjsonpath.New("default_branch"), compare.ValuesSame()),
42+
statecheck.ExpectKnownValue("github_branch_default.test", tfjsonpath.New("repository_id"), knownvalue.NotNull()),
43+
statecheck.ExpectKnownValue("github_branch_default.test", tfjsonpath.New("etag"), knownvalue.NotNull()),
44+
},
5145
},
5246
},
5347
})
@@ -80,9 +74,12 @@ func TestAccGithubBranchDefault(t *testing.T) {
8074
Steps: []resource.TestStep{
8175
{
8276
Config: config,
83-
Check: resource.ComposeTestCheckFunc(
84-
resource.TestCheckResourceAttr("github_branch_default.test", "branch", "test"),
85-
),
77+
ConfigStateChecks: []statecheck.StateCheck{
78+
statecheck.CompareValuePairs("github_branch_default.test", tfjsonpath.New("repository"), "github_repository.test", tfjsonpath.New("name"), compare.ValuesSame()),
79+
statecheck.CompareValuePairs("github_branch_default.test", tfjsonpath.New("branch"), "github_branch.test", tfjsonpath.New("branch"), compare.ValuesSame()),
80+
statecheck.ExpectKnownValue("github_branch_default.test", tfjsonpath.New("repository_id"), knownvalue.NotNull()),
81+
statecheck.ExpectKnownValue("github_branch_default.test", tfjsonpath.New("etag"), knownvalue.NotNull()),
82+
},
8683
},
8784
{
8885
Config: `
@@ -112,24 +109,18 @@ func TestAccGithubBranchDefault(t *testing.T) {
112109
}
113110
`, repoName)
114111

115-
check := resource.ComposeTestCheckFunc(
116-
resource.TestCheckResourceAttr(
117-
"github_branch_default.test", "branch",
118-
"main",
119-
),
120-
resource.TestCheckResourceAttr(
121-
"github_branch_default.test", "repository",
122-
repoName,
123-
),
124-
)
125-
126112
resource.Test(t, resource.TestCase{
127113
PreCheck: func() { skipUnauthenticated(t) },
128114
ProviderFactories: providerFactories,
129115
Steps: []resource.TestStep{
130116
{
131117
Config: config,
132-
Check: check,
118+
ConfigStateChecks: []statecheck.StateCheck{
119+
statecheck.CompareValuePairs("github_branch_default.test", tfjsonpath.New("repository"), "github_repository.test", tfjsonpath.New("name"), compare.ValuesSame()),
120+
statecheck.CompareValuePairs("github_branch_default.test", tfjsonpath.New("branch"), "github_repository.test", tfjsonpath.New("default_branch"), compare.ValuesSame()),
121+
statecheck.ExpectKnownValue("github_branch_default.test", tfjsonpath.New("repository_id"), knownvalue.NotNull()),
122+
statecheck.ExpectKnownValue("github_branch_default.test", tfjsonpath.New("etag"), knownvalue.NotNull()),
123+
},
133124
},
134125
},
135126
})
@@ -157,7 +148,12 @@ func TestAccGithubBranchDefault(t *testing.T) {
157148
Steps: []resource.TestStep{
158149
{
159150
Config: config,
160-
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttr("github_branch_default.test", "branch", "development")),
151+
ConfigStateChecks: []statecheck.StateCheck{
152+
statecheck.CompareValuePairs("github_branch_default.test", tfjsonpath.New("repository"), "github_repository.test", tfjsonpath.New("name"), compare.ValuesSame()),
153+
statecheck.ExpectKnownValue("github_branch_default.test", tfjsonpath.New("branch"), knownvalue.StringExact("development")),
154+
statecheck.ExpectKnownValue("github_branch_default.test", tfjsonpath.New("repository_id"), knownvalue.NotNull()),
155+
statecheck.ExpectKnownValue("github_branch_default.test", tfjsonpath.New("etag"), knownvalue.NotNull()),
156+
},
161157
},
162158
},
163159
})

0 commit comments

Comments
 (0)