MCPcopy
hub / github.com/go-gorm/gorm / init

Function init

tests/tests_test.go:30–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28)
29
30func init() {
31 var err error
32 if DB, err = OpenTestConnection(&gorm.Config{}); err != nil {
33 log.Printf("failed to connect database, got error %v", err)
34 os.Exit(1)
35 } else {
36 sqlDB, err := DB.DB()
37 if err != nil {
38 log.Printf("failed to connect database, got error %v", err)
39 os.Exit(1)
40 }
41
42 err = sqlDB.Ping()
43 if err != nil {
44 log.Printf("failed to ping sqlDB, got error %v", err)
45 os.Exit(1)
46 }
47
48 RunMigrations()
49 }
50}
51
52func OpenTestConnection(cfg *gorm.Config) (db *gorm.DB, err error) {
53 dbDSN := os.Getenv("GORM_DSN")

Callers

nothing calls this directly

Calls 5

OpenTestConnectionFunction · 0.85
RunMigrationsFunction · 0.85
PrintfMethod · 0.80
DBMethod · 0.80
PingMethod · 0.45

Tested by

no test coverage detected