golden.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package testutil
  5. import (
  6. "encoding/json"
  7. "flag"
  8. "io/ioutil"
  9. "regexp"
  10. "runtime"
  11. "testing"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. var updateRegex = flag.String("update", "", "Update testdata of tests matching the given regex")
  15. // Update returns true if update regex mathces given test name.
  16. func Update(name string) bool {
  17. if updateRegex == nil || *updateRegex == "" {
  18. return false
  19. }
  20. return regexp.MustCompile(*updateRegex).MatchString(name)
  21. }
  22. // AssertGolden compares what's got and what's in the golden file. It updates
  23. // the golden file on-demand. It does nothing when the runtime is "windows".
  24. func AssertGolden(t testing.TB, path string, update bool, got interface{}) {
  25. if runtime.GOOS == "windows" {
  26. return
  27. }
  28. t.Helper()
  29. data := marshal(t, got)
  30. if update {
  31. if err := ioutil.WriteFile(path, data, 0640); err != nil {
  32. t.Fatalf("update golden file %q: %s", path, err)
  33. }
  34. }
  35. golden, err := ioutil.ReadFile(path)
  36. if err != nil {
  37. t.Fatalf("read golden file %q: %s", path, err)
  38. }
  39. assert.Equal(t, string(golden), string(data))
  40. }
  41. func marshal(t testing.TB, v interface{}) []byte {
  42. t.Helper()
  43. switch v2 := v.(type) {
  44. case string:
  45. return []byte(v2)
  46. case []byte:
  47. return v2
  48. default:
  49. data, err := json.MarshalIndent(v, "", " ")
  50. if err != nil {
  51. t.Fatal(err)
  52. }
  53. return data
  54. }
  55. }
PANIC: session(release): write data/sessions/5/e/5e92c98fecc383b7: no space left on device

PANIC

session(release): write data/sessions/5/e/5e92c98fecc383b7: no space left on device
github.com/go-macaron/session@v0.0.0-20190805070824-1a3cdc6f5659/session.go:199 (0x8b2934)
gopkg.in/macaron.v1@v1.3.9/context.go:79 (0x83d0a0)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x84fdb5)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x84fda8)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x840c73)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x850fc6)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x8493e5)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x841fca)
net/http/server.go:2836 (0x7a79b2)
net/http/server.go:1924 (0x7a341b)
runtime/asm_amd64.s:1373 (0x46f9f0)