Skip to content

Commit

Permalink
chore: add terrafmt for linting blocks in provider code
Browse files Browse the repository at this point in the history
  • Loading branch information
bschaatsbergen committed Mar 31, 2024
1 parent 6cf9435 commit 065d07f
Show file tree
Hide file tree
Showing 19 changed files with 378 additions and 366 deletions.
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,17 @@ test:
testacc:
TF_ACC=1 go test -v -cover -timeout 120m ./...

tests-lint: tools
@echo "==> Checking acceptance test terraform blocks code with terrafmt..."
@terrafmt diff -f ./internal/provider --check --pattern '*_test.go' --quiet || (echo; \
echo "Unexpected differences in acceptance test HCL formatting."; \
echo "To see the full differences, run: terrafmt diff ./internal/provider --pattern '*_test.go'"; \
echo "To automatically fix the formatting, run 'make tests-lint-fix' and commit the changes."; \
exit 1)

tests-lint-fix: tools
@echo "==> Fixing acceptance test terraform blocks code with terrafmt..."
@find ./internal/provider -name "*_test.go" -exec sed -i ':a;N;$$!ba;s/fmt.Sprintf(`\n/fmt.Sprintf(`/g' '{}' \; # remove newlines for terrafmt
@terrafmt fmt -f ./internal/provider --pattern '*_test.go'

.PHONY: build install lint generate fmt test testacc
12 changes: 6 additions & 6 deletions internal/provider/between_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func TestBetweenFunction(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::between(1, 10, 5)
}
output "test" {
value = provider::assert::between(1, 10, 5)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -43,9 +43,9 @@ func TestBetweenFunction_falseCases(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::between(1, 10, 11)
}
output "test" {
value = provider::assert::between(1, 10, 11)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "false"),
Expand Down
12 changes: 6 additions & 6 deletions internal/provider/contains_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func TestContainsFunction(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::contains(["a", "b", "c"], "b")
}
output "test" {
value = provider::assert::contains(["a", "b", "c"], "b")
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -43,9 +43,9 @@ func TestContainsFunction_falseCases(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::contains(["a", "b", "c"], "x")
}
output "test" {
value = provider::assert::contains(["a", "b", "c"], "x")
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "false"),
Expand Down
30 changes: 15 additions & 15 deletions internal/provider/equal_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func TestEqualFunction(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::equal(1000000, 1000000)
}
output "test" {
value = provider::assert::equal(1000000, 1000000)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -43,9 +43,9 @@ func TestEqualFunction_float(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::equal(43234.43234, 43234.43234)
}
output "test" {
value = provider::assert::equal(43234.43234, 43234.43234)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -65,9 +65,9 @@ func TestEqualFunction_minus(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::equal(-20, -20)
}
output "test" {
value = provider::assert::equal(-20, -20)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -87,9 +87,9 @@ func TestEqualFunction_minusFloat(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::equal(-10.43234, -10.43234)
}
output "test" {
value = provider::assert::equal(-10.43234, -10.43234)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -109,9 +109,9 @@ func TestEqualFunction_falseCases(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::equal(100, 105)
}
output "test" {
value = provider::assert::equal(100, 105)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "false"),
Expand Down
36 changes: 18 additions & 18 deletions internal/provider/false_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func TestFalseFunction(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::false(false)
}
output "test" {
value = provider::assert::false(false)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -43,12 +43,12 @@ func TestFalseFunction_stringComparison(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
locals {
comparison = "abc" == "def"
}
output "test" {
value = provider::assert::false(local.comparison)
}
locals {
comparison = "abc" == "def"
}
output "test" {
value = provider::assert::false(local.comparison)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -68,22 +68,22 @@ func TestFalseFunction_falseCases(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::false(true)
}
output "test" {
value = provider::assert::false(true)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "false"),
),
},
{
Config: `
locals {
comparison = "abc" == "abc"
}
output "test" {
value = provider::assert::false(local.comparison)
}
locals {
comparison = "abc" == "abc"
}
output "test" {
value = provider::assert::false(local.comparison)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "false"),
Expand Down
30 changes: 15 additions & 15 deletions internal/provider/greater_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func TestGreaterFunction(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater(500, 200)
}
output "test" {
value = provider::assert::greater(500, 200)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -43,9 +43,9 @@ func TestGreaterFunction_float(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater(50.32132, 40.53443)
}
output "test" {
value = provider::assert::greater(50.32132, 40.53443)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -65,9 +65,9 @@ func TestGreaterFunction_minus(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater(-10, -20)
}
output "test" {
value = provider::assert::greater(-10, -20)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -87,9 +87,9 @@ func TestGreaterFunction_minusFloat(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater(-10.43234, -20.2112132)
}
output "test" {
value = provider::assert::greater(-10.43234, -20.2112132)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -109,9 +109,9 @@ func TestGreaterFunction_falseCases(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater(100, 105)
}
output "test" {
value = provider::assert::greater(100, 105)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "false"),
Expand Down
42 changes: 21 additions & 21 deletions internal/provider/greater_or_equal_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func TestGreaterOrEqualFunction(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater_or_equal(500, 200)
}
output "test" {
value = provider::assert::greater_or_equal(500, 200)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -43,9 +43,9 @@ func TestGreaterOrEqualFunction_equal(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater_or_equal(1000000, 1000000)
}
output "test" {
value = provider::assert::greater_or_equal(1000000, 1000000)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -65,9 +65,9 @@ func TestGreaterOrEqualFunction_equalFloat(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater_or_equal(43234.43234, 43234.43234)
}
output "test" {
value = provider::assert::greater_or_equal(43234.43234, 43234.43234)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -87,9 +87,9 @@ func TestGreaterOrEqualFunction_float(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater_or_equal(50.32132, 40.53443)
}
output "test" {
value = provider::assert::greater_or_equal(50.32132, 40.53443)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -109,9 +109,9 @@ func TestGreaterOrEqualFunction_minus(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater_or_equal(-10, -20)
}
output "test" {
value = provider::assert::greater_or_equal(-10, -20)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -131,9 +131,9 @@ func TestGreaterOrEqualFunction_minusFloat(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater_or_equal(-10.43234, -20.2112132)
}
output "test" {
value = provider::assert::greater_or_equal(-10.43234, -20.2112132)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
Expand All @@ -153,9 +153,9 @@ func TestGreaterOrEqualFunction_falseCases(t *testing.T) {
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::greater_or_equal(100, 105)
}
output "test" {
value = provider::assert::greater_or_equal(100, 105)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "false"),
Expand Down
Loading

0 comments on commit 065d07f

Please sign in to comment.