Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bump github.com/testcontainers/testcontainers-go from 0.13.0 to 0.14.0 #26

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: lint
on:
push:
Expand All @@ -20,15 +21,15 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- id: get-lint-version
- id: vars
run: |
make golangci-lint-version
make gha-vars

- name: lint
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: ${{ steps.get-lint-version.outputs.GOLANGCI_LINT_VERSION }}
version: ${{ steps.vars.outputs.GOLANGCI_LINT_VERSION }}

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: test

on:
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/update-registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@ name: 'update-registry'

on:
push:
tags:
- v*
branches:
- master
workflow_dispatch:

env:
MODULE_NAME: testcontainers-extra

jobs:
notify:
runs-on: ubuntu-latest
strategy:
matrix:
registry: [ go.nhat.io, go-staging.nhat.io ]
steps:
- uses: actions/checkout@v3

- id: vars
run: |
make gha-vars

- name: notify ${{ matrix.registry }}
uses: benc-uk/workflow-dispatch@v1
with:
workflow: build
repo: nhatthm/${{ matrix.registry }}
token: ${{ secrets.REGISTRY_TOKEN }}
inputs: '{"modules": "${{ env.MODULE_NAME }}"}'
inputs: '{"modules": "${{ steps.vars.outputs.MODULE_NAME }}"}'
ref: 'master'
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
MODULE_NAME=testcontainers-extra

VENDOR_DIR = vendor

GOLANGCI_LINT_VERSION ?= v1.48.0
Expand Down Expand Up @@ -27,8 +29,9 @@ test-unit:
# @echo ">> integration test"
# @$(GO) test ./features/... -gcflags=-l -coverprofile=features.coverprofile -coverpkg ./... -race --godog

.PHONY: golangci-lint-version
golangci-lint-version:
.PHONY: gha-vars
gha-vars:
@echo "::set-output name=MODULE_NAME::$(MODULE_NAME)"
@echo "::set-output name=GOLANGCI_LINT_VERSION::$(GOLANGCI_LINT_VERSION)"

$(GOLANGCI_LINT):
Expand Down
15 changes: 7 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/docker/docker v20.10.18+incompatible
github.com/docker/go-connections v0.4.0
github.com/stretchr/testify v1.8.0
github.com/testcontainers/testcontainers-go v0.13.0
github.com/testcontainers/testcontainers-go v0.14.0
)

