Skip to content

Commit

Permalink
Merge branch 'main' into compose-module
Browse files Browse the repository at this point in the history
* main:
  chore(deps): bump google.golang.org/api in /examples/pubsub (testcontainers#685)
  chore(deps): bump google.golang.org/api in /examples/spanner (testcontainers#684)
  chore(deps): bump google.golang.org/grpc in /examples/firestore (testcontainers#686)
  chore(deps): bump google.golang.org/api in /examples/bigtable (testcontainers#680)
  chore(deps): bump google.golang.org/api in /examples/datastore (testcontainers#678)
  chore(deps): bump golang.org/x/text from 0.3.7 to 0.5.0 (testcontainers#660)
  chore(deps): bump github.com/magiconair/properties from 1.8.6 to 1.8.7 (testcontainers#677)
  chore: postgres example (testcontainers#674)
  Add bigtable example (testcontainers#676)
  chore(deps): bump github.com/containerd/containerd from 1.6.10 to 1.6.12 (testcontainers#675)
  chore: run go mod tidy in examples (testcontainers#672)
  Improve datastore, firestore, pubsub and spanner tests (testcontainers#670)
  chore: group dependabot updates (testcontainers#668)
  chore: update mkdocs format to go-yaml v3 (testcontainers#667)
  • Loading branch information
mdelapenya committed Dec 15, 2022
2 parents 0d0f5ff + 099b181 commit 65c0375
Show file tree
Hide file tree
Showing 44 changed files with 2,252 additions and 521 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Expand Up @@ -12,6 +12,12 @@ updates:
interval: daily
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/bigtable
schedule:
interval: daily
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/cockroachdb
schedule:
Expand All @@ -36,6 +42,12 @@ updates:
interval: daily
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/postgres
schedule:
interval: daily
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /examples/pubsub
schedule:
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/bigtable-example.yml
@@ -0,0 +1,42 @@
name: Bigtable example pipeline

on: [push, pull_request]

jobs:
test-bigtable:
strategy:
matrix:
go-version: [1.18.x, 1.x]
runs-on: "ubuntu-latest"
steps:

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: modVerify
working-directory: ./examples/bigtable
run: go mod verify

- name: modTidy
working-directory: ./examples/bigtable
run: make tools-tidy

- name: gotestsum
working-directory: ./examples/bigtable
run: make test-unit

- name: Run checker
run: |
./scripts/check_environment.sh
- name: Test Summary
uses: test-summary/action@4ee9ece4bca777a38f05c8fc578ac2007fe266f7
with:
paths: "**/TEST-bigtable*.xml"
if: always()
42 changes: 42 additions & 0 deletions .github/workflows/postgres-example.yml
@@ -0,0 +1,42 @@
name: Postgres example pipeline

on: [push, pull_request]

jobs:
test-postgres:
strategy:
matrix:
go-version: [1.18.x, 1.x]
runs-on: "ubuntu-latest"
steps:

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: modVerify
working-directory: ./examples/postgres
run: go mod verify

- name: modTidy
working-directory: ./examples/postgres
run: make tools-tidy

- name: gotestsum
working-directory: ./examples/postgres
run: make test-unit

- name: Run checker
run: |
./scripts/check_environment.sh
- name: Test Summary
uses: test-summary/action@4ee9ece4bca777a38f05c8fc578ac2007fe266f7
with:
paths: "**/TEST-postgres*.xml"
if: always()
9 changes: 9 additions & 0 deletions docs/examples/bigtable.md
@@ -0,0 +1,9 @@
# Bigtable

<!--codeinclude-->
[Creating a Bigtable container](../../examples/bigtable/bigtable.go)
<!--/codeinclude-->

<!--codeinclude-->
[Test for a Bigtable container](../../examples/bigtable/bigtable_test.go)
<!--/codeinclude-->
9 changes: 9 additions & 0 deletions docs/examples/index.md
Expand Up @@ -36,3 +36,12 @@ From the [`examples` directory]({{repo_url}}/tree/main/examples), please run:
```shell
go run . --name ${NAME_OF_YOUR_EXAMPLE} --image "${REGISTRY}/${EXAMPLE}:${TAG}"
```

## Update Go dependencies in the examples

To update the Go dependencies in the examples, please run:

```shell
$ cd examples
$ make tidy-examples
```
9 changes: 9 additions & 0 deletions docs/examples/postgres.md
@@ -0,0 +1,9 @@
# Postgres

<!--codeinclude-->
[Creating a Postgres container](../../examples/postgres/postgres.go)
<!--/codeinclude-->

<!--codeinclude-->
[Test for a Postgres container](../../examples/postgres/postgres_test.go)
<!--/codeinclude-->
4 changes: 4 additions & 0 deletions examples/Makefile
Expand Up @@ -6,3 +6,7 @@ test: test-unit
$(MAKE) -C nginx test
$(MAKE) -C pulsar test
$(MAKE) -C redis test

.PHONY: tidy-examples
tidy-examples:
@find . -type f -name Makefile -execdir make tools-tidy \;
5 changes: 5 additions & 0 deletions examples/bigtable/Makefile
@@ -0,0 +1,5 @@
include ../../commons-test.mk

.PHONY: test
test:
$(MAKE) test-bigtable
50 changes: 50 additions & 0 deletions examples/bigtable/bigtable.go
@@ -0,0 +1,50 @@
package bigtable

import (
"context"
"fmt"
"github.com/testcontainers/testcontainers-go/wait"

"github.com/testcontainers/testcontainers-go"
)

// bigtableContainer represents the bigtable container type used in the module
type bigtableContainer struct {
testcontainers.Container
URI string
}

// setupBigtable creates an instance of the bigtable container type
func setupBigtable(ctx context.Context) (*bigtableContainer, error) {
req := testcontainers.ContainerRequest{
Image: "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators",
ExposedPorts: []string{"9000/tcp"},
WaitingFor: wait.ForLog("running"),
Cmd: []string{
"/bin/sh",
"-c",
"gcloud beta emulators bigtable start --host-port 0.0.0.0:9000",
},
}
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
return nil, err
}

mappedPort, err := container.MappedPort(ctx, "9000")
if err != nil {
return nil, err
}

hostIP, err := container.Host(ctx)
if err != nil {
return nil, err
}

uri := fmt.Sprintf("%s:%s", hostIP, mappedPort.Port())

return &bigtableContainer{Container: container, URI: uri}, nil
}
73 changes: 73 additions & 0 deletions examples/bigtable/bigtable_test.go
@@ -0,0 +1,73 @@
package bigtable

import (
"cloud.google.com/go/bigtable"
"context"
"google.golang.org/api/option"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"testing"
)

const (
projectId = "test-project"
instanceId = "test-instance"
tableName = "test-table"
)

func TestBigtable(t *testing.T) {
ctx := context.Background()

container, err := setupBigtable(ctx)
if err != nil {
t.Fatal(err)
}

// Clean up the container after the test is complete
t.Cleanup(func() {
if err := container.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %s", err)
}
})

options := []option.ClientOption{
option.WithEndpoint(container.URI),
option.WithoutAuthentication(),
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
}
adminClient, err := bigtable.NewAdminClient(ctx, projectId, instanceId, options...)
if err != nil {
t.Fatal(err)
}
err = adminClient.CreateTable(ctx, tableName)
if err != nil {
t.Fatal(err)
}
err = adminClient.CreateColumnFamily(ctx, tableName, "name")
if err != nil {
t.Fatal(err)
}

client, err := bigtable.NewClient(ctx, projectId, instanceId, options...)
if err != nil {
t.Fatal(err)
}
tbl := client.Open(tableName)

mut := bigtable.NewMutation()
mut.Set("name", "firstName", bigtable.Now(), []byte("Gopher"))
err = tbl.Apply(ctx, "1", mut)
if err != nil {
t.Fatal(err)
}

row, err := tbl.ReadRow(ctx, "1", bigtable.RowFilter(bigtable.FamilyFilter("name")))
if err != nil {
t.Fatal(err)
}
// perform assertions
name := string(row["name"][0].Value)
if name != "Gopher" {
t.Fatalf("expected row key to be 'Gopher', got '%s'", name)
}
}
89 changes: 89 additions & 0 deletions examples/bigtable/go.mod
@@ -0,0 +1,89 @@
module github.com/testcontainers/testcontainers-go/examples/bigtable

go 1.18

require (
cloud.google.com/go/bigtable v1.18.1
github.com/testcontainers/testcontainers-go v0.16.0
google.golang.org/api v0.104.0
google.golang.org/grpc v1.51.0
gotest.tools/gotestsum v1.8.2
)

require (
cloud.google.com/go v0.105.0 // indirect
cloud.google.com/go/compute v1.13.0 // indirect
cloud.google.com/go/compute/metadata v0.2.2 // indirect
cloud.google.com/go/iam v0.8.0 // indirect
cloud.google.com/go/longrunning v0.3.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.2.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1 // indirect
github.com/containerd/containerd v1.6.12 // indirect
github.com/dnephin/pflag v1.0.7 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v20.10.20+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1 // indirect
github.com/envoyproxy/protoc-gen-validate v0.1.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/moby/patternmatcher v0.5.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/term v0.0.0-20221128092401-c43b287e0e0f // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/opencontainers/runc v1.1.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/tools v0.1.12 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221206210731-b1a01be3a5f6 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gotest.tools/v3 v3.4.0 // indirect
)

replace (
github.com/docker/cli => github.com/docker/cli v20.10.3-0.20221013132413-1d6c6e2367e2+incompatible // 22.06 master branch
github.com/docker/docker => github.com/docker/docker v20.10.3-0.20221013203545-33ab36d6b304+incompatible // 22.06 branch
github.com/moby/buildkit => github.com/moby/buildkit v0.10.1-0.20220816171719-55ba9d14360a // same as buildx

github.com/opencontainers/runc => github.com/opencontainers/runc v1.1.2 // Can be removed on next bump of containerd to > 1.6.4
github.com/testcontainers/testcontainers-go => ../..

// For k8s dependencies, we use a replace directive, to prevent them being
// upgraded to the version specified in containerd, which is not relevant to the
// version needed.
// See https://github.com/docker/buildx/pull/948 for details.
// https://github.com/docker/buildx/blob/v0.8.1/go.mod#L62-L64
k8s.io/api => k8s.io/api v0.22.4
k8s.io/apimachinery => k8s.io/apimachinery v0.22.4
k8s.io/client-go => k8s.io/client-go v0.22.4
)

0 comments on commit 65c0375

Please sign in to comment.