From a343a8e07fe92a16c9468457421fbcbd35b29e90 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Sat, 7 Mar 2020 13:15:37 -0800 Subject: [PATCH] Fix missing windows test case, fmt --- commands.go | 2 +- hostess/hostfile_test.go | 12 +++++++++++- hostess/hostlist_test.go | 6 ++---- main.go | 2 +- main_test.go | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/commands.go b/commands.go index 8793a1a..5de8683 100644 --- a/commands.go +++ b/commands.go @@ -12,7 +12,7 @@ import ( ) type Options struct { - Preview bool + Preview bool } // PrintErrLn will print to stderr followed by a newline diff --git a/hostess/hostfile_test.go b/hostess/hostfile_test.go index 21244dc..1a787b4 100644 --- a/hostess/hostfile_test.go +++ b/hostess/hostfile_test.go @@ -61,12 +61,22 @@ func TestFormatHostfile(t *testing.T) { // 1. We want localhost entries at the top // 2. The rest are sorted by IP as STRINGS, not numeric values, so 10 // precedes 8 - const expected = `127.0.0.1 localhost devsite + expected := `127.0.0.1 localhost devsite 127.0.1.1 ip-10-37-12-18 # 8.8.8.8 google.com 10.37.12.18 devsite.com m.devsite.com ` + if runtime.GOOS == "windows" { + expected = `127.0.0.1 localhost +127.0.0.1 devsite +127.0.1.1 ip-10-37-12-18 +# 8.8.8.8 google.com +10.37.12.18 devsite.com +10.37.12.18 m.devsite.com +` + } + hostfile := hostess.NewHostfile() hostfile.Path = "./hosts" hostfile.Hosts.Add(hostess.MustHostname("localhost", "127.0.0.1", true)) diff --git a/hostess/hostlist_test.go b/hostess/hostlist_test.go index 751f527..3ef3c80 100644 --- a/hostess/hostlist_test.go +++ b/hostess/hostlist_test.go @@ -107,7 +107,6 @@ func TestFormatLinux(t *testing.T) { t.Fatal(errs) } - expected, err := ioutil.ReadFile(filepath.Join("testdata", "expected-linux")) if err != nil { t.Fatal(err) @@ -116,7 +115,7 @@ func TestFormatLinux(t *testing.T) { output := hostfile.Hosts.FormatLinux() if !bytes.Equal(output, expected) { - t.Errorf("---- Expected ----\n%s\n---- Found----\n%s\n", expected, output) + t.Error(Diff(string(expected), string(output))) } } @@ -138,11 +137,10 @@ func TestFormatWindows(t *testing.T) { output := hostfile.Hosts.FormatWindows() if !bytes.Equal(output, expected) { - t.Errorf("---- Expected ----\n%s\n---- Found----\n%s\n", expected, output) + t.Error(Diff(string(expected), string(output))) } } - func TestFormat(t *testing.T) { hosts := hostess.NewHostlist() hosts.Add(hostess.MustHostname(domain, ip, false)) diff --git a/main.go b/main.go index a85fccf..8e6c9fc 100644 --- a/main.go +++ b/main.go @@ -75,7 +75,7 @@ func wrappedMain(args []string) error { } options := &Options{ - Preview: *preview, + Preview: *preview, } command := cli.Arg(0) diff --git a/main_test.go b/main_test.go index a5d5045..550323a 100644 --- a/main_test.go +++ b/main_test.go @@ -164,7 +164,7 @@ ff02::1 ip6-allnodes ff02::2 ip6-allrouters ` - if runtime.GOOS== "windows" { + if runtime.GOOS == "windows" { expected = `127.0.0.1 localhost 127.0.1.1 ubuntu ::1 ip6-localhost