forked from DavidKrau/terraform-provider-simplemdm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomProfile_resource_unit_test.go
More file actions
66 lines (60 loc) · 1.62 KB
/
customProfile_resource_unit_test.go
File metadata and controls
66 lines (60 loc) · 1.62 KB
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
package provider
import (
"testing"
"github.com/hashicorp/terraform-plugin-framework/types"
)
// TestStringValueOrNull tests the stringValueOrNull utility function
// that converts empty strings to Terraform null values for proper state management.
func TestStringValueOrNull(t *testing.T) {
tests := []struct {
name string
input string
expected types.String
}{
{
name: "non-empty string",
input: "test-value",
expected: types.StringValue("test-value"),
},
{
name: "empty string returns null",
input: "",
expected: types.StringNull(),
},
{
name: "string with spaces",
input: "value with spaces",
expected: types.StringValue("value with spaces"),
},
{
name: "string with special characters",
input: "test@example.com",
expected: types.StringValue("test@example.com"),
},
{
name: "numeric string",
input: "12345",
expected: types.StringValue("12345"),
},
{
name: "string with newline",
input: "line1\nline2",
expected: types.StringValue("line1\nline2"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := stringValueOrNull(tt.input)
// Compare null states
if result.IsNull() != tt.expected.IsNull() {
t.Errorf("stringValueOrNull() null state = %v, want %v", result.IsNull(), tt.expected.IsNull())
}
// If not null, compare values
if !result.IsNull() && !tt.expected.IsNull() {
if result.ValueString() != tt.expected.ValueString() {
t.Errorf("stringValueOrNull() = %v, want %v", result.ValueString(), tt.expected.ValueString())
}
}
})
}
}