2014-02-25 16:17:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
2014-10-20 03:10:31 +00:00
|
|
|
"strings"
|
2015-03-24 11:25:26 +00:00
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/stringutils"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
2014-02-25 16:17:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// tagging a named image in a new unprefixed repo should work
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagUnprefixedRepoByName(c *check.C) {
|
2014-06-30 19:42:09 +00:00
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 19:42:09 +00:00
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "testfoobarbaz")
|
2014-10-14 19:28:56 +00:00
|
|
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(out, err)
|
2014-10-14 19:28:56 +00:00
|
|
|
}
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// tagging an image by ID in a new unprefixed repo should work
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagUnprefixedRepoByID(c *check.C) {
|
2014-05-31 01:13:37 +00:00
|
|
|
getIDCmd := exec.Command(dockerBinary, "inspect", "-f", "{{.Id}}", "busybox")
|
2014-02-25 16:17:48 +00:00
|
|
|
out, _, err := runCommandWithOutput(getIDCmd)
|
2014-10-14 19:28:56 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to get the image ID of busybox: %s, %v", out, err)
|
2014-10-14 19:28:56 +00:00
|
|
|
}
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedImageID := strings.TrimSpace(out)
|
2014-02-25 16:17:48 +00:00
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", cleanedImageID, "testfoobarbaz")
|
2014-10-14 19:28:56 +00:00
|
|
|
if out, _, err = runCommandWithOutput(tagCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(out, err)
|
2014-10-14 19:28:56 +00:00
|
|
|
}
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 14:32:44 +00:00
|
|
|
// ensure we don't allow the use of invalid repository names; these tag operations should fail
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagInvalidUnprefixedRepo(c *check.C) {
|
2014-02-25 16:17:48 +00:00
|
|
|
|
2014-09-11 14:32:44 +00:00
|
|
|
invalidRepos := []string{"fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo%asd"}
|
2014-02-25 16:17:48 +00:00
|
|
|
|
|
|
|
for _, repo := range invalidRepos {
|
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repo)
|
|
|
|
_, _, err := runCommandWithOutput(tagCmd)
|
|
|
|
if err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("tag busybox %v should have failed", repo)
|
2014-09-11 14:32:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we don't allow the use of invalid tags; these tag operations should fail
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagInvalidPrefixedRepo(c *check.C) {
|
2015-03-26 01:40:23 +00:00
|
|
|
longTag := stringutils.GenerateRandomAlphaOnlyString(121)
|
2014-09-11 14:32:44 +00:00
|
|
|
|
2015-03-26 01:40:23 +00:00
|
|
|
invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag}
|
2014-09-11 14:32:44 +00:00
|
|
|
|
|
|
|
for _, repotag := range invalidTags {
|
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repotag)
|
|
|
|
_, _, err := runCommandWithOutput(tagCmd)
|
|
|
|
if err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("tag busybox %v should have failed", repotag)
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we allow the use of valid tags
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagValidPrefixedRepo(c *check.C) {
|
2014-06-30 19:42:09 +00:00
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
2014-09-15 22:17:50 +00:00
|
|
|
validRepos := []string{"fooo/bar", "fooaa/test", "foooo:t"}
|
2014-02-25 16:17:48 +00:00
|
|
|
|
|
|
|
for _, repo := range validRepos {
|
2014-06-30 19:42:09 +00:00
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", repo)
|
2014-02-25 16:17:48 +00:00
|
|
|
_, _, err := runCommandWithOutput(tagCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("tag busybox %v should have worked: %s", repo, err)
|
2014-02-25 16:17:48 +00:00
|
|
|
continue
|
|
|
|
}
|
2014-04-04 00:22:32 +00:00
|
|
|
deleteImages(repo)
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-20 03:10:31 +00:00
|
|
|
|
|
|
|
// tag an image with an existed tag name without -f option should fail
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagExistedNameWithoutForce(c *check.C) {
|
2014-10-20 03:10:31 +00:00
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
2014-10-20 03:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "busybox:test")
|
|
|
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(out, err)
|
2014-10-20 03:10:31 +00:00
|
|
|
}
|
|
|
|
tagCmd = exec.Command(dockerBinary, "tag", "busybox:latest", "busybox:test")
|
|
|
|
out, _, err := runCommandWithOutput(tagCmd)
|
|
|
|
if err == nil || !strings.Contains(out, "Conflict: Tag test is already set to image") {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("tag busybox busybox:test should have failed,because busybox:test is existed")
|
2014-10-20 03:10:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// tag an image with an existed tag name with -f option should work
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagExistedNameWithForce(c *check.C) {
|
2014-10-20 03:10:31 +00:00
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
2014-10-20 03:10:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", "busybox:test")
|
|
|
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(out, err)
|
2014-10-20 03:10:31 +00:00
|
|
|
}
|
|
|
|
tagCmd = exec.Command(dockerBinary, "tag", "-f", "busybox:latest", "busybox:test")
|
|
|
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(out, err)
|
2014-10-20 03:10:31 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-07 01:54:52 +00:00
|
|
|
|
|
|
|
// ensure tagging using official names works
|
|
|
|
// ensure all tags result in the same name
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestTagOfficialNames(c *check.C) {
|
2014-10-07 01:54:52 +00:00
|
|
|
names := []string{
|
|
|
|
"docker.io/busybox",
|
|
|
|
"index.docker.io/busybox",
|
|
|
|
"library/busybox",
|
|
|
|
"docker.io/library/busybox",
|
|
|
|
"index.docker.io/library/busybox",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range names {
|
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "-f", "busybox:latest", name+":latest")
|
|
|
|
out, exitCode, err := runCommandWithOutput(tagCmd)
|
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("tag busybox %v should have worked: %s, %s", name, err, out)
|
2014-10-07 01:54:52 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we don't have multiple tag names.
|
|
|
|
imagesCmd := exec.Command(dockerBinary, "images")
|
|
|
|
out, _, err = runCommandWithOutput(imagesCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("listing images failed with errors: %v, %s", err, out)
|
2014-10-07 01:54:52 +00:00
|
|
|
} else if strings.Contains(out, name) {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("images should not have listed '%s'", name)
|
2014-10-07 01:54:52 +00:00
|
|
|
deleteImages(name + ":latest")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range names {
|
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "-f", name+":latest", "fooo/bar:latest")
|
|
|
|
_, exitCode, err := runCommandWithOutput(tagCmd)
|
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("tag %v fooo/bar should have worked: %s", name, err)
|
2014-10-07 01:54:52 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
deleteImages("fooo/bar:latest")
|
|
|
|
}
|
|
|
|
}
|