|
4 | 4 | package reflect
|
5 | 5 |
|
6 | 6 | import (
|
7 |
| - "context" |
8 | 7 | "fmt"
|
9 | 8 | "reflect"
|
10 | 9 | "testing"
|
11 |
| - |
12 |
| - "github.com/hashicorp/terraform-plugin-framework/path" |
13 | 10 | )
|
14 | 11 |
|
15 | 12 | func TestTrueReflectValue(t *testing.T) {
|
@@ -96,88 +93,6 @@ func TestCommaSeparatedString(t *testing.T) {
|
96 | 93 | }
|
97 | 94 | }
|
98 | 95 |
|
99 |
| -func TestGetStructTags_success(t *testing.T) { |
100 |
| - t.Parallel() |
101 |
| - |
102 |
| - type testStruct struct { |
103 |
| - ExportedAndTagged string `tfsdk:"exported_and_tagged"` |
104 |
| - unexported string //nolint:structcheck,unused |
105 |
| - unexportedAndTagged string `tfsdk:"unexported_and_tagged"` |
106 |
| - ExportedAndExcluded string `tfsdk:"-"` |
107 |
| - } |
108 |
| - |
109 |
| - res, err := getStructTags(context.Background(), reflect.ValueOf(testStruct{}), path.Empty()) |
110 |
| - if err != nil { |
111 |
| - t.Errorf("Unexpected error: %s", err) |
112 |
| - } |
113 |
| - if len(res) != 1 { |
114 |
| - t.Errorf("Unexpected result: %v", res) |
115 |
| - } |
116 |
| - if res["exported_and_tagged"] != 0 { |
117 |
| - t.Errorf("Unexpected result: %v", res) |
118 |
| - } |
119 |
| -} |
120 |
| - |
121 |
| -func TestGetStructTags_untagged(t *testing.T) { |
122 |
| - t.Parallel() |
123 |
| - type testStruct struct { |
124 |
| - ExportedAndUntagged string |
125 |
| - } |
126 |
| - _, err := getStructTags(context.Background(), reflect.ValueOf(testStruct{}), path.Empty()) |
127 |
| - if err == nil { |
128 |
| - t.Error("Expected error, got nil") |
129 |
| - } |
130 |
| - expected := `: need a struct tag for "tfsdk" on ExportedAndUntagged` |
131 |
| - if err.Error() != expected { |
132 |
| - t.Errorf("Expected error to be %q, got %q", expected, err.Error()) |
133 |
| - } |
134 |
| -} |
135 |
| - |
136 |
| -func TestGetStructTags_invalidTag(t *testing.T) { |
137 |
| - t.Parallel() |
138 |
| - type testStruct struct { |
139 |
| - InvalidTag string `tfsdk:"invalidTag"` |
140 |
| - } |
141 |
| - _, err := getStructTags(context.Background(), reflect.ValueOf(testStruct{}), path.Empty()) |
142 |
| - if err == nil { |
143 |
| - t.Errorf("Expected error, got nil") |
144 |
| - } |
145 |
| - expected := `invalidTag: invalid field name, must only use lowercase letters, underscores, and numbers, and must start with a letter` |
146 |
| - if err.Error() != expected { |
147 |
| - t.Errorf("Expected error to be %q, got %q", expected, err.Error()) |
148 |
| - } |
149 |
| -} |
150 |
| - |
151 |
| -func TestGetStructTags_duplicateTag(t *testing.T) { |
152 |
| - t.Parallel() |
153 |
| - type testStruct struct { |
154 |
| - Field1 string `tfsdk:"my_field"` |
155 |
| - Field2 string `tfsdk:"my_field"` |
156 |
| - } |
157 |
| - _, err := getStructTags(context.Background(), reflect.ValueOf(testStruct{}), path.Empty()) |
158 |
| - if err == nil { |
159 |
| - t.Errorf("Expected error, got nil") |
160 |
| - } |
161 |
| - expected := `my_field: can't use field name for both Field1 and Field2` |
162 |
| - if err.Error() != expected { |
163 |
| - t.Errorf("Expected error to be %q, got %q", expected, err.Error()) |
164 |
| - } |
165 |
| -} |
166 |
| - |
167 |
| -func TestGetStructTags_notAStruct(t *testing.T) { |
168 |
| - t.Parallel() |
169 |
| - var testStruct string |
170 |
| - |
171 |
| - _, err := getStructTags(context.Background(), reflect.ValueOf(testStruct), path.Empty()) |
172 |
| - if err == nil { |
173 |
| - t.Errorf("Expected error, got nil") |
174 |
| - } |
175 |
| - expected := `: can't get struct tags of string, is not a struct` |
176 |
| - if err.Error() != expected { |
177 |
| - t.Errorf("Expected error to be %q, got %q", expected, err.Error()) |
178 |
| - } |
179 |
| -} |
180 |
| - |
181 | 96 | func TestIsValidFieldName(t *testing.T) {
|
182 | 97 | t.Parallel()
|
183 | 98 | tests := map[string]bool{
|
|
0 commit comments