Skip to content

Commit

Permalink
update opts snippet to handle error; update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mtellis2 committed May 1, 2024
1 parent bfa2cb4 commit 9d940cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion docs/modules/gcloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ go get github.com/testcontainers/testcontainers-go/modules/gcloud
## Usage example

!!!info
By default, the all the emulators use `gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators` as the default Docker image, except for the BigQuery emulator, which uses `ghcr.io/goccy/bigquery-emulator:0.4.3`, and Spanner, which uses `gcr.io/cloud-spanner-emulator/emulator:1.4.0`.
By default, the all the emulators use `gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators` as the default Docker image, except for the BigQuery emulator, which uses `ghcr.io/goccy/bigquery-emulator:0.6.1`, and Spanner, which uses `gcr.io/cloud-spanner-emulator/emulator:1.4.0`.

### BigQuery

Expand All @@ -28,6 +28,17 @@ go get github.com/testcontainers/testcontainers-go/modules/gcloud

It's important to set the `option.WithEndpoint()` option using the container's URI, as shown in the client example above.

#### Data Yaml (Seed File)

If you would like to do additional initialization in the BigQuery container, add a `data.yaml` file to the container request with the `WithDataYamlFile` function.
Those files will be copied after the container is created but before it's started. The startup command then used will look like `--project test --data-from-yaml /data.yaml`.

An example of a `data.yaml` file that seeds the BigQuery instance with datasets and tables is shown below:

<!--codeinclude-->
[Data Yaml content](../../modules/gcloud/testdata/data.yaml)
<!--/codeinclude-->

### BigTable

<!--codeinclude-->
Expand Down
4 changes: 3 additions & 1 deletion modules/gcloud/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func RunBigQueryContainer(ctx context.Context, opts ...testcontainers.ContainerC
req.Cmd = []string{"--project", settings.ProjectID}

for _, opt := range opts {
opt.Customize(&req)
if err := opt.Customize(&req); err != nil {
return nil, err
}
}

container, err := testcontainers.GenericContainer(ctx, req)
Expand Down

0 comments on commit 9d940cc

Please sign in to comment.