diff options
author | 2016-09-16 23:49:35 -0700 | |
---|---|---|
committer | 2016-09-17 07:49:35 +0100 | |
commit | ed907d33278003072443029fef666232f16e1985 (patch) | |
tree | 79cb47e64983319376d50192dd5f1d917c8beeea /middleware/proxy/upstream_test.go | |
parent | 50d47a55a277ea3521efe822b1faea4e93610c24 (diff) | |
download | coredns-ed907d33278003072443029fef666232f16e1985.tar.gz coredns-ed907d33278003072443029fef666232f16e1985.tar.zst coredns-ed907d33278003072443029fef666232f16e1985.zip |
Fix proxy upstream parser issue and add test cases (#263)
This fix tries to fix 261 where proxy upstream parser is not
able to parse upstream correctly.
Several test cases have also been added to cover the changes
and prevent regression in the future.
This fix fixes 261.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Diffstat (limited to 'middleware/proxy/upstream_test.go')
-rw-r--r-- | middleware/proxy/upstream_test.go | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/middleware/proxy/upstream_test.go b/middleware/proxy/upstream_test.go index a589cf85e..c48b4446b 100644 --- a/middleware/proxy/upstream_test.go +++ b/middleware/proxy/upstream_test.go @@ -3,6 +3,8 @@ package proxy import ( "testing" "time" + + "github.com/mholt/caddy" ) func TestHealthCheck(t *testing.T) { @@ -75,3 +77,78 @@ func TestAllowedPaths(t *testing.T) { } } } + +func TestProxyParse(t *testing.T) { + tests := []struct { + inputUpstreams string + shouldErr bool + }{ + { + `proxy . 8.8.8.8:53`, + false, + }, + { + ` +proxy . 8.8.8.8:53 { + policy round_robin +}`, + false, + }, + { + ` +proxy . 8.8.8.8:53 { + fail_timeout 5s +}`, + false, + }, + { + ` +proxy . 8.8.8.8:53 { + max_fails 10 +}`, + false, + }, + { + ` +proxy . 8.8.8.8:53 { + health_check /health:8080 +}`, + false, + }, + { + ` +proxy . 8.8.8.8:53 { + without without +}`, + false, + }, + { + ` +proxy . 8.8.8.8:53 { + except miek.nl example.org +}`, + false, + }, + { + ` +proxy . 8.8.8.8:53 { + spray +}`, + false, + }, + { + ` +proxy . 8.8.8.8:53 { + error_option +}`, + true, + }, + } + for i, test := range tests { + c := caddy.NewTestController("dns", test.inputUpstreams) + _, err := NewStaticUpstreams(&c.Dispenser) + if (err != nil) != test.shouldErr { + t.Errorf("Test %d expected no error, got %v", i+1, err) + } + } +} |