diff options
author | 2019-07-25 18:53:07 +0000 | |
---|---|---|
committer | 2019-07-25 11:53:07 -0700 | |
commit | 89fa9bc61e1347c26ebfa87dc789673d049294f9 (patch) | |
tree | 836526f98e431813288e9fa8dbaf8025b3037992 /plugin/hosts/setup_test.go | |
parent | 2a41b9a93b69483298fd5933a095c40eea99529f (diff) | |
download | coredns-89fa9bc61e1347c26ebfa87dc789673d049294f9.tar.gz coredns-89fa9bc61e1347c26ebfa87dc789673d049294f9.tar.zst coredns-89fa9bc61e1347c26ebfa87dc789673d049294f9.zip |
plugin/host: don't append the names when reparsing hosts file (#3045)
The host plugin kept on adding entries instead of overwriting. Split the
inline cache off from the /etc/hosts file cache and clear /etc/hosts
file cache and re-parsing.
A bunch of other cleanup as well. Use functions defined in the plugin
package, don't re-parse strings if you don't have to and use To4() to
check the family for IP addresses. Fix all test cases a carried entries
are always fqdn-ed. Various smaller cleanup in unnessacry constants.
Fixes: #3014
Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/hosts/setup_test.go')
-rw-r--r-- | plugin/hosts/setup_test.go | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/plugin/hosts/setup_test.go b/plugin/hosts/setup_test.go index 0e3800112..fd8a8060e 100644 --- a/plugin/hosts/setup_test.go +++ b/plugin/hosts/setup_test.go @@ -100,7 +100,7 @@ func TestHostsInlineParse(t *testing.T) { tests := []struct { inputFileRules string shouldErr bool - expectedbyAddr map[string][]string + expectedaddr map[string][]string expectedFallthrough fall.F }{ { @@ -148,19 +148,20 @@ func TestHostsInlineParse(t *testing.T) { t.Fatalf("Test %d expected no errors, but got '%v'", i, err) } else if !test.shouldErr { if !h.Fall.Equal(test.expectedFallthrough) { - t.Fatalf("Test %d expected fallthrough of %v, got %v", i, test.expectedFallthrough, h.Fall) + t.Errorf("Test %d expected fallthrough of %v, got %v", i, test.expectedFallthrough, h.Fall) } - for k, expectedVal := range test.expectedbyAddr { - if val, ok := h.hmap.byAddr[k]; !ok { - t.Fatalf("Test %d expected %v, got no entry", i, k) - } else { - if len(expectedVal) != len(val) { - t.Fatalf("Test %d expected %v records for %v, got %v", i, len(expectedVal), k, len(val)) - } - for j := range expectedVal { - if expectedVal[j] != val[j] { - t.Fatalf("Test %d expected %v for %v, got %v", i, expectedVal[j], j, val[j]) - } + for k, expectedVal := range test.expectedaddr { + val, ok := h.inline.addr[k] + if !ok { + t.Errorf("Test %d expected %v, got no entry", i, k) + continue + } + if len(expectedVal) != len(val) { + t.Errorf("Test %d expected %v records for %v, got %v", i, len(expectedVal), k, len(val)) + } + for j := range expectedVal { + if expectedVal[j] != val[j] { + t.Errorf("Test %d expected %v for %v, got %v", i, expectedVal[j], j, val[j]) } } } |