aboutsummaryrefslogtreecommitdiff
path: root/internal/testutil
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-05-04 16:25:57 +0800
committerGitHub <noreply@github.com>2020-05-04 16:25:57 +0800
commit9bb218734c53c98a13264c2f4f479e3633ccfe18 (patch)
treef32557409337e18d9f7959dcb2089f0bf698513b /internal/testutil
parent82ffca3fc9988345016c8033f7f65c5b028dfe10 (diff)
db: use GORM to backup and restore non-legacy tables (#6142)
Diffstat (limited to 'internal/testutil')
-rw-r--r--internal/testutil/golden.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/internal/testutil/golden.go b/internal/testutil/golden.go
index 15ac095f..7f0295a0 100644
--- a/internal/testutil/golden.go
+++ b/internal/testutil/golden.go
@@ -8,6 +8,8 @@ import (
"encoding/json"
"flag"
"io/ioutil"
+ "os"
+ "path/filepath"
"regexp"
"runtime"
"testing"
@@ -17,7 +19,7 @@ import (
var updateRegex = flag.String("update", "", "Update testdata of tests matching the given regex")
-// Update returns true if update regex mathces given test name.
+// Update returns true if update regex matches given test name.
func Update(name string) bool {
if updateRegex == nil || *updateRegex == "" {
return false
@@ -38,14 +40,20 @@ func AssertGolden(t testing.TB, path string, update bool, got interface{}) {
data := marshal(t, got)
if update {
- if err := ioutil.WriteFile(path, data, 0640); err != nil {
- t.Fatalf("update golden file %q: %s", path, err)
+ err := os.MkdirAll(filepath.Dir(path), os.ModePerm)
+ if err != nil {
+ t.Fatalf("create directories for golden file %q: %v", path, err)
+ }
+
+ err = ioutil.WriteFile(path, data, 0640)
+ if err != nil {
+ t.Fatalf("update golden file %q: %v", path, err)
}
}
golden, err := ioutil.ReadFile(path)
if err != nil {
- t.Fatalf("read golden file %q: %s", path, err)
+ t.Fatalf("read golden file %q: %v", path, err)
}
assert.Equal(t, string(golden), string(data))