1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:44:41 -07:00

cmd/go/internal/fsys: improve initOverlay test helper

1. Remove the use of fmt.Sprintf from t.Fatal.

2. Check for errors from initFromJSON.

3. Move 'overlay=0' to a separate cleanup function, for clarity.

Change-Id: I4d0daad248e8f26b6f159b4cc7e77fd60dc1ed98
Reviewed-on: https://go-review.googlesource.com/c/go/+/527700
Auto-Submit: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
Kir Kolyshkin 2023-09-12 18:36:44 -07:00 committed by Gopher Robot
parent d5138e580c
commit 77a1104975

View File

@ -7,7 +7,6 @@ package fsys
import (
"encoding/json"
"errors"
"fmt"
"internal/testenv"
"internal/txtar"
"io"
@ -38,7 +37,6 @@ func initOverlay(t *testing.T, config string) {
t.Fatal(err)
}
t.Cleanup(func() {
overlay = nil
if err := os.Chdir(prevwd); err != nil {
t.Fatal(err)
}
@ -57,10 +55,13 @@ func initOverlay(t *testing.T, config string) {
var overlayJSON OverlayJSON
if err := json.Unmarshal(a.Comment, &overlayJSON); err != nil {
t.Fatal(fmt.Errorf("parsing overlay JSON: %v", err))
t.Fatal("parsing overlay JSON:", err)
}
initFromJSON(overlayJSON)
if err := initFromJSON(overlayJSON); err != nil {
t.Fatal(err)
}
t.Cleanup(func() { overlay = nil })
}
func TestIsDir(t *testing.T) {