2014-02-25 16:17:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// tagging a named image in a new unprefixed repo should work
|
|
|
|
func TestTagUnprefixedRepoByName(t *testing.T) {
|
2014-06-30 19:42:09 +00:00
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
|
|
|
t.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")
|
|
|
|
out, _, err := runCommandWithOutput(tagCmd)
|
2014-02-25 16:17:48 +00:00
|
|
|
errorOut(err, t, fmt.Sprintf("%v %v", out, err))
|
|
|
|
|
|
|
|
deleteImages("testfoobarbaz")
|
|
|
|
|
|
|
|
logDone("tag - busybox -> testfoobarbaz")
|
|
|
|
}
|
|
|
|
|
|
|
|
// tagging an image by ID in a new unprefixed repo should work
|
|
|
|
func TestTagUnprefixedRepoByID(t *testing.T) {
|
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)
|
|
|
|
errorOut(err, t, fmt.Sprintf("failed to get the image ID of busybox: %v", err))
|
|
|
|
|
|
|
|
cleanedImageID := stripTrailingCharacters(out)
|
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", cleanedImageID, "testfoobarbaz")
|
|
|
|
out, _, err = runCommandWithOutput(tagCmd)
|
|
|
|
errorOut(err, t, fmt.Sprintf("%s %s", out, err))
|
|
|
|
|
|
|
|
deleteImages("testfoobarbaz")
|
|
|
|
|
|
|
|
logDone("tag - busybox's image ID -> testfoobarbaz")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we don't allow the use of invalid tags; these tag operations should fail
|
|
|
|
func TestTagInvalidUnprefixedRepo(t *testing.T) {
|
|
|
|
// skip this until we start blocking bad tags
|
|
|
|
t.Skip()
|
|
|
|
|
|
|
|
invalidRepos := []string{"-foo", "fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo", "f"}
|
|
|
|
|
|
|
|
for _, repo := range invalidRepos {
|
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repo)
|
|
|
|
_, _, err := runCommandWithOutput(tagCmd)
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("tag busybox %v should have failed", repo)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
logMessage := fmt.Sprintf("tag - busybox %v --> must fail", repo)
|
|
|
|
logDone(logMessage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we allow the use of valid tags
|
|
|
|
func TestTagValidPrefixedRepo(t *testing.T) {
|
2014-06-30 19:42:09 +00:00
|
|
|
if err := pullImageIfNotExist("busybox:latest"); err != nil {
|
|
|
|
t.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validRepos := []string{"fooo/bar", "fooaa/test"}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
t.Errorf("tag busybox %v should have worked: %s", repo, err)
|
|
|
|
continue
|
|
|
|
}
|
2014-04-04 00:22:32 +00:00
|
|
|
deleteImages(repo)
|
2014-02-25 16:17:48 +00:00
|
|
|
logMessage := fmt.Sprintf("tag - busybox %v", repo)
|
|
|
|
logDone(logMessage)
|
|
|
|
}
|
|
|
|
}
|