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.
main
Mostyn Bramley-Moore 5 years ago
parent 7a390105cb
commit 9eb96e77a1

@ -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"))
}

Loading…
Cancel
Save