Skip to content
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

Merged
merged 1 commit into from Jun 2, 2021

Conversation

mohanli-ml
Copy link
Contributor

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.

@mohanli-ml mohanli-ml requested review from hengfengli, skuruppu and a team as code owners June 2, 2021 03:11
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jun 2, 2021
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Jun 2, 2021
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a -> an

Copy link
Contributor Author

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 != "" {
Copy link
Contributor

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
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an if-else.

Copy link
Contributor

@hengfengli hengfengli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@hengfengli hengfengli merged commit e935345 into googleapis:master Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants