Skip to content

Commit 4314326

Browse files
authored
Merge branch 'main' into ci/tests-enable-race
2 parents 82e9dd9 + 11eb809 commit 4314326

File tree

91 files changed

+525
-586
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+525
-586
lines changed

container_file_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"os"
88
"path/filepath"
99
"testing"
10+
11+
"github.com/stretchr/testify/require"
1012
)
1113

1214
func TestContainerFileValidation(t *testing.T) {
@@ -17,9 +19,7 @@ func TestContainerFileValidation(t *testing.T) {
1719
}
1820

1921
f, err := os.Open(filepath.Join(".", "testdata", "hello.sh"))
20-
if err != nil {
21-
t.Fatal(err)
22-
}
22+
require.NoError(t, err)
2323

2424
testTable := []ContainerFileValidationTestCase{
2525
{

container_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func Test_BuildImageWithContexts(t *testing.T) {
167167
}{
168168
{
169169
Name: "Dockerfile",
170-
Contents: `FROM docker.io/alpine
170+
Contents: `FROM alpine
171171
CMD ["echo", "this is from the archive"]`,
172172
},
173173
}
@@ -216,7 +216,7 @@ func Test_BuildImageWithContexts(t *testing.T) {
216216
},
217217
{
218218
Name: "Dockerfile",
219-
Contents: `FROM docker.io/alpine
219+
Contents: `FROM alpine
220220
WORKDIR /app
221221
COPY . .
222222
CMD ["sh", "./say_hi.sh"]`,
@@ -365,7 +365,7 @@ func Test_GetLogsFromFailedContainer(t *testing.T) {
365365
ctx := context.Background()
366366
// directDockerHubReference {
367367
req := testcontainers.ContainerRequest{
368-
Image: "docker.io/alpine",
368+
Image: "alpine",
369369
Cmd: []string{"echo", "-n", "I was not expecting this"},
370370
WaitingFor: wait.ForLog("I was expecting this").WithStartupTimeout(5 * time.Second),
371371
}
@@ -392,11 +392,11 @@ func Test_GetLogsFromFailedContainer(t *testing.T) {
392392
type dockerImageSubstitutor struct{}
393393

394394
func (s dockerImageSubstitutor) Description() string {
395-
return "DockerImageSubstitutor (prepends docker.io)"
395+
return "DockerImageSubstitutor (prepends registry.hub.docker.com)"
396396
}
397397

398398
func (s dockerImageSubstitutor) Substitute(image string) (string, error) {
399-
return "docker.io/" + image, nil
399+
return "registry.hub.docker.com/library/" + image, nil
400400
}
401401

402402
// }
@@ -455,7 +455,7 @@ func TestImageSubstitutors(t *testing.T) {
455455
name: "Prepend namespace",
456456
image: "alpine",
457457
substitutors: []testcontainers.ImageSubstitutor{dockerImageSubstitutor{}},
458-
expectedImage: "docker.io/alpine",
458+
expectedImage: "registry.hub.docker.com/library/alpine",
459459
},
460460
{
461461
name: "Substitution with error",
@@ -554,5 +554,5 @@ func ExampleGenericContainer_withSubstitutors() {
554554

555555
fmt.Println(dockerContainer.Image)
556556

557-
// Output: docker.io/alpine:latest
557+
// Output: registry.hub.docker.com/library/alpine:latest
558558
}

docker_files_test.go

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,22 @@ import (
1313
"github.com/testcontainers/testcontainers-go/wait"
1414
)
1515

16+
const testBashImage string = "bash:5.2.26"
17+
1618
func TestCopyFileToContainer(t *testing.T) {
1719
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
1820
defer cnl()
1921

2022
// copyFileOnCreate {
2123
absPath, err := filepath.Abs(filepath.Join(".", "testdata", "hello.sh"))
22-
if err != nil {
23-
t.Fatal(err)
24-
}
24+
require.NoError(t, err)
2525

2626
r, err := os.Open(absPath)
27-
if err != nil {
28-
t.Fatal(err)
29-
}
27+
require.NoError(t, err)
3028

3129
ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
3230
ContainerRequest: testcontainers.ContainerRequest{
33-
Image: "docker.io/bash",
31+
Image: testBashImage,
3432
Files: []testcontainers.ContainerFile{
3533
{
3634
Reader: r,
@@ -56,17 +54,13 @@ func TestCopyFileToRunningContainer(t *testing.T) {
5654
// Not using the assertations here to avoid leaking the library into the example
5755
// copyFileAfterCreate {
5856
waitForPath, err := filepath.Abs(filepath.Join(".", "testdata", "waitForHello.sh"))
59-
if err != nil {
60-
t.Fatal(err)
61-
}
57+
require.NoError(t, err)
6258
helloPath, err := filepath.Abs(filepath.Join(".", "testdata", "hello.sh"))
63-
if err != nil {
64-
t.Fatal(err)
65-
}
59+
require.NoError(t, err)
6660

6761
ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
6862
ContainerRequest: testcontainers.ContainerRequest{
69-
Image: "docker.io/bash:5.2.26",
63+
Image: testBashImage,
7064
Files: []testcontainers.ContainerFile{
7165
{
7266
HostFilePath: waitForPath,
@@ -98,13 +92,11 @@ func TestCopyDirectoryToContainer(t *testing.T) {
9892
// Not using the assertations here to avoid leaking the library into the example
9993
// copyDirectoryToContainer {
10094
dataDirectory, err := filepath.Abs(filepath.Join(".", "testdata"))
101-
if err != nil {
102-
t.Fatal(err)
103-
}
95+
require.NoError(t, err)
10496

10597
ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
10698
ContainerRequest: testcontainers.ContainerRequest{
107-
Image: "docker.io/bash",
99+
Image: testBashImage,
108100
Files: []testcontainers.ContainerFile{
109101
{
110102
HostFilePath: dataDirectory,
@@ -131,17 +123,13 @@ func TestCopyDirectoryToRunningContainerAsFile(t *testing.T) {
131123

132124
// copyDirectoryToRunningContainerAsFile {
133125
dataDirectory, err := filepath.Abs(filepath.Join(".", "testdata"))
134-
if err != nil {
135-
t.Fatal(err)
136-
}
126+
require.NoError(t, err)
137127
waitForPath, err := filepath.Abs(filepath.Join(dataDirectory, "waitForHello.sh"))
138-
if err != nil {
139-
t.Fatal(err)
140-
}
128+
require.NoError(t, err)
141129

142130
ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
143131
ContainerRequest: testcontainers.ContainerRequest{
144-
Image: "docker.io/bash",
132+
Image: testBashImage,
145133
Files: []testcontainers.ContainerFile{
146134
{
147135
HostFilePath: waitForPath,
@@ -173,17 +161,13 @@ func TestCopyDirectoryToRunningContainerAsDir(t *testing.T) {
173161
// Not using the assertations here to avoid leaking the library into the example
174162
// copyDirectoryToRunningContainerAsDir {
175163
waitForPath, err := filepath.Abs(filepath.Join(".", "testdata", "waitForHello.sh"))
176-
if err != nil {
177-
t.Fatal(err)
178-
}
164+
require.NoError(t, err)
179165
dataDirectory, err := filepath.Abs(filepath.Join(".", "testdata"))
180-
if err != nil {
181-
t.Fatal(err)
182-
}
166+
require.NoError(t, err)
183167

184168
ctr, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
185169
ContainerRequest: testcontainers.ContainerRequest{
186-
Image: "docker.io/bash",
170+
Image: testBashImage,
187171
Files: []testcontainers.ContainerFile{
188172
{
189173
HostFilePath: waitForPath,

0 commit comments

Comments
 (0)