()
| 63 | } |
| 64 | |
| 65 | func (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 | } |
nothing calls this directly
no test coverage detected