require (
Expand All @@ -18,7 +18,7 @@ require (
github.com/containerd/cgroups v1.0.4 // indirect
github.com/containerd/containerd v1.6.8 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // 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
Expand All @@ -30,17 +30,16 @@ require (
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
github.com/opencontainers/runc v1.1.3 // indirect
github.com/opencontainers/runc v1.1.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect
google.golang.org/genproto v0.0.0-20220817144833-d7fd3f11b9b1 // indirect
google.golang.org/grpc v1.48.0 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/sys v0.0.0-20220909162455-aba9fc2a8ff2 // indirect
google.golang.org/genproto v0.0.0-20220909194730-69f6226f97e5 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
211 changes: 185 additions & 26 deletions go.sum

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions mock/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,16 @@ func (c *Container) NetworkAliases(ctx context.Context) (map[string][]string, er
}

// Exec satisfies testcontainers.Container interface.
func (c *Container) Exec(ctx context.Context, cmd []string) (int, error) {
func (c *Container) Exec(ctx context.Context, cmd []string) (int, io.Reader, error) {
result := c.Called(ctx, cmd)

return result.Int(0), result.Error(1)
r1, r2, r3 := result.Int(0), result.Get(1), result.Error(2)

if r2 == nil {
return r1, nil, r3
}

return r1, r2.(io.Reader), r3
}

// ContainerIP satisfies testcontainers.Container interface.
Expand All @@ -202,6 +208,11 @@ func (c *Container) CopyFileToContainer(ctx context.Context, hostFilePath string
return c.Called(ctx, hostFilePath, containerFilePath, fileMode).Error(0)
}

// CopyDirToContainer satisfies testcontainers.Container interface.
func (c *Container) CopyDirToContainer(ctx context.Context, hostDirPath string, containerParentPath string, fileMode int64) error {
return c.Called(ctx, hostDirPath, containerParentPath, fileMode).Error(0)
}

// CopyFileFromContainer satisfies testcontainers.Container interface.
func (c *Container) CopyFileFromContainer(ctx context.Context, filePath string) (io.ReadCloser, error) {
result := c.Called(ctx, filePath)
Expand All @@ -216,6 +227,11 @@ func (c *Container) CopyFileFromContainer(ctx context.Context, filePath string)
return rc.(io.ReadCloser), err
}

// IsRunning satisfies testcontainers.Container interface.
func (c *Container) IsRunning() bool {
return c.Called().Bool(0)
}

// mockContainer mocks testcontainers.Container interface.
func mockContainer(mocks ...func(c *Container)) *Container {
c := &Container{}
Expand Down
99 changes: 94 additions & 5 deletions mock/container_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mock_test

import (
"bytes"
"context"
"errors"
"io"
Expand Down Expand Up @@ -670,39 +671,52 @@ func TestContainer_NetworkAliases(t *testing.T) {
func TestContainer_Exec(t *testing.T) {
t.Parallel()

rdr := new(bytes.Buffer)

testCases := []struct {
scenario string
mock mock.ContainerMocker
expectedResult int
expectedReader io.Reader
expectedError error
}{
{
scenario: "error",
mock: mock.MockContainer(func(c *mock.Container) {
c.On("Exec", context.Background(), []string{"test"}).
Return(1, errors.New("error"))
Return(1, nil, errors.New("error"))
}),
expectedResult: 1,
expectedError: errors.New("error"),
},
{
scenario: "no error",
scenario: "no reader",
mock: mock.MockContainer(func(c *mock.Container) {
c.On("Exec", context.Background(), []string{"test"}).
Return(0, nil)
Return(0, nil, nil)
}),
expectedResult: 0,
},
{
scenario: "has reader",
mock: mock.MockContainer(func(c *mock.Container) {
c.On("Exec", context.Background(), []string{"test"}).
Return(0, rdr, nil)
}),
expectedResult: 0,
expectedReader: rdr,
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()

result, err := tc.mock(t).Exec(context.Background(), []string{"test"})
actualResult, actualReader, err := tc.mock(t).Exec(context.Background(), []string{"test"})

assert.Equal(t, tc.expectedResult, result)
assert.Equal(t, tc.expectedResult, actualResult)
assert.Equal(t, tc.expectedReader, actualReader)
assert.Equal(t, tc.expectedError, err)
})
}
Expand Down Expand Up @@ -822,6 +836,43 @@ func TestContainer_CopyFileToContainer(t *testing.T) {
}
}

func TestContainer_CopyDirToContainer(t *testing.T) {
t.Parallel()

testCases := []struct {
scenario string
mock mock.ContainerMocker
expectedError error
}{
{
scenario: "error",
mock: mock.MockContainer(func(c *mock.Container) {
c.On("CopyDirToContainer", context.Background(), "test", "/tmp", int64(0)).
Return(errors.New("error"))
}),
expectedError: errors.New("error"),
},
{
scenario: "no error",
mock: mock.MockContainer(func(c *mock.Container) {
c.On("CopyDirToContainer", context.Background(), "test", "/tmp", int64(0)).
Return(nil)
}),
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()

err := tc.mock(t).CopyDirToContainer(context.Background(), "test", "/tmp", 0)

assert.Equal(t, tc.expectedError, err)
})
}
}

func TestContainer_CopyFileFromContainer(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -863,3 +914,41 @@ func TestContainer_CopyFileFromContainer(t *testing.T) {
})
}
}

func TestContainer_IsRunning(t *testing.T) {
t.Parallel()

testCases := []struct {
scenario string
mock mock.ContainerMocker
expected bool
}{
{
scenario: "not running",
mock: mock.MockContainer(func(c *mock.Container) {
c.On("IsRunning").
Return(false)
}),
expected: false,
},
{
scenario: "running",
mock: mock.MockContainer(func(c *mock.Container) {
c.On("IsRunning").
Return(true)
}),
expected: true,
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()

actual := tc.mock(t).IsRunning()

assert.Equal(t, tc.expected, actual)
})
}
}
23 changes: 21 additions & 2 deletions mock/wait/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,29 @@ func (s *StrategyTarget) Logs(ctx context.Context) (io.ReadCloser, error) {
}

// Exec satisfies wait.StrategyTarget interface.
func (s *StrategyTarget) Exec(ctx context.Context, cmd []string) (int, error) {
func (s *StrategyTarget) Exec(ctx context.Context, cmd []string) (int, io.Reader, error) {
result := s.Called(ctx, cmd)

return result.Int(0), result.Error(1)
r1, r2, r3 := result.Int(0), result.Get(1), result.Error(2)

if r2 == nil {
return r1, nil, r3
}

return r1, r2.(io.Reader), r3
}

// Ports satisfies wait.StrategyTarget interface.
func (s *StrategyTarget) Ports(ctx context.Context) (nat.PortMap, error) {
result := s.Called(ctx)

r1, r2 := result.Get(0), result.Error(1)

if r1 == nil {
return nil, r2
}

return r1.(nat.PortMap), r2
}

// State satisfies wait.StrategyTarget interface.
Expand Down
Loading