-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathexample_function_test.go
86 lines (79 loc) · 2.1 KB
/
example_function_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package provider
import (
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfversion"
)
func TestExampleFunction_Known(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(tfversion.Version1_8_0),
},
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::scaffolding::example("testvalue")
}
`,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownOutputValue(
"test",
knownvalue.StringExact("testvalue"),
),
},
},
},
})
}
func TestExampleFunction_Null(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(tfversion.Version1_8_0),
},
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: `
output "test" {
value = provider::scaffolding::example(null)
}
`,
// The parameter does not enable AllowNullValue
ExpectError: regexp.MustCompile(`argument must not be null`),
},
},
})
}
func TestExampleFunction_Unknown(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(tfversion.Version1_8_0),
},
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: `
resource "terraform_data" "test" {
input = "testvalue"
}
output "test" {
value = provider::scaffolding::example(terraform_data.test.output)
}
`,
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownOutputValue(
"test",
knownvalue.StringExact("testvalue"),
),
},
},
},
})
}