Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Adjust test asserts #3289

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions pkg/acceptance/bettertestspoc/assert/resource_assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package assert
import (
"errors"
"fmt"
"strconv"
"strings"
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance/importchecks"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)
Expand Down Expand Up @@ -92,62 +90,6 @@ func ValueNotSet(fieldName string) ResourceAssertion {
return ResourceAssertion{fieldName: fieldName, resourceAssertionType: resourceAssertionTypeValueNotSet}
}

const showOutputPrefix = "show_output.0."

func ResourceShowOutputBoolValueSet(fieldName string, expected bool) ResourceAssertion {
return ResourceShowOutputValueSet(fieldName, strconv.FormatBool(expected))
}

func ResourceShowOutputIntValueSet(fieldName string, expected int) ResourceAssertion {
return ResourceShowOutputValueSet(fieldName, strconv.Itoa(expected))
}

func ResourceShowOutputFloatValueSet(fieldName string, expected float64) ResourceAssertion {
return ResourceShowOutputValueSet(fieldName, strconv.FormatFloat(expected, 'f', -1, 64))
}

func ResourceShowOutputStringUnderlyingValueSet[U ~string](fieldName string, expected U) ResourceAssertion {
return ResourceShowOutputValueSet(fieldName, string(expected))
}

func ResourceShowOutputValueSet(fieldName string, expected string) ResourceAssertion {
return ResourceAssertion{fieldName: showOutputPrefix + fieldName, expectedValue: expected, resourceAssertionType: resourceAssertionTypeValueSet}
}

func ResourceShowOutputValueNotSet(fieldName string) ResourceAssertion {
return ResourceAssertion{fieldName: showOutputPrefix + fieldName, resourceAssertionType: resourceAssertionTypeValueNotSet}
}

func ResourceShowOutputValuePresent(fieldName string) ResourceAssertion {
return ResourceAssertion{fieldName: showOutputPrefix + fieldName, resourceAssertionType: resourceAssertionTypeValuePresent}
}

const (
parametersPrefix = "parameters.0."
parametersValueSuffix = ".0.value"
parametersLevelSuffix = ".0.level"
)

func ResourceParameterBoolValueSet[T ~string](parameterName T, expected bool) ResourceAssertion {
return ResourceParameterValueSet(parameterName, strconv.FormatBool(expected))
}

func ResourceParameterIntValueSet[T ~string](parameterName T, expected int) ResourceAssertion {
return ResourceParameterValueSet(parameterName, strconv.Itoa(expected))
}

func ResourceParameterStringUnderlyingValueSet[T ~string, U ~string](parameterName T, expected U) ResourceAssertion {
return ResourceParameterValueSet(parameterName, string(expected))
}

func ResourceParameterValueSet[T ~string](parameterName T, expected string) ResourceAssertion {
return ResourceAssertion{fieldName: parametersPrefix + strings.ToLower(string(parameterName)) + parametersValueSuffix, expectedValue: expected, resourceAssertionType: resourceAssertionTypeValueSet}
}

func ResourceParameterLevelSet[T ~string](parameterName T, parameterType sdk.ParameterType) ResourceAssertion {
return ResourceAssertion{fieldName: parametersPrefix + strings.ToLower(string(parameterName)) + parametersLevelSuffix, expectedValue: string(parameterType), resourceAssertionType: resourceAssertionTypeValueSet}
}

// ToTerraformTestCheckFunc implements TestCheckFuncProvider to allow easier creation of new resource assertions.
// It goes through all the assertion accumulated earlier and gathers the results of the checks.
func (r *ResourceAssert) ToTerraformTestCheckFunc(t *testing.T) resource.TestCheckFunc {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package assert

import (
"strconv"
"strings"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
)

const (
parametersPrefix = "parameters.0."
parametersValueSuffix = ".0.value"
parametersLevelSuffix = ".0.level"
)

func ResourceParameterBoolValueSet[T ~string](parameterName T, expected bool) ResourceAssertion {
return ResourceParameterValueSet(parameterName, strconv.FormatBool(expected))
}

func ResourceParameterBoolValueNotSet[T ~string](parameterName T) ResourceAssertion {
return ResourceParameterValueNotSet(parameterName)
}

func ResourceParameterBoolValuePresent[T ~string](parameterName T) ResourceAssertion {
return ResourceParameterValuePresent(parameterName)
}

func ResourceParameterIntValueSet[T ~string](parameterName T, expected int) ResourceAssertion {
return ResourceParameterValueSet(parameterName, strconv.Itoa(expected))
}

func ResourceParameterIntValueNotSet[T ~string](parameterName T) ResourceAssertion {
return ResourceParameterValueNotSet(parameterName)
}

func ResourceParameterIntValuePresent[T ~string](parameterName T) ResourceAssertion {
return ResourceParameterValuePresent(parameterName)
}

func ResourceParameterStringUnderlyingValueSet[T ~string, U ~string](parameterName T, expected U) ResourceAssertion {
return ResourceParameterValueSet(parameterName, string(expected))
}

func ResourceParameterStringUnderlyingValueNotSet[T ~string](parameterName T) ResourceAssertion {
return ResourceParameterValueNotSet(parameterName)
}

func ResourceParameterStringUnderlyingValuePresent[T ~string](parameterName T) ResourceAssertion {
return ResourceParameterValuePresent(parameterName)
}

func ResourceParameterValueSet[T ~string](parameterName T, expected string) ResourceAssertion {
return ResourceAssertion{fieldName: parametersPrefix + strings.ToLower(string(parameterName)) + parametersValueSuffix, expectedValue: expected, resourceAssertionType: resourceAssertionTypeValueSet}
}

func ResourceParameterValueNotSet[T ~string](parameterName T) ResourceAssertion {
return ResourceAssertion{fieldName: parametersPrefix + strings.ToLower(string(parameterName)) + parametersValueSuffix, resourceAssertionType: resourceAssertionTypeValueNotSet}
}

func ResourceParameterValuePresent[T ~string](parameterName T) ResourceAssertion {
return ResourceAssertion{fieldName: parametersPrefix + strings.ToLower(string(parameterName)) + parametersValueSuffix, resourceAssertionType: resourceAssertionTypeValuePresent}
}

func ResourceParameterLevelSet[T ~string](parameterName T, parameterType sdk.ParameterType) ResourceAssertion {
return ResourceAssertion{fieldName: parametersPrefix + strings.ToLower(string(parameterName)) + parametersLevelSuffix, expectedValue: string(parameterType), resourceAssertionType: resourceAssertionTypeValueSet}
}
67 changes: 67 additions & 0 deletions pkg/acceptance/bettertestspoc/assert/resource_show_assertions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package assert

import (
"strconv"
)

const showOutputPrefix = "show_output.0."

func ResourceShowOutputBoolValueSet(fieldName string, expected bool) ResourceAssertion {
return ResourceShowOutputValueSet(fieldName, strconv.FormatBool(expected))
}

func ResourceShowOutputBoolValueNotSet(fieldName string) ResourceAssertion {
return ResourceShowOutputValueNotSet(fieldName)
}

func ResourceShowOutputBoolValuePresent(fieldName string) ResourceAssertion {
return ResourceShowOutputValuePresent(fieldName)
}

func ResourceShowOutputIntValueSet(fieldName string, expected int) ResourceAssertion {
return ResourceShowOutputValueSet(fieldName, strconv.Itoa(expected))
}

func ResourceShowOutputIntValueNotSet(fieldName string) ResourceAssertion {
return ResourceShowOutputValueNotSet(fieldName)
}

func ResourceShowOutputIntValuePresent(fieldName string) ResourceAssertion {
return ResourceShowOutputValuePresent(fieldName)
}

func ResourceShowOutputFloatValueSet(fieldName string, expected float64) ResourceAssertion {
return ResourceShowOutputValueSet(fieldName, strconv.FormatFloat(expected, 'f', -1, 64))
}

func ResourceShowOutputFloatValueNotSet(fieldName string) ResourceAssertion {
return ResourceShowOutputValueNotSet(fieldName)
}

func ResourceShowOutputFloatValuePresent(fieldName string) ResourceAssertion {
return ResourceShowOutputValuePresent(fieldName)
}

func ResourceShowOutputStringUnderlyingValueSet[U ~string](fieldName string, expected U) ResourceAssertion {
return ResourceShowOutputValueSet(fieldName, string(expected))
}

func ResourceShowOutputStringUnderlyingValueNotSet(fieldName string) ResourceAssertion {
return ResourceShowOutputValueNotSet(fieldName)
}

func ResourceShowOutputStringUnderlyingValuePresent(fieldName string) ResourceAssertion {
return ResourceShowOutputValuePresent(fieldName)
}

func ResourceShowOutputValueSet(fieldName string, expected string) ResourceAssertion {
return ResourceAssertion{fieldName: showOutputPrefix + fieldName, expectedValue: expected, resourceAssertionType: resourceAssertionTypeValueSet}
}

func ResourceShowOutputValueNotSet(fieldName string) ResourceAssertion {
return ResourceAssertion{fieldName: showOutputPrefix + fieldName, resourceAssertionType: resourceAssertionTypeValueNotSet}
}

func ResourceShowOutputValuePresent(fieldName string) ResourceAssertion {
return ResourceAssertion{fieldName: showOutputPrefix + fieldName, resourceAssertionType: resourceAssertionTypeValuePresent}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading