Move abs resolution a bit earlier to make it clear where we are looking for golden output

This commit is contained in:
Ole Markus With 2020-09-05 18:28:21 +02:00
parent bac4afa3e5
commit 5e7ec64347
1 changed files with 7 additions and 7 deletions

View File

@ -33,6 +33,13 @@ import (
func AssertMatchesFile(t *testing.T, actual string, p string) {
actual = strings.TrimSpace(actual)
abs, err := filepath.Abs(p)
if err != nil {
t.Errorf("unable to get absolute path for %q: %v", p, err)
} else {
p = abs
}
expectedBytes, err := ioutil.ReadFile(p)
if err != nil {
if !os.IsNotExist(err) || os.Getenv("HACK_UPDATE_EXPECTED_IN_PLACE") == "" {
@ -69,13 +76,6 @@ func AssertMatchesFile(t *testing.T, actual string, p string) {
diffString := diff.FormatDiff(expected, actual)
t.Logf("diff:\n%s\n", diffString)
abs, err := filepath.Abs(p)
if err != nil {
t.Errorf("unable to get absolute path for %q: %v", p, err)
} else {
p = abs
}
t.Logf("to update golden output automatically, run hack/update-expected.sh")
t.Errorf("output did not match expected for %q", p)