From 9eb96e77a165f0236f2c802395d56ee88e381ea6 Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Tue, 14 Apr 2020 07:36:33 +0200 Subject: [PATCH] Don't assume a fixed windows drive letter in tests Prior to this change, this test was failing for me on a new windows machine, with mismatching drive letters: helpers_test.go:20: (C:/Users/Foo Bar/cli/altsrc/flag_test.go:195) Expected C:\path\to\source\hello (type string) - Got D:\path\to\source\hello (type string) Rather than hard-coding the drive letter in the expected path, we can expect the filepath.Abs'ed version. This should fix part of #1105. --- altsrc/flag_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/altsrc/flag_test.go b/altsrc/flag_test.go index 59292e4..2048331 100644 --- a/altsrc/flag_test.go +++ b/altsrc/flag_test.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "os" + "path/filepath" "runtime" "strings" "testing" @@ -190,7 +191,13 @@ func TestPathApplyInputSourceMethodSet(t *testing.T) { expected := "/path/to/source/hello" if runtime.GOOS == "windows" { - expected = `D:\path\to\source\hello` + var err error + // Prepend the corresponding drive letter (or UNC path?), and change + // to windows-style path: + expected, err = filepath.Abs(expected) + if err != nil { + t.Fatal(err) + } } expect(t, expected, c.String("test")) }