TestGitOpsCheckAppliedButChanged tests that CheckRelease detects files that have been applied but with different content.
(t *testing.T)
| 1173 | |
| 1174 | // TestGitOpsCheckAppliedButChanged tests that CheckRelease detects files that have been applied but with different content. |
| 1175 | func TestGitOpsCheckAppliedButChanged(t *testing.T) { |
| 1176 | t.Parallel() |
| 1177 | a := require.New(t) |
| 1178 | ctx := context.Background() |
| 1179 | ctl := &controller{} |
| 1180 | ctx, err := ctl.StartServerWithExternalPg(ctx) |
| 1181 | a.NoError(err) |
| 1182 | defer ctl.Close(ctx) |
| 1183 | |
| 1184 | // Create a project for GitOps testing. |
| 1185 | projectID := generateRandomString("gitops-changed") |
| 1186 | projectResp, err := ctl.projectServiceClient.CreateProject(ctx, connect.NewRequest(&v1pb.CreateProjectRequest{ |
| 1187 | Project: &v1pb.Project{ |
| 1188 | Name: fmt.Sprintf("projects/%s", projectID), |
| 1189 | Title: projectID, |
| 1190 | AllowSelfApproval: true, |
| 1191 | }, |
| 1192 | ProjectId: projectID, |
| 1193 | })) |
| 1194 | a.NoError(err) |
| 1195 | project := projectResp.Msg |
| 1196 | |
| 1197 | // Provision test instance. |
| 1198 | instanceRootDir := t.TempDir() |
| 1199 | testInstanceDir, err := ctl.provisionSQLiteInstance(instanceRootDir, "gitops-changed-test") |
| 1200 | a.NoError(err) |
| 1201 | |
| 1202 | // Add the provisioned instance. |
| 1203 | testInstanceResp, err := ctl.instanceServiceClient.CreateInstance(ctx, connect.NewRequest(&v1pb.CreateInstanceRequest{ |
| 1204 | InstanceId: generateRandomString("instance"), |
| 1205 | Instance: &v1pb.Instance{ |
| 1206 | Title: "gitops-changed-test", |
| 1207 | Engine: v1pb.Engine_SQLITE, |
| 1208 | Environment: new("environments/test"), |
| 1209 | Activation: true, |
| 1210 | DataSources: []*v1pb.DataSource{{Type: v1pb.DataSourceType_ADMIN, Host: testInstanceDir, Id: "admin"}}, |
| 1211 | }, |
| 1212 | })) |
| 1213 | a.NoError(err) |
| 1214 | testInstance := testInstanceResp.Msg |
| 1215 | |
| 1216 | // Create database. |
| 1217 | databaseName := "gitops_changed_db" |
| 1218 | err = ctl.createDatabase(ctx, project, testInstance, nil, databaseName, "") |
| 1219 | a.NoError(err) |
| 1220 | |
| 1221 | // Step 1: Create a release with version 1.0.0 file. |
| 1222 | originalRelease := &v1pb.Release{ |
| 1223 | Type: v1pb.Release_VERSIONED, |
| 1224 | Files: []*v1pb.Release_File{ |
| 1225 | { |
| 1226 | Path: "migrations/1.0.0__create_users_table.sql", |
| 1227 | Version: "1.0.0", |
| 1228 | Statement: []byte(`CREATE TABLE users ( |
| 1229 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 1230 | username TEXT NOT NULL, |
| 1231 | email TEXT NOT NULL |
| 1232 | );`), |
nothing calls this directly
no test coverage detected