// Copyright 2020 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. package db import ( "flag" "fmt" "io/ioutil" "os" "path/filepath" "testing" "time" "github.com/jinzhu/gorm" log "unknwon.dev/clog/v2" "gogs.io/gogs/internal/conf" "gogs.io/gogs/internal/dbutil" "gogs.io/gogs/internal/testutil" ) var printSQL = flag.Bool("print-sql", false, "Print SQL executed") func TestMain(m *testing.M) { flag.Parse() if !testing.Verbose() { // Remove the primary logger and register a noop logger. log.Remove(log.DefaultConsoleName) err := log.New("noop", testutil.InitNoopLogger) if err != nil { fmt.Println(err) os.Exit(1) } } now := time.Now().UTC().Truncate(time.Second) gorm.NowFunc = func() time.Time { return now } os.Exit(m.Run()) } // clearTables removes all rows from given tables. func clearTables(t *testing.T, db *gorm.DB, tables ...interface{}) error { if t.Failed() { return nil } for _, t := range tables { err := db.Delete(t).Error if err != nil { return err } } return nil } func initTestDB(t *testing.T, suite string, tables ...interface{}) *gorm.DB { t.Helper() dbpath := filepath.Join(os.TempDir(), fmt.Sprintf("gogs-%s-%d.db", suite, time.Now().Unix())) db, err := openDB(conf.DatabaseOpts{ Type: "sqlite3", Path: dbpath, }) if err != nil { t.Fatal(err) } t.Cleanup(func() { _ = db.Close() if t.Failed() { t.Logf("Database %q left intact for inspection", dbpath) return } _ = os.Remove(dbpath) }) db.SingularTable(true) if !testing.Verbose() { db.SetLogger(&dbutil.Writer{Writer: ioutil.Discard}) } if *printSQL { db.LogMode(true) } err = db.AutoMigrate(tables...).Error if err != nil { t.Fatal(err) } return db } PANIC: session(release): write data/sessions/c/d/cd15f1f3a18ad57d: no space left on device

PANIC

session(release): write data/sessions/c/d/cd15f1f3a18ad57d: 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)