main_test.go 773 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 db
  5. import (
  6. "flag"
  7. "fmt"
  8. "os"
  9. "testing"
  10. "github.com/jinzhu/gorm"
  11. log "unknwon.dev/clog/v2"
  12. "gogs.io/gogs/internal/testutil"
  13. )
  14. func TestMain(m *testing.M) {
  15. flag.Parse()
  16. if !testing.Verbose() {
  17. // Remove the primary logger and register a noop logger.
  18. log.Remove(log.DefaultConsoleName)
  19. err := log.New("noop", testutil.InitNoopLogger)
  20. if err != nil {
  21. fmt.Println(err)
  22. os.Exit(1)
  23. }
  24. }
  25. os.Exit(m.Run())
  26. }
  27. func deleteTables(db *gorm.DB, tables ...interface{}) error {
  28. for _, t := range tables {
  29. err := db.Delete(t).Error
  30. if err != nil {
  31. return err
  32. }
  33. }
  34. return nil
  35. }