compute_tax_function_test.go 1.4 KB

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