[infra] Make some testutil helpers take t and not return error.
I got tired of having to put require.NoError(t, err) all over the place.
Change-Id: Ifc2c3f2e64e22e9daca90329605a4a2e891fda1f
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/371971
Reviewed-by: Eric Boren <borenet@google.com>
diff --git a/ct/go/util/ct_perf_test.go b/ct/go/util/ct_perf_test.go
index bb3f891..e41c52f 100644
--- a/ct/go/util/ct_perf_test.go
+++ b/ct/go/util/ct_perf_test.go
@@ -72,8 +72,7 @@
func TestConvertCSVToBenchData(t *testing.T) {
unittest.SmallTest(t)
- testDataDir, err := testutils.TestDataDir()
- require.NoError(t, err)
+ testDataDir := testutils.TestDataDir(t)
pathToTestCSV := filepath.Join(testDataDir, "test.csv")
perfData, err := convertCSVToBenchData(TEST_HASH, TEST_GROUP_NAME, TEST_UNIQUE_ID, pathToTestCSV)
diff --git a/go/config/config_test.go b/go/config/config_test.go
index 6e3dc2d..3ad579a 100644
--- a/go/config/config_test.go
+++ b/go/config/config_test.go
@@ -50,8 +50,7 @@
func TestParseConfigFile(t *testing.T) {
unittest.MediumTest(t)
- dir, err := testutils.TestDataDir()
- require.NoError(t, err)
+ dir := testutils.TestDataDir(t)
configFile := filepath.Join(dir, "TestParseConfigFile.json5")
parsed := TestConfig{}
require.NoError(t, ParseConfigFile(configFile, "", &parsed))
@@ -92,6 +91,7 @@
configFile := filepath.Join(dir, "nonexistent-file.json5")
parsed := TestConfig{}
err := ParseConfigFile(configFile, "--main-config", &parsed)
+ require.Error(t, err)
require.Regexp(t, `Unable to read --main-config file ".*/nonexistent-file.json5":.* no such file or directory`, err.Error())
}
@@ -103,5 +103,6 @@
require.NoError(t, ioutil.WriteFile(configFile, []byte("Hi Mom!"), os.ModePerm))
parsed := TestConfig{}
err := ParseConfigFile(configFile, "", &parsed)
+ require.Error(t, err)
require.Regexp(t, `Unable to parse file ".*/invalid.json5": invalid character 'H' looking for beginning of value`, err.Error())
}
diff --git a/go/git/gitinfo/gitinfo_test.go b/go/git/gitinfo/gitinfo_test.go
index 7dfe1c5..5aaacc3 100644
--- a/go/git/gitinfo/gitinfo_test.go
+++ b/go/git/gitinfo/gitinfo_test.go
@@ -15,7 +15,7 @@
func TestVCSSuite(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
ctx := context.Background()
@@ -26,7 +26,7 @@
func TestFrom(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
r, err := NewGitInfo(context.TODO(), repoDir, false, false)
@@ -36,7 +36,7 @@
func TestLastN(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
ctx := context.Background()
@@ -73,7 +73,7 @@
func TestByIndex(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
r, err := NewGitInfo(context.TODO(), repoDir, false, false)
@@ -83,7 +83,7 @@
func TestLastNIndex(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
r, err := NewGitInfo(context.TODO(), repoDir, false, false)
@@ -93,7 +93,7 @@
func TestIndexOf(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
ctx := context.Background()
@@ -107,7 +107,7 @@
func TestRange(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
r, err := NewGitInfo(context.TODO(), repoDir, false, false)
@@ -116,7 +116,7 @@
}
func TestLog(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
ctx := context.Background()
@@ -165,7 +165,7 @@
func TestLogFine(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
ctx := context.Background()
@@ -197,7 +197,7 @@
func TestLogArgs(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
ctx := context.Background()
@@ -218,7 +218,7 @@
func TestShortList(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
ctx := context.Background()
@@ -270,7 +270,7 @@
func TestRevList(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
ctx := context.Background()
@@ -318,7 +318,7 @@
func TestBranchInfo(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
ctx := context.Background()
@@ -338,7 +338,7 @@
func TestSetBranch(t *testing.T) {
unittest.MediumTest(t)
- repoDir, cleanup := vcstu.InitTempRepo()
+ repoDir, cleanup := vcstu.InitTempRepo(t)
defer cleanup()
ctx := context.Background()
diff --git a/go/jsonutils/jsonutils_test.go b/go/jsonutils/jsonutils_test.go
index 64fe2bd..3900f47 100644
--- a/go/jsonutils/jsonutils_test.go
+++ b/go/jsonutils/jsonutils_test.go
@@ -70,6 +70,7 @@
var got Number
err := json.Unmarshal([]byte(tc.in), &got)
if tc.err != "" {
+ require.Error(t, err)
require.Contains(t, err.Error(), tc.err)
} else {
require.NoError(t, err)
@@ -108,7 +109,7 @@
func TestMarshalStringMap_NonEmptyMap_MatchesBuiltInImpl(t *testing.T) {
unittest.MediumTest(t)
input := map[string]string{}
- testutils.MustReadJsonFile("mediumparams.json", &input)
+ testutils.ReadJSONFile(t, "mediumparams.json", &input)
require.Len(t, input, 50)
actual := MarshalStringMap(input)
expected, err := json.Marshal(input)
@@ -116,7 +117,7 @@
assert.Equal(t, expected, actual, "%s != %s", string(expected), string(actual))
input2 := map[string]string{}
- testutils.MustReadJsonFile("smallparams.json", &input2)
+ testutils.ReadJSONFile(t, "smallparams.json", &input2)
require.Len(t, input2, 10)
actual = MarshalStringMap(input2)
expected, err = json.Marshal(input2)
@@ -144,7 +145,7 @@
func BenchmarkMarshalStringMap_10Items(b *testing.B) {
input := map[string]string{}
- testutils.MustReadJsonFile("smallparams.json", &input)
+ testutils.ReadJSONFile(b, "smallparams.json", &input)
b.ResetTimer()
for i := 0; i < b.N; i++ {
b := MarshalStringMap(input)
@@ -156,7 +157,7 @@
func BenchmarkMarshalStringMap_50Items(b *testing.B) {
input := map[string]string{}
- testutils.MustReadJsonFile("mediumparams.json", &input)
+ testutils.ReadJSONFile(b, "mediumparams.json", &input)
b.ResetTimer()
for i := 0; i < b.N; i++ {
b := MarshalStringMap(input)
@@ -168,7 +169,7 @@
func BenchmarkBuiltInJSONMarshal_10Items(b *testing.B) {
input := map[string]string{}
- testutils.MustReadJsonFile("smallparams.json", &input)
+ testutils.ReadJSONFile(b, "smallparams.json", &input)
b.ResetTimer()
for i := 0; i < b.N; i++ {
b, _ := json.Marshal(input)
@@ -180,7 +181,7 @@
func BenchmarkBuiltInJSONMarshal_50Items(b *testing.B) {
input := map[string]string{}
- testutils.MustReadJsonFile("mediumparams.json", &input)
+ testutils.ReadJSONFile(b, "mediumparams.json", &input)
b.ResetTimer()
for i := 0; i < b.N; i++ {
b, _ := json.Marshal(input)
diff --git a/go/testutils/testutils.go b/go/testutils/testutils.go
index c376248..65279f2 100644
--- a/go/testutils/testutils.go
+++ b/go/testutils/testutils.go
@@ -35,16 +35,12 @@
// TestDataDir returns the path to the caller's testdata directory, which
// is assumed to be "<path to caller dir>/testdata".
-func TestDataDir() (string, error) {
+func TestDataDir(t sktest.TestingT) string {
_, thisFile, _, ok := runtime.Caller(0)
- if !ok {
- return "", fmt.Errorf("Could not find test data dir: runtime.Caller() failed.")
- }
+ require.True(t, ok, "Could not find test data dir: runtime.Caller() failed.")
for skip := 0; ; skip++ {
_, file, _, ok := runtime.Caller(skip)
- if !ok {
- return "", fmt.Errorf("Could not find test data dir: runtime.Caller() failed.")
- }
+ require.True(t, ok, "Could not find test data dir: runtime.Caller() failed.")
if file != thisFile {
// Under Bazel, the path returned by runtime.Caller() is relative to the workspace's root
// directory (e.g. "go/testutils"). We prepend this with the absolute path to the runfiles
@@ -56,82 +52,43 @@
file = filepath.Join(bazel.RunfilesDir(), file)
}
- return filepath.Join(filepath.Dir(file), "testdata"), nil
+ return filepath.Join(filepath.Dir(file), "testdata")
}
}
}
-func readFile(filename string) (io.ReadCloser, error) {
- dir, err := TestDataDir()
- if err != nil {
- return nil, fmt.Errorf("Could not read %s: %v", filename, err)
- }
- f, err := os.Open(filepath.Join(dir, filename))
- if err != nil {
- return nil, fmt.Errorf("Could not read %s: %v", filename, err)
- }
- return f, nil
-}
-
// ReadFileBytes reads a file from the caller's testdata directory and returns its contents as a
// slice of bytes.
-func ReadFileBytes(filename string) ([]byte, error) {
- f, err := readFile(filename)
- if err != nil {
- return nil, err
- }
+func ReadFileBytes(t sktest.TestingT, filename string) []byte {
+ f := GetReader(t, filename)
b, err := ioutil.ReadAll(f)
- if err != nil {
- return nil, fmt.Errorf("Could not read %s: %v", filename, err)
- }
- return b, nil
+ require.NoError(t, err, "Could not read %s: %v", filename)
+ require.NoError(t, f.Close())
+ return b
}
// ReadFile reads a file from the caller's testdata directory.
-func ReadFile(filename string) (string, error) {
- b, err := ReadFileBytes(filename)
- if err != nil {
- return "", err
- }
- return string(b), nil
+func ReadFile(t sktest.TestingT, filename string) string {
+ b := ReadFileBytes(t, filename)
+ return string(b)
}
-// MustGetReader reads a file from the caller's testdata directory and panics on
+// GetReader reads a file from the caller's testdata directory and panics on
// error.
-func MustGetReader(filename string) io.ReadCloser {
- r, err := readFile(filename)
- if err != nil {
- panic(err)
- }
- return r
+func GetReader(t sktest.TestingT, filename string) io.ReadCloser {
+ dir := TestDataDir(t)
+ f, err := os.Open(filepath.Join(dir, filename))
+ require.NoError(t, err, "Reading %s from testdir", filename)
+ return f
}
-// MustReadFile returns from the caller's testdata directory and panics on
-// error.
-func MustReadFile(filename string) string {
- s, err := ReadFile(filename)
- if err != nil {
- panic(err)
- }
- return s
-}
-
-// ReadJsonFile reads a JSON file from the caller's testdata directory into the
+// ReadJSONFile reads a JSON file from the caller's testdata directory into the
// given interface.
-func ReadJsonFile(filename string, dest interface{}) error {
- f, err := readFile(filename)
- if err != nil {
- return err
- }
- return json.NewDecoder(f).Decode(dest)
-}
-
-// MustReadJsonFile reads a JSON file from the caller's testdata directory into
-// the given interface and panics on error.
-func MustReadJsonFile(filename string, dest interface{}) {
- if err := ReadJsonFile(filename, dest); err != nil {
- panic(err)
- }
+func ReadJSONFile(t sktest.TestingT, filename string, dest interface{}) {
+ f := GetReader(t, filename)
+ err := json.NewDecoder(f).Decode(dest)
+ require.NoError(t, err, "Decoding JSON in %s", filename)
+ require.NoError(t, f.Close())
}
// WriteFile writes the given contents to the given file path, reporting any
@@ -159,6 +116,7 @@
// TempDir is a wrapper for ioutil.TempDir. Returns the path to the directory and a cleanup
// function to defer.
+// TODO(kjlubick) replace this with testing.TempDir()
func TempDir(t sktest.TestingT) (string, func()) {
d, err := ioutil.TempDir("", "testutils")
require.NoError(t, err)
diff --git a/go/vcsinfo/bt_vcs/bt_vcs_test.go b/go/vcsinfo/bt_vcs/bt_vcs_test.go
index 678b98a..742ac37 100644
--- a/go/vcsinfo/bt_vcs/bt_vcs_test.go
+++ b/go/vcsinfo/bt_vcs/bt_vcs_test.go
@@ -189,7 +189,7 @@
// setupVCSLocalRepo loads the test repo into a new GitStore and returns an instance of vcsinfo.VCS.
func setupVCSLocalRepo(t *testing.T, branch string) (vcsinfo.VCS, gitstore.GitStore, func()) {
- repoDir, cleanup := vcs_testutils.InitTempRepo()
+ repoDir, cleanup := vcs_testutils.InitTempRepo(t)
wd, err := ioutil.TempDir("", "")
require.NoError(t, err)
ctx := context.Background()
diff --git a/go/vcsinfo/testutils/repo.go b/go/vcsinfo/testutils/repo.go
index 14aac3e..af948ad 100644
--- a/go/vcsinfo/testutils/repo.go
+++ b/go/vcsinfo/testutils/repo.go
@@ -5,6 +5,8 @@
"os"
"path/filepath"
+ "go.skia.org/infra/go/sktest"
+
"go.skia.org/infra/go/sklog"
go_testutils "go.skia.org/infra/go/testutils"
"go.skia.org/infra/go/util/zip"
@@ -37,11 +39,8 @@
// newTempRepo assumes the repo is called testrepo.zip, is in a directory
// called testdata under the directory of the unit test that is calling it
// and contains a single directory 'testrepo'.
-func newTempRepo() *tempRepo {
- testDataDir, err := go_testutils.TestDataDir()
- if err != nil {
- sklog.Fatal("Failed to locate test data dir:", err)
- }
+func newTempRepo(t sktest.TestingT) *tempRepo {
+ testDataDir := go_testutils.TestDataDir(t)
ret := newTempRepoFrom(filepath.Join(testDataDir, "testrepo.zip"))
ret.Dir = filepath.Join(ret.Dir, "testrepo")
return ret
diff --git a/go/vcsinfo/testutils/vcsinfo_testutils.go b/go/vcsinfo/testutils/vcsinfo_testutils.go
index 5b603a5..b405694 100644
--- a/go/vcsinfo/testutils/vcsinfo_testutils.go
+++ b/go/vcsinfo/testutils/vcsinfo_testutils.go
@@ -17,8 +17,8 @@
// InitTempRepo creates a temporary git repository from ./testdata/testrepo.zip.
// It returns the path to the repo directory and a cleanup function that should
// be called in a deferred.
-func InitTempRepo() (string, func()) {
- tr := newTempRepo()
+func InitTempRepo(t sktest.TestingT) (string, func()) {
+ tr := newTempRepo(t)
sklog.Infof("YYY: %s", tr.Dir)
return tr.Dir, tr.Cleanup
}
diff --git a/gold-client/cmd/goldctl/cmd_diff_test.go b/gold-client/cmd/goldctl/cmd_diff_test.go
index 081c1f1..29802aa 100644
--- a/gold-client/cmd/goldctl/cmd_diff_test.go
+++ b/gold-client/cmd/goldctl/cmd_diff_test.go
@@ -23,8 +23,7 @@
workDir := t.TempDir()
setupAuthWithGSUtil(t, workDir)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
mh := &mocks.HTTPClient{}
j, err := json.Marshal(frontend.DigestListResponse{Digests: []types.Digest{a05Digest, a09Digest}})
diff --git a/gold-client/cmd/goldctl/cmd_imgtest_test.go b/gold-client/cmd/goldctl/cmd_imgtest_test.go
index 77bd8c0..552764d 100644
--- a/gold-client/cmd/goldctl/cmd_imgtest_test.go
+++ b/gold-client/cmd/goldctl/cmd_imgtest_test.go
@@ -89,8 +89,7 @@
workDir := t.TempDir()
setupAuthWithGSUtil(t, workDir)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
mh := mockRPCResponses("https://my-instance-gold.skia.org").Build()
@@ -166,8 +165,7 @@
workDir := t.TempDir()
setupAuthWithGSUtil(t, workDir)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
mh := mockRPCResponses("https://my-custom-gold-url.example.com").Build()
@@ -245,8 +243,7 @@
workDir := t.TempDir()
setupAuthWithGSUtil(t, workDir)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
mh := mockRPCResponses("https://my-instance-gold.skia.org").Positive("pixel-tests", blankDigest).Build()
@@ -314,8 +311,7 @@
workDir := t.TempDir()
setupAuthWithGSUtil(t, workDir)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
mh := mockRPCResponses("https://my-instance-gold.skia.org").Positive("pixel-tests", blankDigest).Build()
@@ -415,8 +411,7 @@
workDir := t.TempDir()
setupAuthWithGSUtil(t, workDir)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
keysFile := filepath.Join(workDir, "keys.json")
require.NoError(t, ioutil.WriteFile(keysFile, []byte(`{"os": "Android"}`), 0644))
@@ -475,8 +470,7 @@
workDir := t.TempDir()
setupAuthWithGSUtil(t, workDir)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
mh := mockRPCResponses("https://my-instance-gold.skia.org").Positive("pixel-tests", blankDigest).Build()
@@ -569,8 +563,7 @@
workDir := t.TempDir()
setupAuthWithGSUtil(t, workDir)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
mh := mockRPCResponses("https://my-instance-gold.skia.org").Build()
@@ -675,8 +668,7 @@
workDir := t.TempDir()
setupAuthWithGSUtil(t, workDir)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
mh := mockRPCResponses("https://my-instance-gold.skia.org").Positive("pixel-tests", a01Digest).
LatestPositive(a01Digest, paramtools.Params{
@@ -715,8 +707,7 @@
workDir := t.TempDir()
setupAuthWithGSUtil(t, workDir)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
mh := mockRPCResponses("https://my-instance-gold.skia.org").Positive("pixel-tests", a01Digest).
LatestPositive(a01Digest, paramtools.Params{
diff --git a/gold-client/cmd/goldctl/cmd_match_test.go b/gold-client/cmd/goldctl/cmd_match_test.go
index 4d6b27a..69fbc73 100644
--- a/gold-client/cmd/goldctl/cmd_match_test.go
+++ b/gold-client/cmd/goldctl/cmd_match_test.go
@@ -5,8 +5,6 @@
"testing"
"github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
-
"go.skia.org/infra/go/testutils"
"go.skia.org/infra/go/testutils/unittest"
"go.skia.org/infra/gold-client/go/imgmatching"
@@ -15,8 +13,7 @@
func TestMatch_Fuzzy_ImagesAreWithinTolerance_ExitCodeZero(t *testing.T) {
unittest.MediumTest(t)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
// Call imgtest match using the fuzzy match algorithm
ctx, output, exit := testContext(nil, nil, nil, nil)
@@ -43,8 +40,7 @@
func TestMatch_Sobel_ImagesAreVeryDifferent_ExitCodeZero(t *testing.T) {
unittest.MediumTest(t)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
// Call imgtest match using the fuzzy match algorithm
ctx, output, exit := testContext(nil, nil, nil, nil)
diff --git a/golden/go/config/config_test.go b/golden/go/config/config_test.go
index 77340c6..e820050 100644
--- a/golden/go/config/config_test.go
+++ b/golden/go/config/config_test.go
@@ -28,13 +28,12 @@
func TestLoadFromJSON5_Success(t *testing.T) {
unittest.MediumTest(t)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
commonPath := filepath.Join(td, "common.json5")
specificPath := filepath.Join(td, "specific.json5")
var tsc testSpecificConfig
- err = LoadFromJSON5(&tsc, &commonPath, &specificPath)
+ err := LoadFromJSON5(&tsc, &commonPath, &specificPath)
require.NoError(t, err)
assert.Equal(t, testSpecificConfig{
@@ -51,13 +50,12 @@
func TestLoadFromJSON5_WithDuration_Success(t *testing.T) {
unittest.MediumTest(t)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
commonPath := filepath.Join(td, "common.json5")
specificPath := filepath.Join(td, "specific_duration.json5")
var tsc testSpecificConfig
- err = LoadFromJSON5(&tsc, &commonPath, &specificPath)
+ err := LoadFromJSON5(&tsc, &commonPath, &specificPath)
require.NoError(t, err)
assert.Equal(t, testSpecificConfig{
@@ -75,13 +73,12 @@
func TestLoadFromJSON5_RequiredFieldMissing_Error(t *testing.T) {
unittest.MediumTest(t)
- td, err := testutils.TestDataDir()
- require.NoError(t, err)
+ td := testutils.TestDataDir(t)
commonPath := filepath.Join(td, "common_missing_field.json5")
specificPath := filepath.Join(td, "specific.json5")
var tsc testSpecificConfig
- err = LoadFromJSON5(&tsc, &commonPath, &specificPath)
+ err := LoadFromJSON5(&tsc, &commonPath, &specificPath)
require.Error(t, err)
assert.Contains(t, err.Error(), "CommonInt")
}
diff --git a/golden/go/diff/diff_test.go b/golden/go/diff/diff_test.go
index 831341a..73d9eaa 100644
--- a/golden/go/diff/diff_test.go
+++ b/golden/go/diff/diff_test.go
@@ -254,8 +254,7 @@
// openNRGBAFromFile opens the given file path to a PNG file and returns the image as image.NRGBA.
func openNRGBAFromFile(t testing.TB, fileName string) *image.NRGBA {
- b, err := testutils.ReadFileBytes(fileName)
- require.NoError(t, err, "Failed to read test image %s", fileName)
+ b := testutils.ReadFileBytes(t, fileName)
im, err := png.Decode(bytes.NewReader(b))
require.NoError(t, err, "invalid png file %s", fileName)
return GetNRGBA(im)
diff --git a/golden/go/diffstore/mem_diffstore_test.go b/golden/go/diffstore/mem_diffstore_test.go
index 1e8513a..99a86d9 100644
--- a/golden/go/diffstore/mem_diffstore_test.go
+++ b/golden/go/diffstore/mem_diffstore_test.go
@@ -53,8 +53,7 @@
func TestMD5Hash16BitImageIsCorrect(t *testing.T) {
unittest.SmallTest(t)
- b, err := testutils.ReadFileBytes(fmt.Sprintf("%s.png", digest16BitImage))
- require.NoError(t, err)
+ b := testutils.ReadFileBytes(t, fmt.Sprintf("%s.png", digest16BitImage))
require.Equal(t, md5Hash16BitImage, bytesToMD5HashString(b))
}
@@ -375,8 +374,7 @@
mockBucketClient.On("GetFileObjectAttrs", testutils.AnyContext, digest16BitImageGsPath).Return(oa3, nil)
// digest16BitImage is read.
- bytes16BitImage, err := testutils.ReadFileBytes(fmt.Sprintf("%s.png", digest16BitImage))
- require.NoError(t, err)
+ bytes16BitImage := testutils.ReadFileBytes(t, fmt.Sprintf("%s.png", digest16BitImage))
reader3 := ioutil.NopCloser(bytes.NewReader(bytes16BitImage))
mockBucketClient.On("FileReader", testutils.AnyContext, digest16BitImageGsPath).Return(reader3, nil)
diff --git a/golden/go/search/query/query_test.go b/golden/go/search/query/query_test.go
index a4e225a..ccadcfc 100644
--- a/golden/go/search/query/query_test.go
+++ b/golden/go/search/query/query_test.go
@@ -60,8 +60,7 @@
unittest.SmallTest(t)
// Load the list of of live queries.
- contents, err := testutils.ReadFile("valid_queries.txt")
- require.NoError(t, err)
+ contents := testutils.ReadFile(t, "valid_queries.txt")
queries := strings.Split(contents, "\n")
@@ -76,8 +75,7 @@
unittest.SmallTest(t)
// Load the list of of live queries.
- contents, err := testutils.ReadFile("invalid_queries.txt")
- require.NoError(t, err)
+ contents := testutils.ReadFile(t, "invalid_queries.txt")
queries := strings.Split(contents, "\n")
diff --git a/golden/go/sql/databuilder/databuilder_test.go b/golden/go/sql/databuilder/databuilder_test.go
index 43452ee..2fa8bcd 100644
--- a/golden/go/sql/databuilder/databuilder_test.go
+++ b/golden/go/sql/databuilder/databuilder_test.go
@@ -92,8 +92,7 @@
"device": []string{"NUC1234"},
})
- dir, err := testutils.TestDataDir()
- require.NoError(t, err)
+ dir := testutils.TestDataDir(t)
b.ComputeDiffMetricsFromImages(dir, "2020-12-14T14:14:14Z")
tables := b.Build()
@@ -536,8 +535,7 @@
types.PrimaryKeyField: []string{"test_two"},
})
- dir, err := testutils.TestDataDir()
- require.NoError(t, err)
+ dir := testutils.TestDataDir(t)
b.ComputeDiffMetricsFromImages(dir, "2020-12-14T14:14:14Z")
tables := b.Build()
@@ -1414,8 +1412,7 @@
func TestComputeDiffMetricsFromImages_IncompleteData_Panics(t *testing.T) {
unittest.SmallTest(t)
- testDir, err := testutils.TestDataDir()
- require.NoError(t, err)
+ testDir := testutils.TestDataDir(t)
b := TablesBuilder{}
b.SetGroupingKeys(types.CorpusField)
@@ -1437,8 +1434,7 @@
func TestComputeDiffMetricsFromImages_InvalidTime_Panics(t *testing.T) {
unittest.SmallTest(t)
- testDir, err := testutils.TestDataDir()
- require.NoError(t, err)
+ testDir := testutils.TestDataDir(t)
b := TablesBuilder{}
b.SetGroupingKeys(types.CorpusField)
diff --git a/perf/go/ingest/parser/parser_test.go b/perf/go/ingest/parser/parser_test.go
index eff11ab..f9bfcac 100644
--- a/perf/go/ingest/parser/parser_test.go
+++ b/perf/go/ingest/parser/parser_test.go
@@ -38,7 +38,7 @@
unittest.SmallTest(t)
// Load the sample data file as BenchData.
- r := testutils.MustGetReader(filepath.Join("legacy", "success.json"))
+ r := testutils.GetReader(t, filepath.Join("legacy", "success.json"))
benchData, err := format.ParseLegacyFormat(r)
require.NoError(t, err)
@@ -53,7 +53,7 @@
func TestGetParamsAndValuesFromFormat_Success(t *testing.T) {
unittest.SmallTest(t)
// Load the sample data file as BenchData.
- r := testutils.MustGetReader(filepath.Join("version_1", "success.json"))
+ r := testutils.GetReader(t, filepath.Join("version_1", "success.json"))
f, err := format.Parse(r)
require.NoError(t, err)
@@ -93,7 +93,7 @@
// Load the sample data file as BenchData.
- r := testutils.MustGetReader(filepath.Join(subdir, filename))
+ r := testutils.GetReader(t, filepath.Join(subdir, filename))
return ret, file.File{
Name: filename,
@@ -227,7 +227,7 @@
unittest.SmallTest(t)
// Load the sample data file as BenchData.
- r := testutils.MustGetReader(filepath.Join("legacy", "samples_success.json"))
+ r := testutils.GetReader(t, filepath.Join("legacy", "samples_success.json"))
b, err := format.ParseLegacyFormat(r)
require.NoError(t, err)
@@ -268,7 +268,7 @@
unittest.SmallTest(t)
// Load the sample data file as BenchData.
- r := testutils.MustGetReader(filepath.Join("legacy", "samples_no_results.json"))
+ r := testutils.GetReader(t, filepath.Join("legacy", "samples_no_results.json"))
b, err := format.ParseLegacyFormat(r)
require.NoError(t, err)
diff --git a/perf/go/trybot/ingester/gerrit/gerrit_test.go b/perf/go/trybot/ingester/gerrit/gerrit_test.go
index abc2e6a..e930fa0 100644
--- a/perf/go/trybot/ingester/gerrit/gerrit_test.go
+++ b/perf/go/trybot/ingester/gerrit/gerrit_test.go
@@ -13,7 +13,7 @@
"go.skia.org/infra/perf/go/types"
)
-var createdTime time.Time = time.Date(2020, 01, 01, 00, 00, 00, 0000, time.UTC)
+var createdTime = time.Date(2020, 01, 01, 00, 00, 00, 0000, time.UTC)
func setupForTest(t *testing.T, filename string) (*parser.Parser, file.File) {
unittest.SmallTest(t)
@@ -26,7 +26,7 @@
return p, file.File{
Name: filename,
- Contents: testutils.MustGetReader(filename),
+ Contents: testutils.GetReader(t, filename),
Created: createdTime,
}
}
diff --git a/perf/nanostat/main_test.go b/perf/nanostat/main_test.go
index 9f4867a..8d852bc 100644
--- a/perf/nanostat/main_test.go
+++ b/perf/nanostat/main_test.go
@@ -7,7 +7,6 @@
"testing"
"github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
"go.skia.org/infra/go/testutils"
"go.skia.org/infra/go/testutils/unittest"
)
@@ -15,8 +14,7 @@
func TestMain_DifferentFlags_ChangeOutput(t *testing.T) {
unittest.SmallTest(t)
- testdataDir, err := testutils.TestDataDir()
- require.NoError(t, err)
+ testdataDir := testutils.TestDataDir(t)
oldFile := filepath.Join(testdataDir, "nanobench_old.json")
newFile := filepath.Join(testdataDir, "nanobench_new.json")
@@ -38,8 +36,7 @@
var stdout bytes.Buffer
actualMain(&stdout)
- golden, err := testutils.ReadFile(name + ".golden")
- require.NoError(t, err)
+ golden := testutils.ReadFile(t, name+".golden")
assert.Equal(t, golden, stdout.String())
})
}
diff --git a/power/go/testdata/data.go b/power/go/testdata/data.go
index bd14f02..fa5a260 100644
--- a/power/go/testdata/data.go
+++ b/power/go/testdata/data.go
@@ -1,9 +1,6 @@
package testdata
import (
- "encoding/json"
-
- "github.com/stretchr/testify/require"
swarming "go.chromium.org/luci/common/api/swarming/swarming/v1"
"go.skia.org/infra/go/sktest"
"go.skia.org/infra/go/testutils"
@@ -25,11 +22,8 @@
// MockBotAndId creates a *swarming.SwarmingRpcsBotInfo using the matching JSON
// file in ./testdata
func MockBotAndId(t sktest.TestingT, filename, id string) *swarming.SwarmingRpcsBotInfo {
- j, err := testutils.ReadFile(filename)
- require.NoError(t, err, "There was a problem reading in the test data")
var s swarming.SwarmingRpcsBotInfo
- err = json.Unmarshal([]byte(j), &s)
- require.NoError(t, err, "There was a problem parsing the test data")
+ testutils.ReadJSONFile(t, filename, &s)
s.BotId = id
return &s
}
diff --git a/task_driver/go/lib/docker/docker_test.go b/task_driver/go/lib/docker/docker_test.go
index 7746f7a..ab94dbe 100644
--- a/task_driver/go/lib/docker/docker_test.go
+++ b/task_driver/go/lib/docker/docker_test.go
@@ -20,8 +20,7 @@
// Strip our PATH so we find our version of `docker` which is in the
// testdata directory. Then add `/bin` to the PATH since we are running a
// Bash shell.
- testDataDir, err := testutils.TestDataDir()
- require.NoError(t, err)
+ testDataDir := testutils.TestDataDir(t)
dockerCmd = filepath.Join(testDataDir, "docker_mock")
type args struct {