-
-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement]: add ability to set repo:tag for ContainerRequest FromD…
…ockerfile (#1508) * add ability to set repo:tag for ContainerRequest FromDockerfile * chore: add test * fix: imports * fix: imports * chor: add more tests * docs: document the fields in the site * docs: use code snippets --------- Co-authored-by: igribkov <i.gribkov@robovoice.ru> Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>
- Loading branch information
1 parent
7863b82
commit e1db360
Showing
6 changed files
with
163 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package testcontainers | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBuildImageFromDockerfile(t *testing.T) { | ||
provider, err := NewDockerProvider() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer provider.Close() | ||
|
||
cli := provider.Client() | ||
|
||
ctx := context.Background() | ||
|
||
tag, err := provider.BuildImage(ctx, &ContainerRequest{ | ||
// fromDockerfileIncludingRepo { | ||
FromDockerfile: FromDockerfile{ | ||
Context: filepath.Join("testdata"), | ||
Dockerfile: "echo.Dockerfile", | ||
Repo: "test-repo", | ||
Tag: "test-tag", | ||
}, | ||
// } | ||
}) | ||
assert.Nil(t, err) | ||
assert.Equal(t, "test-repo:test-tag", tag) | ||
|
||
_, _, err = cli.ImageInspectWithRaw(ctx, tag) | ||
assert.Nil(t, err) | ||
|
||
t.Cleanup(func() { | ||
_, err := cli.ImageRemove(ctx, tag, types.ImageRemoveOptions{ | ||
Force: true, | ||
PruneChildren: true, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
} | ||
|
||
func TestBuildImageFromDockerfile_NoRepo(t *testing.T) { | ||
provider, err := NewDockerProvider() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer provider.Close() | ||
|
||
cli := provider.Client() | ||
|
||
ctx := context.Background() | ||
|
||
tag, err := provider.BuildImage(ctx, &ContainerRequest{ | ||
FromDockerfile: FromDockerfile{ | ||
Context: filepath.Join("testdata"), | ||
Dockerfile: "echo.Dockerfile", | ||
Repo: "test-repo", | ||
}, | ||
}) | ||
assert.Nil(t, err) | ||
assert.True(t, strings.HasPrefix(tag, "test-repo:")) | ||
|
||
_, _, err = cli.ImageInspectWithRaw(ctx, tag) | ||
assert.Nil(t, err) | ||
|
||
t.Cleanup(func() { | ||
_, err := cli.ImageRemove(ctx, tag, types.ImageRemoveOptions{ | ||
Force: true, | ||
PruneChildren: true, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
} | ||
|
||
func TestBuildImageFromDockerfile_NoTag(t *testing.T) { | ||
provider, err := NewDockerProvider() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer provider.Close() | ||
|
||
cli := provider.Client() | ||
|
||
ctx := context.Background() | ||
|
||
tag, err := provider.BuildImage(ctx, &ContainerRequest{ | ||
FromDockerfile: FromDockerfile{ | ||
Context: filepath.Join("testdata"), | ||
Dockerfile: "echo.Dockerfile", | ||
Tag: "test-tag", | ||
}, | ||
}) | ||
assert.Nil(t, err) | ||
assert.True(t, strings.HasSuffix(tag, ":test-tag")) | ||
|
||
_, _, err = cli.ImageInspectWithRaw(ctx, tag) | ||
assert.Nil(t, err) | ||
|
||
t.Cleanup(func() { | ||
_, err := cli.ImageRemove(ctx, tag, types.ImageRemoveOptions{ | ||
Force: true, | ||
PruneChildren: true, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}) | ||
} |