C: &Config{},
}
tests := []struct {
- ConfigFile string
- ExpectedError string
+ input string
+ want string
}{
{
- ConfigFile: "testdata/blackbox-bad.yml",
- ExpectedError: "error parsing config file: yaml: unmarshal errors:\n line 50: field invalid_extra_field not found in type config.plain",
+ input: "testdata/blackbox-bad.yml",
+ want: "error parsing config file: yaml: unmarshal errors:\n line 50: field invalid_extra_field not found in type config.plain",
},
{
- ConfigFile: "testdata/blackbox-bad2.yml",
- ExpectedError: "error parsing config file: at most one of bearer_token & bearer_token_file must be configured",
+ input: "testdata/blackbox-bad2.yml",
+ want: "error parsing config file: at most one of bearer_token & bearer_token_file must be configured",
},
{
- ConfigFile: "testdata/invalid-dns-module.yml",
- ExpectedError: "error parsing config file: query name must be set for DNS module",
+ input: "testdata/invalid-dns-module.yml",
+ want: "error parsing config file: query name must be set for DNS module",
},
{
- ConfigFile: "testdata/invalid-dns-class.yml",
- ExpectedError: "error parsing config file: query class 'X' is not valid",
+ input: "testdata/invalid-dns-class.yml",
+ want: "error parsing config file: query class 'X' is not valid",
},
{
- ConfigFile: "testdata/invalid-dns-type.yml",
- ExpectedError: "error parsing config file: query type 'X' is not valid",
+ input: "testdata/invalid-dns-type.yml",
+ want: "error parsing config file: query type 'X' is not valid",
},
{
- ConfigFile: "testdata/invalid-http-header-match.yml",
- ExpectedError: "error parsing config file: regexp must be set for HTTP header matchers",
+ input: "testdata/invalid-http-header-match.yml",
+ want: "error parsing config file: regexp must be set for HTTP header matchers",
},
{
- ConfigFile: "testdata/invalid-http-body-match-regexp.yml",
- ExpectedError: "error parsing config file: \"Could not compile regular expression\" regexp=\":[\"",
+ input: "testdata/invalid-http-body-match-regexp.yml",
+ want: `error parsing config file: "Could not compile regular expression" regexp=":["`,
},
{
- ConfigFile: "testdata/invalid-http-body-not-match-regexp.yml",
- ExpectedError: "error parsing config file: \"Could not compile regular expression\" regexp=\":[\"",
+ input: "testdata/invalid-http-body-not-match-regexp.yml",
+ want: `error parsing config file: "Could not compile regular expression" regexp=":["`,
},
{
- ConfigFile: "testdata/invalid-http-header-match-regexp.yml",
- ExpectedError: "error parsing config file: \"Could not compile regular expression\" regexp=\":[\"",
+ input: "testdata/invalid-http-header-match-regexp.yml",
+ want: `error parsing config file: "Could not compile regular expression" regexp=":["`,
},
{
- ConfigFile: "testdata/invalid-tcp-query-response-regexp.yml",
- ExpectedError: "error parsing config file: \"Could not compile regular expression\" regexp=\":[\"",
+ input: "testdata/invalid-tcp-query-response-regexp.yml",
+ want: `error parsing config file: "Could not compile regular expression" regexp=":["`,
},
}
- for i, test := range tests {
- err := sc.ReloadConfig(test.ConfigFile)
- if err == nil {
- t.Errorf("In case %v:\nExpected:\n%v\nGot:\nnil", i, test.ExpectedError)
- continue
- }
- if err.Error() != test.ExpectedError {
- t.Errorf("In case %v:\nExpected:\n%v\nGot:\n%v", i, test.ExpectedError, err.Error())
- }
+ for _, test := range tests {
+ t.Run(test.input, func(t *testing.T) {
+ got := sc.ReloadConfig(test.input)
+ if got == nil || got.Error() != test.want {
+ t.Fatalf("ReloadConfig(%q) = %v; want %q", test.input, got, test.want)
+ }
+ })
}
}