()
| 76 | } |
| 77 | |
| 78 | func (s *InstancesTestSuite) SetupTest() { |
| 79 | ctx := context.Background() |
| 80 | watcher.InitWatcher(ctx) |
| 81 | // create testing sqlite database |
| 82 | db, err := NewSQLDatabase(ctx, garmTesting.GetTestSqliteDBConfig(s.T())) |
| 83 | if err != nil { |
| 84 | s.FailNow(fmt.Sprintf("failed to create db connection: %s", err)) |
| 85 | } |
| 86 | s.Store = db |
| 87 | |
| 88 | adminCtx := garmTesting.ImpersonateAdminContext(ctx, db, s.T()) |
| 89 | s.adminCtx = adminCtx |
| 90 | |
| 91 | githubEndpoint := garmTesting.CreateDefaultGithubEndpoint(adminCtx, db, s.T()) |
| 92 | creds := garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), githubEndpoint) |
| 93 | |
| 94 | // create an organization for testing purposes |
| 95 | org, err := s.Store.CreateOrganization(s.adminCtx, "test-org", creds, "test-webhookSecret", params.PoolBalancerTypeRoundRobin, false) |
| 96 | if err != nil { |
| 97 | s.FailNow(fmt.Sprintf("failed to create org: %s", err)) |
| 98 | } |
| 99 | |
| 100 | // create an organization pool for testing purposes |
| 101 | createPoolParams := params.CreatePoolParams{ |
| 102 | ProviderName: "test-provider", |
| 103 | MaxRunners: 4, |
| 104 | MinIdleRunners: 2, |
| 105 | Image: "test-image", |
| 106 | Flavor: "test-flavor", |
| 107 | OSType: "linux", |
| 108 | Tags: []string{"amd64", "linux"}, |
| 109 | } |
| 110 | entity, err := org.GetEntity() |
| 111 | s.Require().Nil(err) |
| 112 | pool, err := s.Store.CreateEntityPool(s.adminCtx, entity, createPoolParams) |
| 113 | if err != nil { |
| 114 | s.FailNow(fmt.Sprintf("failed to create org pool: %s", err)) |
| 115 | } |
| 116 | |
| 117 | // create some instance objects in the database, for testing purposes |
| 118 | instances := []params.Instance{} |
| 119 | for i := 1; i <= 3; i++ { |
| 120 | instance, err := db.CreateInstance( |
| 121 | s.adminCtx, |
| 122 | pool.ID, |
| 123 | params.CreateInstanceParams{ |
| 124 | Name: fmt.Sprintf("test-instance-%d", i), |
| 125 | OSType: "linux", |
| 126 | OSArch: "amd64", |
| 127 | CallbackURL: "https://garm.example.com/", |
| 128 | Status: commonParams.InstanceRunning, |
| 129 | RunnerStatus: params.RunnerIdle, |
| 130 | JitConfiguration: map[string]string{ |
| 131 | "secret": fmt.Sprintf("secret-%d", i), |
| 132 | }, |
| 133 | AditionalLabels: []string{ |
| 134 | fmt.Sprintf("label-%d", i), |
| 135 | }, |
nothing calls this directly
no test coverage detected