Skip to content

Commit

Permalink
chore: extend tests with false cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bschaatsbergen committed Mar 31, 2024
1 parent 34432c4 commit 01eb4e5
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 1 deletion.
88 changes: 88 additions & 0 deletions internal/provider/between_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,94 @@ output "test" {
})
}

func TestBetweenFunction_minus(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(version.Must(version.NewVersion(MinimalRequiredTerraformVersion))),
},
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::between(-10, 10, 0)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
),
},
},
})
}

func TestBetweenFunction_float(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(version.Must(version.NewVersion(MinimalRequiredTerraformVersion))),
},
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::between(1.0, 10.0, 5.0)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
),
},
},
})
}

func TestBetweenFunction_minusFloat(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(version.Must(version.NewVersion(MinimalRequiredTerraformVersion))),
},
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::between(-10.0, 10.0, 0.0)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
),
},
},
})
}

func TestBetweenFunction_largeNumber(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(version.Must(version.NewVersion(MinimalRequiredTerraformVersion))),
},
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::between(2147483647, 2147483648, 2147483647)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
),
},
},
})
}

func TestBetweenFunction_falseCases(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
Expand Down
22 changes: 22 additions & 0 deletions internal/provider/contains_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ output "test" {
})
}

func TestContainsFunction_set(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(version.Must(version.NewVersion(MinimalRequiredTerraformVersion))),
},
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::assert::contains(toset(["a", "b", "c"]), "b")
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "true"),
),
},
},
})
}

func TestContainsFunction_falseCases(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
Expand Down
13 changes: 13 additions & 0 deletions internal/provider/http_client_error_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ locals {
}
output "test" {
value = provider::assert::http_client_error(local.status_code)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "false"),
),
},
{
Config: `
locals {
status_code_as_string = "201"
}
output "test" {
value = provider::assert::http_client_error(local.status_code_as_string)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
Expand Down
4 changes: 3 additions & 1 deletion internal/provider/http_redirect_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func (r IsHTTPRedirectFunction) Run(ctx context.Context, req function.RunRequest
return
}

resp.Error = function.ConcatFuncErrors(resp.Result.Set(ctx, isRedirectStatusCode(statusCode.ValueInt64())))
result := isRedirectStatusCode(statusCode.ValueInt64())

resp.Error = function.ConcatFuncErrors(resp.Result.Set(ctx, result))
}

// isValid3xxStatusCode checks if an HTTP status code is within the 3xx range.
Expand Down
13 changes: 13 additions & 0 deletions internal/provider/http_redirect_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ locals {
}
output "test" {
value = provider::assert::http_redirect(local.status_code)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "false"),
),
},
{
Config: `
locals {
status_code_as_string = "201"
}
output "test" {
value = provider::assert::http_redirect(local.status_code_as_string)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
Expand Down
13 changes: 13 additions & 0 deletions internal/provider/http_server_error_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ locals {
}
output "test" {
value = provider::assert::http_server_error(local.status_code)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "false"),
),
},
{
Config: `
locals {
status_code_as_string = "201"
}
output "test" {
value = provider::assert::http_server_error(local.status_code_as_string)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
Expand Down
13 changes: 13 additions & 0 deletions internal/provider/http_success_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ locals {
}
output "test" {
value = provider::assert::http_success(local.status_code)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckOutput("test", "false"),
),
},
{
Config: `
locals {
status_code_as_string = "403"
}
output "test" {
value = provider::assert::http_success(local.status_code_as_string)
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
Expand Down

0 comments on commit 01eb4e5

Please sign in to comment.