main_test.go 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2022 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 and LICENSE.gogs file.
  4. // Copyright 2025 Huan-Gogs Authors. All rights reserved.
  5. // Use of this source code is governed by a MIT-style
  6. // license that can be found in the LICENSE file.
  7. package migrations
  8. import (
  9. "flag"
  10. "fmt"
  11. "os"
  12. "testing"
  13. "gorm.io/gorm/logger"
  14. _ "modernc.org/sqlite"
  15. log "unknwon.dev/clog/v2"
  16. "github.com/SongZihuan/huan-gogs/internal/testutil"
  17. )
  18. func TestMain(m *testing.M) {
  19. flag.Parse()
  20. level := logger.Silent
  21. if !testing.Verbose() {
  22. // Remove the primary logger and register a noop logger.
  23. log.Remove(log.DefaultConsoleName)
  24. err := log.New("noop", testutil.InitNoopLogger)
  25. if err != nil {
  26. fmt.Println(err)
  27. os.Exit(1)
  28. }
  29. } else {
  30. level = logger.Info
  31. }
  32. // NOTE: AutoMigrate does not respect logger passed in gorm.Config.
  33. logger.Default = logger.Default.LogMode(level)
  34. os.Exit(m.Run())
  35. }