MCPcopy Create free account
hub / github.com/cloudbase/garm / SetupTest

Method SetupTest

database/sql/enterprise_test.go:86–186  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

84}
85
86func (s *EnterpriseTestSuite) SetupTest() {
87 ctx := context.Background()
88 watcher.InitWatcher(ctx)
89 // create testing sqlite database
90 db, err := NewSQLDatabase(ctx, garmTesting.GetTestSqliteDBConfig(s.T()))
91 if err != nil {
92 s.FailNow(fmt.Sprintf("failed to create db connection: %s", err))
93 }
94 s.Store = db
95
96 adminCtx := garmTesting.ImpersonateAdminContext(ctx, db, s.T())
97 s.adminCtx = adminCtx
98 s.adminUserID = auth.UserID(adminCtx)
99 s.Require().NotEmpty(s.adminUserID)
100
101 s.githubEndpoint = garmTesting.CreateDefaultGithubEndpoint(adminCtx, db, s.T())
102 s.ghesEndpoint = garmTesting.CreateGHESEndpoint(adminCtx, db, s.T())
103 s.testCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), s.githubEndpoint)
104 s.ghesCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "ghes-creds", db, s.T(), s.ghesEndpoint)
105 s.secondaryTestCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "secondary-creds", db, s.T(), s.githubEndpoint)
106
107 // create some enterprise objects in the database, for testing purposes
108 enterprises := []params.Enterprise{}
109 for i := 1; i <= 3; i++ {
110 enterprise, err := db.CreateEnterprise(
111 s.adminCtx,
112 fmt.Sprintf("test-enterprise-%d", i),
113 s.testCreds,
114 fmt.Sprintf("test-webhook-secret-%d", i),
115 params.PoolBalancerTypeRoundRobin,
116 false,
117 )
118 if err != nil {
119 s.FailNow(fmt.Sprintf("failed to create database object (test-enterprise-%d): %q", i, err))
120 }
121
122 enterprises = append(enterprises, enterprise)
123 }
124
125 // create store with mocked sql connection
126 sqlDB, sqlMock, err := sqlmock.New()
127 if err != nil {
128 s.FailNow(fmt.Sprintf("failed to run 'sqlmock.New()', got error: %v", err))
129 }
130 s.T().Cleanup(func() { sqlDB.Close() })
131 mysqlConfig := mysql.Config{
132 Conn: sqlDB,
133 SkipInitializeWithVersion: true,
134 }
135 gormConfig := &gorm.Config{}
136 if flag.Lookup("test.v").Value.String() == falseString {
137 gormConfig.Logger = logger.Default.LogMode(logger.Silent)
138 }
139 gormConn, err := gorm.Open(mysql.New(mysqlConfig), gormConfig)
140 if err != nil {
141 s.FailNow(fmt.Sprintf("fail to open gorm connection: %v", err))
142 }
143 s.StoreSQLMocked = &sqlDatabase{

Callers

nothing calls this directly

Calls 6

InitWatcherFunction · 0.92
UserIDFunction · 0.92
NewSQLDatabaseFunction · 0.85
CreateEnterpriseMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected