Skip to content

Commit aed1a52

Browse files
committed
test(billing-usage): improve acceptance tests with ID format and structural checks
Add assertions for: - ID format using StringRegexp (e.g. 'slug:billing-usage') - usage_items and time_period are NotNull - Additional filter variants (year+month) for billing usage data source
1 parent 18f5381 commit aed1a52

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

github/data_source_github_enterprise_billing_premium_request_usage_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package github
22

33
import (
44
"fmt"
5+
"regexp"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -29,6 +30,18 @@ func TestAccGithubEnterpriseBillingPremiumRequestUsage(t *testing.T) {
2930
tfjsonpath.New("enterprise_slug"),
3031
knownvalue.StringExact(testAccConf.enterpriseSlug),
3132
),
33+
statecheck.ExpectKnownValue("data.github_enterprise_billing_premium_request_usage.test",
34+
tfjsonpath.New("id"),
35+
knownvalue.StringRegexp(regexp.MustCompile(`^.+:billing-premium-request-usage$`)),
36+
),
37+
statecheck.ExpectKnownValue("data.github_enterprise_billing_premium_request_usage.test",
38+
tfjsonpath.New("usage_items"),
39+
knownvalue.NotNull(),
40+
),
41+
statecheck.ExpectKnownValue("data.github_enterprise_billing_premium_request_usage.test",
42+
tfjsonpath.New("time_period"),
43+
knownvalue.NotNull(),
44+
),
3245
},
3346
},
3447
},
@@ -55,6 +68,14 @@ func TestAccGithubEnterpriseBillingPremiumRequestUsage(t *testing.T) {
5568
tfjsonpath.New("enterprise_slug"),
5669
knownvalue.StringExact(testAccConf.enterpriseSlug),
5770
),
71+
statecheck.ExpectKnownValue("data.github_enterprise_billing_premium_request_usage.test",
72+
tfjsonpath.New("usage_items"),
73+
knownvalue.NotNull(),
74+
),
75+
statecheck.ExpectKnownValue("data.github_enterprise_billing_premium_request_usage.test",
76+
tfjsonpath.New("time_period"),
77+
knownvalue.NotNull(),
78+
),
5879
},
5980
},
6081
},

github/data_source_github_enterprise_billing_usage_summary_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package github
22

33
import (
44
"fmt"
5+
"regexp"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -29,6 +30,18 @@ func TestAccGithubEnterpriseBillingUsageSummary(t *testing.T) {
2930
tfjsonpath.New("enterprise_slug"),
3031
knownvalue.StringExact(testAccConf.enterpriseSlug),
3132
),
33+
statecheck.ExpectKnownValue("data.github_enterprise_billing_usage_summary.test",
34+
tfjsonpath.New("id"),
35+
knownvalue.StringRegexp(regexp.MustCompile(`^.+:billing-usage-summary$`)),
36+
),
37+
statecheck.ExpectKnownValue("data.github_enterprise_billing_usage_summary.test",
38+
tfjsonpath.New("usage_items"),
39+
knownvalue.NotNull(),
40+
),
41+
statecheck.ExpectKnownValue("data.github_enterprise_billing_usage_summary.test",
42+
tfjsonpath.New("time_period"),
43+
knownvalue.NotNull(),
44+
),
3245
},
3346
},
3447
},
@@ -55,6 +68,14 @@ func TestAccGithubEnterpriseBillingUsageSummary(t *testing.T) {
5568
tfjsonpath.New("enterprise_slug"),
5669
knownvalue.StringExact(testAccConf.enterpriseSlug),
5770
),
71+
statecheck.ExpectKnownValue("data.github_enterprise_billing_usage_summary.test",
72+
tfjsonpath.New("usage_items"),
73+
knownvalue.NotNull(),
74+
),
75+
statecheck.ExpectKnownValue("data.github_enterprise_billing_usage_summary.test",
76+
tfjsonpath.New("time_period"),
77+
knownvalue.NotNull(),
78+
),
5879
},
5980
},
6081
},

github/data_source_github_enterprise_billing_usage_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package github
22

33
import (
44
"fmt"
5+
"regexp"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -29,6 +30,14 @@ func TestAccGithubEnterpriseBillingUsage(t *testing.T) {
2930
tfjsonpath.New("enterprise_slug"),
3031
knownvalue.StringExact(testAccConf.enterpriseSlug),
3132
),
33+
statecheck.ExpectKnownValue("data.github_enterprise_billing_usage.test",
34+
tfjsonpath.New("id"),
35+
knownvalue.StringRegexp(regexp.MustCompile(`^.+:billing-usage$`)),
36+
),
37+
statecheck.ExpectKnownValue("data.github_enterprise_billing_usage.test",
38+
tfjsonpath.New("usage_items"),
39+
knownvalue.NotNull(),
40+
),
3241
},
3342
},
3443
},
@@ -54,6 +63,40 @@ func TestAccGithubEnterpriseBillingUsage(t *testing.T) {
5463
tfjsonpath.New("enterprise_slug"),
5564
knownvalue.StringExact(testAccConf.enterpriseSlug),
5665
),
66+
statecheck.ExpectKnownValue("data.github_enterprise_billing_usage.test",
67+
tfjsonpath.New("usage_items"),
68+
knownvalue.NotNull(),
69+
),
70+
},
71+
},
72+
},
73+
})
74+
})
75+
76+
t.Run("reads billing usage with month filter without error", func(t *testing.T) {
77+
config := fmt.Sprintf(`
78+
data "github_enterprise_billing_usage" "test" {
79+
enterprise_slug = "%s"
80+
year = 2025
81+
month = 1
82+
}
83+
`, testAccConf.enterpriseSlug)
84+
85+
resource.Test(t, resource.TestCase{
86+
PreCheck: func() { skipUnlessMode(t, enterprise) },
87+
ProviderFactories: providerFactories,
88+
Steps: []resource.TestStep{
89+
{
90+
Config: config,
91+
ConfigStateChecks: []statecheck.StateCheck{
92+
statecheck.ExpectKnownValue("data.github_enterprise_billing_usage.test",
93+
tfjsonpath.New("enterprise_slug"),
94+
knownvalue.StringExact(testAccConf.enterpriseSlug),
95+
),
96+
statecheck.ExpectKnownValue("data.github_enterprise_billing_usage.test",
97+
tfjsonpath.New("usage_items"),
98+
knownvalue.NotNull(),
99+
),
57100
},
58101
},
59102
},

0 commit comments

Comments
 (0)