From e404a691237c06e86cf16f8657cd1298d0fb81a4 Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Mon, 25 Aug 2014 22:23:56 -0700 Subject: [PATCH] pkg/networkfs/etchosts: tests for Update method Docker-DCO-1.1-Signed-off-by: Erik Hollensbe (github: erikh) --- networkfs/etchosts/etchosts_test.go | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/networkfs/etchosts/etchosts_test.go b/networkfs/etchosts/etchosts_test.go index 44406c8..05a4f44 100644 --- a/networkfs/etchosts/etchosts_test.go +++ b/networkfs/etchosts/etchosts_test.go @@ -72,3 +72,37 @@ func TestBuildNoIP(t *testing.T) { t.Fatalf("Expected to find '%s' got '%s'", expected, content) } } + +func TestUpdate(t *testing.T) { + file, err := ioutil.TempFile("", "") + if err != nil { + t.Fatal(err) + } + defer os.Remove(file.Name()) + + if err := Build(file.Name(), "10.11.12.13", "testhostname", "testdomainname", nil); err != nil { + t.Fatal(err) + } + + content, err := ioutil.ReadFile(file.Name()) + if err != nil { + t.Fatal(err) + } + + if expected := "10.11.12.13\ttesthostname.testdomainname testhostname\n"; !bytes.Contains(content, []byte(expected)) { + t.Fatalf("Expected to find '%s' got '%s'", expected, content) + } + + if err := Update(file.Name(), "1.1.1.1", "testhostname"); err != nil { + t.Fatal(err) + } + + content, err = ioutil.ReadFile(file.Name()) + if err != nil { + t.Fatal(err) + } + + if expected := "1.1.1.1\ttesthostname.testdomainname testhostname\n"; !bytes.Contains(content, []byte(expected)) { + t.Fatalf("Expected to find '%s' got '%s'", expected, content) + } +}