Skip to content

Commit 20ec150

Browse files
committed
add unit tests for CheckConfigStruct
1 parent e459c4a commit 20ec150

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

component/componenttest/configtest_test.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestCheckConfigStruct(t *testing.T) {
4343
// A public type with proper tag.
4444
MyPublicInt string `mapstructure:"int"`
4545
// A public type that should be ignored.
46-
MyFunc func() error
46+
MyFunc func() error `mapstructure:"-"`
4747
// A public type that should be ignored.
4848
Reader io.Reader
4949
// private type not tagged.
@@ -176,6 +176,20 @@ func TestCheckConfigStruct(t *testing.T) {
176176
Slice []string `mapstructure:"test_slice"`
177177
}{},
178178
},
179+
{
180+
name: "invalid_function_item",
181+
config: struct {
182+
Function func() `mapstructure:"test_function"`
183+
}{},
184+
wantErrMsgSubStr: "config must be able to be marshaled to JSON and YAML, failed to marshal config: json: unsupported type: func()",
185+
},
186+
{
187+
name: "valid_ignored_function_item",
188+
config: struct {
189+
Function func() `mapstructure:"-"`
190+
Data string `mapstructure:"data"`
191+
}{},
192+
},
179193
}
180194

181195
for _, tt := range tests {

0 commit comments

Comments
 (0)