Skip to content

Commit

Permalink
Add custom instance config to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanli-ml committed Jun 2, 2021
1 parent 255ca39 commit 1c10413
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion spanner/integration_test.go
Expand Up @@ -63,6 +63,11 @@ var (
// by setting the environment variable GCLOUD_TESTS_GOLANG_SPANNER_HOST
spannerHost = getSpannerHost()

// instanceConfig specifies the instance config used to create a instance for testing.
// It can be changed by setting the environment variable
// GCLOUD_TESTS_GOLANG_SPANNER_INSTANCE_CONFIG.
instanceConfig = getInstanceConfig()

dbNameSpace = uid.NewSpace("gotest", &uid.Options{Sep: '_', Short: true})
instanceNameSpace = uid.NewSpace("gotest", &uid.Options{Sep: '-', Short: true})
backupIDSpace = uid.NewSpace("gotest", &uid.Options{Sep: '_', Short: true})
Expand Down Expand Up @@ -204,6 +209,10 @@ func getSpannerHost() string {
return os.Getenv("GCLOUD_TESTS_GOLANG_SPANNER_HOST")
}

func getInstanceConfig() string {
return os.Getenv("GCLOUD_TESTS_GOLANG_SPANNER_INSTANCE_CONFIG")
}

const (
str1 = "alice"
str2 = "a@example.com"
Expand Down Expand Up @@ -262,6 +271,10 @@ func initIntegrationTests() (cleanup func()) {
if err != nil {
log.Fatalf("Cannot get any instance configurations.\nPlease make sure the Cloud Spanner API is enabled for the test project.\nGet error: %v", err)
}
configName := config.Name
if instanceConfig != "" {
configName = fmt.Sprintf("projects/%s/instanceConfigs/%s", testProjectID, instanceConfig)
}

// First clean up any old test instances before we start the actual testing
// as these might cause this test run to fail.
Expand All @@ -272,7 +285,7 @@ func initIntegrationTests() (cleanup func()) {
Parent: fmt.Sprintf("projects/%s", testProjectID),
InstanceId: testInstanceID,
Instance: &instancepb.Instance{
Config: config.Name,
Config: configName,
DisplayName: testInstanceID,
NodeCount: 1,
},
Expand Down

0 comments on commit 1c10413

Please sign in to comment.