compute_tax_function_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package provider
  2. import (
  3. "regexp"
  4. "testing"
  5. "github.com/hashicorp/terraform-plugin-testing/helper/resource"
  6. "github.com/hashicorp/terraform-plugin-testing/tfversion"
  7. )
  8. func TestComputeTaxFunction_Known(t *testing.T) {
  9. // Should only be used for resource that don't have any external dependencies.
  10. resource.UnitTest(t, resource.TestCase{
  11. TerraformVersionChecks: []tfversion.TerraformVersionCheck{
  12. tfversion.SkipBelow(tfversion.Version1_8_0), // Functions were introduced in 1.8.0
  13. },
  14. ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
  15. Steps: []resource.TestStep{
  16. {
  17. Config: `output "test" {
  18. value = provider::hashicups::compute_tax(5.00, 0.085)
  19. }`,
  20. Check: resource.ComposeAggregateTestCheckFunc(
  21. resource.TestCheckOutput("test", "5.43")), // 5*1.085 == 5.425
  22. },
  23. },
  24. })
  25. }
  26. func TestComputeTaxFunction_Null(t *testing.T) {
  27. resource.UnitTest(t, resource.TestCase{
  28. TerraformVersionChecks: []tfversion.TerraformVersionCheck{
  29. tfversion.SkipBelow(tfversion.Version1_8_0),
  30. },
  31. ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
  32. Steps: []resource.TestStep{
  33. {
  34. Config: `output "test" {
  35. value = provider::hashicups::compute_tax(null, 0.085)
  36. }`,
  37. ExpectError: regexp.MustCompile(`argument must not be null`),
  38. },
  39. },
  40. })
  41. }