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

Method SetupTest

database/sql/pools_test.go:65–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

63}
64
65func (s *PoolsTestSuite) SetupTest() {
66 // create testing sqlite database
67 ctx := context.Background()
68 watcher.InitWatcher(ctx)
69
70 db, err := NewSQLDatabase(context.Background(), garmTesting.GetTestSqliteDBConfig(s.T()))
71 if err != nil {
72 s.FailNow(fmt.Sprintf("failed to create db connection: %s", err))
73 }
74 s.Store = db
75 s.ctx = garmTesting.ImpersonateAdminContext(ctx, s.Store, s.T())
76
77 adminCtx := garmTesting.ImpersonateAdminContext(context.Background(), db, s.T())
78 s.adminCtx = adminCtx
79
80 githubEndpoint := garmTesting.CreateDefaultGithubEndpoint(adminCtx, db, s.T())
81 creds := garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), githubEndpoint)
82
83 // create an organization for testing purposes
84 org, err := s.Store.CreateOrganization(s.adminCtx, "test-org", creds, "test-webhookSecret", params.PoolBalancerTypeRoundRobin, false)
85 if err != nil {
86 s.FailNow(fmt.Sprintf("failed to create org: %s", err))
87 }
88
89 entity, err := org.GetEntity()
90 s.Require().Nil(err)
91 // create some pool objects in the database, for testing purposes
92 orgPools := []params.Pool{}
93 for i := 1; i <= 3; i++ {
94 pool, err := db.CreateEntityPool(
95 s.adminCtx,
96 entity,
97 params.CreatePoolParams{
98 ProviderName: "test-provider",
99 MaxRunners: 4,
100 MinIdleRunners: 2,
101 Image: fmt.Sprintf("test-image-%d", i),
102 Flavor: "test-flavor",
103 OSType: "linux",
104 Tags: []string{"amd64-linux-runner"},
105 },
106 )
107 if err != nil {
108 s.FailNow(fmt.Sprintf("cannot create org pool: %v", err))
109 }
110 orgPools = append(orgPools, pool)
111 }
112
113 // create store with mocked sql connection
114 sqlDB, sqlMock, err := sqlmock.New()
115 if err != nil {
116 s.FailNow(fmt.Sprintf("failed to run 'sqlmock.New()', got error: %v", err))
117 }
118 s.T().Cleanup(func() { sqlDB.Close() })
119 mysqlConfig := mysql.Config{
120 Conn: sqlDB,
121 SkipInitializeWithVersion: true,
122 }

Callers

nothing calls this directly

Calls 7

InitWatcherFunction · 0.92
NewSQLDatabaseFunction · 0.85
CreateOrganizationMethod · 0.65
GetEntityMethod · 0.65
CreateEntityPoolMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected