(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestDatabaseEnvironment(t *testing.T) { |
| 16 | a := require.New(t) |
| 17 | ctx := context.Background() |
| 18 | ctl := &controller{} |
| 19 | ctx, err := ctl.StartServerWithExternalPg(ctx) |
| 20 | a.NoError(err) |
| 21 | defer ctl.Close(ctx) |
| 22 | |
| 23 | instanceRootDir := t.TempDir() |
| 24 | instanceName := "testInstance1" |
| 25 | instanceDir, err := ctl.provisionSQLiteInstance(instanceRootDir, instanceName) |
| 26 | a.NoError(err) |
| 27 | |
| 28 | prodEnvironment, err := ctl.getEnvironment(ctx, "prod") |
| 29 | a.NoError(err) |
| 30 | testEnvironment, err := ctl.getEnvironment(ctx, "test") |
| 31 | a.NoError(err) |
| 32 | |
| 33 | instanceResp, err := ctl.instanceServiceClient.CreateInstance(ctx, connect.NewRequest(&v1pb.CreateInstanceRequest{ |
| 34 | InstanceId: generateRandomString("instance"), |
| 35 | Instance: &v1pb.Instance{ |
| 36 | Title: "test", |
| 37 | Engine: v1pb.Engine_SQLITE, |
| 38 | Environment: new(prodEnvironment.Name), |
| 39 | Activation: true, |
| 40 | DataSources: []*v1pb.DataSource{{Type: v1pb.DataSourceType_ADMIN, Id: "admin-ds", Host: instanceDir}}, |
| 41 | }, |
| 42 | })) |
| 43 | a.NoError(err) |
| 44 | instance := instanceResp.Msg |
| 45 | |
| 46 | db0Name := "db0" |
| 47 | err = ctl.createDatabase(ctx, ctl.project, instance, testEnvironment /* environment */, db0Name, "") |
| 48 | a.NoError(err) |
| 49 | db0Resp, err := ctl.databaseServiceClient.GetDatabase(ctx, connect.NewRequest(&v1pb.GetDatabaseRequest{ |
| 50 | Name: fmt.Sprintf("%s/databases/%s", instance.Name, db0Name), |
| 51 | })) |
| 52 | a.NoError(err) |
| 53 | db0 := db0Resp.Msg |
| 54 | a.NotNil(db0.Environment) |
| 55 | a.Equal(testEnvironment.Name, *db0.Environment) |
| 56 | a.NotNil(db0.EffectiveEnvironment) |
| 57 | a.Equal(testEnvironment.Name, *db0.EffectiveEnvironment) |
| 58 | |
| 59 | db1Name := "db1" |
| 60 | err = ctl.createDatabase(ctx, ctl.project, instance, nil /* environment */, db1Name, "") |
| 61 | a.NoError(err) |
| 62 | db1Resp, err := ctl.databaseServiceClient.GetDatabase(ctx, connect.NewRequest(&v1pb.GetDatabaseRequest{ |
| 63 | Name: fmt.Sprintf("%s/databases/%s", instance.Name, db1Name), |
| 64 | })) |
| 65 | a.NoError(err) |
| 66 | db1 := db1Resp.Msg |
| 67 | a.Nil(db1.Environment) |
| 68 | a.NotNil(db1.EffectiveEnvironment) |
| 69 | a.Equal(prodEnvironment.Name, *db1.EffectiveEnvironment) |
| 70 | |
| 71 | db2Name := "db2" |
| 72 | err = ctl.createDatabase(ctx, ctl.project, instance, nil /* environment */, db2Name, "") |
nothing calls this directly
no test coverage detected