New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(spanner): add custom instance config to tests #4194
Conversation
1c10413
to
f865c3b
Compare
spanner/integration_test.go
Outdated
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a -> an
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -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 != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If instanceConfig
is not empty, there is no need to call ListInstanceConfigs
.
var configName string
if instanceConfig != "" {
configName = fmt.Sprintf("projects/%s/instanceConfigs/%s", testProjectID, instanceConfig)
} else {
configIterator := instanceAdmin.ListInstanceConfigs(ctx, &instancepb.ListInstanceConfigsRequest{
Parent: fmt.Sprintf("projects/%s", testProjectID),
})
config, err := configIterator.Next()
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
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an if-else.
f865c3b
to
52501b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
In spanner integration tests, an instance will be created before the test. Currently, the instance is created with the first instance config. However, for staging environment the instance config is shared among GCP projects and can run out of resources. So this PR tries to solve this issue by allowing users to custom the instance config by adding an environment variable GCLOUD_TESTS_GOLANG_SPANNER_INSTANCE_CONFIG.