all: implement policy failover rcodes

While at it, ensure that config is validated, and fixing a bug related
to reuse ctx between multiple upstreams resolving.
This commit is contained in:
Cuong Manh Le
2022-12-14 23:34:24 +07:00
committed by Cuong Manh Le
parent fe0faac8c4
commit ccada70e31
8 changed files with 148 additions and 23 deletions
+11
View File
@@ -69,6 +69,7 @@ func TestConfigValidation(t *testing.T) {
{"invalid listener port", invalidListenerPort(t), true},
{"os upstream", configWithOsUpstream(t), false},
{"invalid rules", configWithInvalidRules(t), true},
{"invalid dns rcodes", configWithInvalidRcodes(t), true},
}
for _, tc := range tests {
@@ -155,6 +156,16 @@ func configWithInvalidRules(t *testing.T) *ctrld.Config {
return cfg
}
func configWithInvalidRcodes(t *testing.T) *ctrld.Config {
cfg := defaultConfig(t)
cfg.Listener["0"].Policy = &ctrld.ListenerPolicyConfig{
Name: "Policy with invalid Rcodes",
Networks: []ctrld.Rule{{"*.com": []string{"upstream.0"}}},
FailoverRcodes: []string{"foo"},
}
return cfg
}
func TestUpstreamConfig_Init(t *testing.T) {
tests := []struct {
name string