Skip to content

Commit

Permalink
Move the remaining tests into a test package
Browse files Browse the repository at this point in the history
This work has been extracted from testcontainers#2202 and is related to testcontainers#2180. See the original PR for the full context and reasoning. This PR in particular moves all the simpler tests in one go, or adds a comment to any remaining tests that would not make sense to move (or could not be moved without exposing a lot of variables).

This will help with the documentation, since all examples will now have the module prefixes.
  • Loading branch information
Minivera committed Mar 18, 2024
1 parent 9f1d656 commit 23e6936
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 399 deletions.
40 changes: 21 additions & 19 deletions from_dockerfile_test.go
@@ -1,4 +1,4 @@
package testcontainers
package testcontainers_test

import (
"context"
Expand All @@ -12,10 +12,12 @@ import (
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

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

func TestBuildImageFromDockerfile(t *testing.T) {
provider, err := NewDockerProvider()
provider, err := testcontainers.NewDockerProvider()
if err != nil {
t.Fatal(err)
}
Expand All @@ -25,9 +27,9 @@ func TestBuildImageFromDockerfile(t *testing.T) {

ctx := context.Background()

tag, err := provider.BuildImage(ctx, &ContainerRequest{
tag, err := provider.BuildImage(ctx, &testcontainers.ContainerRequest{
// fromDockerfileIncludingRepo {
FromDockerfile: FromDockerfile{
FromDockerfile: testcontainers.FromDockerfile{
Context: "testdata",
Dockerfile: "echo.Dockerfile",
Repo: "test-repo",
Expand All @@ -53,7 +55,7 @@ func TestBuildImageFromDockerfile(t *testing.T) {
}

func TestBuildImageFromDockerfile_NoRepo(t *testing.T) {
provider, err := NewDockerProvider()
provider, err := testcontainers.NewDockerProvider()
if err != nil {
t.Fatal(err)
}
Expand All @@ -63,8 +65,8 @@ func TestBuildImageFromDockerfile_NoRepo(t *testing.T) {

ctx := context.Background()

tag, err := provider.BuildImage(ctx, &ContainerRequest{
FromDockerfile: FromDockerfile{
tag, err := provider.BuildImage(ctx, &testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: "testdata",
Dockerfile: "echo.Dockerfile",
Repo: "test-repo",
Expand All @@ -88,7 +90,7 @@ func TestBuildImageFromDockerfile_NoRepo(t *testing.T) {
}

func TestBuildImageFromDockerfile_NoTag(t *testing.T) {
provider, err := NewDockerProvider()
provider, err := testcontainers.NewDockerProvider()
if err != nil {
t.Fatal(err)
}
Expand All @@ -98,8 +100,8 @@ func TestBuildImageFromDockerfile_NoTag(t *testing.T) {

ctx := context.Background()

tag, err := provider.BuildImage(ctx, &ContainerRequest{
FromDockerfile: FromDockerfile{
tag, err := provider.BuildImage(ctx, &testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: "testdata",
Dockerfile: "echo.Dockerfile",
Tag: "test-tag",
Expand All @@ -126,9 +128,9 @@ func TestBuildImageFromDockerfile_Target(t *testing.T) {
// there are thre targets: target0, target1 and target2.
for i := 0; i < 3; i++ {
ctx := context.Background()
c, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
FromDockerfile: FromDockerfile{
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: "testdata",
Dockerfile: "target.Dockerfile",
PrintBuildLog: true,
Expand Down Expand Up @@ -160,9 +162,9 @@ func ExampleGenericContainer_buildFromDockerfile() {
ctx := context.Background()

// buildFromDockerfileWithModifier {
c, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
FromDockerfile: FromDockerfile{
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: "testdata",
Dockerfile: "target.Dockerfile",
PrintBuildLog: true,
Expand Down Expand Up @@ -199,9 +201,9 @@ func TestBuildImageFromDockerfile_TargetDoesNotExist(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

_, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
FromDockerfile: FromDockerfile{
_, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: "testdata",
Dockerfile: "target.Dockerfile",
PrintBuildLog: true,
Expand Down
2 changes: 2 additions & 0 deletions generic_test.go
@@ -1,3 +1,5 @@
// This test is testing very internal logic that should not be exported away from this package. We'll
// leave it in the main testcontainers package. Do not use for user facing examples.
package testcontainers

import (
Expand Down
2 changes: 2 additions & 0 deletions image_substitutors_test.go
@@ -1,3 +1,5 @@
// This test is testing very internal logic that should not be exported away from this package. We'll
// leave it in the main testcontainers package. Do not use for user facing examples.
package testcontainers

import (
Expand Down
2 changes: 2 additions & 0 deletions image_test.go
@@ -1,3 +1,5 @@
// This test is testing very internal logic that should not be exported away from this package. We'll
// leave it in the main testcontainers package. Do not use for user facing examples.
package testcontainers

import (
Expand Down

0 comments on commit 23e6936

Please sign in to comment.