Remove non-wrapper Save/Load from result.go Removes the non-OSWrapper versions of Save and Load from //tools/src/cts/result/result.go and updates all callers. Any test coverage that is now possible as a result of this will be added in follow-up CLs. Bug: 344014313 Change-Id: I0089c637ba0ed263c97e49c0c02b1ac1fbc2396e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/280256 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org> Auto-Submit: Brian Sheedy <bsheedy@google.com>
diff --git a/tools/src/cmd/cts/common/results.go b/tools/src/cmd/cts/common/results.go index 4c1e17f..7553d18 100644 --- a/tools/src/cmd/cts/common/results.go +++ b/tools/src/cmd/cts/common/results.go
@@ -114,7 +114,7 @@ // If a file was specified, then load that. if r.File != "" { - return result.LoadWithWrapper(r.File, cfg.OsWrapper) + return result.Load(r.File, cfg.OsWrapper) } // Initialize the buildbucket and resultdb clients @@ -233,7 +233,7 @@ path := filepath.Join(dir, strconv.Itoa(ps.Change), fmt.Sprintf("ps-%v%v.txt", ps.Patchset, fileSuffix)) if _, err := cfg.OsWrapper.Stat(path); err == nil { log.Printf("loading cached results from cl %v ps %v...", ps.Change, ps.Patchset) - return result.LoadWithWrapper(path, cfg.OsWrapper) + return result.Load(path, cfg.OsWrapper) } cachePath = path } @@ -251,7 +251,7 @@ resultsByExecutionMode[i] = results } - if err := result.SaveWithWrapper(cachePath, resultsByExecutionMode, cfg.OsWrapper); err != nil { + if err := result.Save(cachePath, resultsByExecutionMode, cfg.OsWrapper); err != nil { log.Println("failed to save results to cache: %w", err) } @@ -645,7 +645,7 @@ path := filepath.Join(dir, "expectation-affected-ci-results", fmt.Sprintf("%d-%d-%d.txt", year, month, day)) if _, err := osWrapper.Stat(path); err == nil { log.Println("loading cached results for today") - return result.LoadWithWrapper(path, osWrapper) + return result.Load(path, osWrapper) } cachePath = path } @@ -663,7 +663,7 @@ resultsByExecutionMode[i] = results } - if err := result.SaveWithWrapper(cachePath, resultsByExecutionMode, osWrapper); err != nil { + if err := result.Save(cachePath, resultsByExecutionMode, osWrapper); err != nil { log.Printf("failed to save results to cache: %v", err) }
diff --git a/tools/src/cmd/cts/common/results_test.go b/tools/src/cmd/cts/common/results_test.go index 26d15c4..d071847 100644 --- a/tools/src/cmd/cts/common/results_test.go +++ b/tools/src/cmd/cts/common/results_test.go
@@ -114,7 +114,7 @@ expectedResults := result.ResultsByExecutionMode{ "execution_mode": resultsList, } - err := result.SaveWithWrapper("results.txt", expectedResults, wrapper) + err := result.Save("results.txt", expectedResults, wrapper) require.NoErrorf(t, err, "Got error writing results: %v", err) var resultsByExecutionMode result.ResultsByExecutionMode @@ -206,7 +206,7 @@ } cachePath := filepath.Join(cacheDir, partialCacheFilePath) - err := result.SaveWithWrapper(cachePath, cachedResults, wrapper) + err := result.Save(cachePath, cachedResults, wrapper) require.NoErrorf(t, err, "Got error writing results: %v", err) resultsByExecutionMode, err := testedFunc(ctx, cfg, patchset, cacheDir, client, BuildsByName{}) @@ -1345,7 +1345,7 @@ // exact time the day changes so the file is created on a different day than // it's read, but that seems exceedingly unlikely in practice. year, month, day := time.Now().Date() - result.SaveWithWrapper( + result.Save( filepath.Join( fileutils.ThisDir(), "expectation-affected-ci-results", @@ -1376,7 +1376,7 @@ }) year, month, day := time.Now().Date() - result.SaveWithWrapper( + result.Save( filepath.Join( "expectation-affected-ci-results", fmt.Sprintf("%d-%d-%d.txt", year, month, day)),
diff --git a/tools/src/cmd/cts/merge/merge.go b/tools/src/cmd/cts/merge/merge.go index a0e7d58..be877d8 100644 --- a/tools/src/cmd/cts/merge/merge.go +++ b/tools/src/cmd/cts/merge/merge.go
@@ -61,7 +61,7 @@ resultsByExecutionMode := make(result.ResultsByExecutionMode) for _, path := range flag.Args() { // Load results - r, err := result.Load(path) + r, err := result.Load(path, cfg.OsWrapper) if err != nil { return fmt.Errorf("while reading '%v': %w", path, err) }
diff --git a/tools/src/cts/result/result.go b/tools/src/cts/result/result.go index 3877a26..a78ebc3 100644 --- a/tools/src/cts/result/result.go +++ b/tools/src/cts/result/result.go
@@ -32,7 +32,6 @@ "bufio" "fmt" "io" - "os" "path/filepath" "sort" "strconv" @@ -339,28 +338,7 @@ } // Load loads the result list from the file with the given path -func Load(path string) (ResultsByExecutionMode, error) { - file, err := os.Open(path) - if err != nil { - return nil, err - } - defer file.Close() - - results, err := Read(file) - if err != nil { - return nil, fmt.Errorf("while reading '%v': %w", path, err) - } - return results, nil -} - -// Identical to Load, but using the provided fsReader instead of directly using -// os. -// TODO(crbug.com/344014313): Merge this with Load once all uses have switched -// to the wrapper version. -func LoadWithWrapper( - path string, - fsReader oswrapper.FilesystemReader) (ResultsByExecutionMode, error) { - +func Load(path string, fsReader oswrapper.FilesystemReader) (ResultsByExecutionMode, error) { file, err := fsReader.Open(path) if err != nil { return nil, err @@ -375,28 +353,7 @@ } // Save saves the result list to the file with the given path -func Save(path string, results ResultsByExecutionMode) error { - dir := filepath.Dir(path) - if err := os.MkdirAll(dir, 0777); err != nil { - return err - } - file, err := os.Create(path) - if err != nil { - return err - } - defer file.Close() - return Write(file, results) -} - -// Identical to Save, but using the provided fsWriter instead of directly using -// os. -// TODO(crbug.com/344014313): Merge this with Save once all uses have switched -// to the wrapper version. -func SaveWithWrapper( - path string, - results ResultsByExecutionMode, - fsWriter oswrapper.FilesystemWriter) error { - +func Save(path string, results ResultsByExecutionMode, fsWriter oswrapper.FilesystemWriter) error { dir := filepath.Dir(path) if err := fsWriter.MkdirAll(dir, 0777); err != nil { return err
diff --git a/tools/src/cts/result/result_test.go b/tools/src/cts/result/result_test.go index 214af56..388be4d 100644 --- a/tools/src/cts/result/result_test.go +++ b/tools/src/cts/result/result_test.go
@@ -810,10 +810,10 @@ } saveLocation := filepath.Join(fileutils.ThisDir(), "cache.txt") - err := result.SaveWithWrapper(saveLocation, in, wrapper) + err := result.Save(saveLocation, in, wrapper) require.NoErrorf(t, err, "Error saving results: %v", err) - out, err := result.LoadWithWrapper(saveLocation, wrapper) + out, err := result.Load(saveLocation, wrapper) require.NoErrorf(t, err, "Error loading results: %v", err) require.Equal(t, in, out) }