Merge pull request #8463 from jfrazelle/fix-invalid-tag-test

Fix Tag Test for longer tags
This commit is contained in:
Victor Vieux 2014-10-08 01:07:24 -07:00
Родитель 60908acff6 de32f48e66
Коммит 0d5daa4a8f
3 изменённых файлов: 15 добавлений и 4 удалений

Просмотреть файл

@ -2394,13 +2394,12 @@ func TestBuildOnBuildOutput(t *testing.T) {
}
func TestBuildInvalidTag(t *testing.T) {
name := "abcd:A0123456789B0123456789C0123456789"
name := "abcd:" + makeRandomString(200)
defer deleteImages(name)
_, out, err := buildImageWithOut(name, "FROM scratch\nMAINTAINER quux\n", true)
// if the error doesnt check for illegal tag name, or the image is built
// then this should fail
if !strings.Contains(err.Error(), "Illegal tag name") ||
strings.Contains(out, "Sending build context to Docker daemon") {
if !strings.Contains(out, "Illegal tag name") || strings.Contains(out, "Sending build context to Docker daemon") {
t.Fatalf("failed to stop before building. Error: %s, Output: %s", err, out)
}
logDone("build - invalid tag")

Просмотреть файл

@ -54,8 +54,9 @@ func TestTagInvalidUnprefixedRepo(t *testing.T) {
// ensure we don't allow the use of invalid tags; these tag operations should fail
func TestTagInvalidPrefixedRepo(t *testing.T) {
long_tag := makeRandomString(121)
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:fwaytoolongandwaymorethan30characterslong", "repo:-foo", "repo:.."}
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:..", long_tag}
for _, repotag := range invalidTags {
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repotag)

Просмотреть файл

@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"math/rand"
"net/http"
"net/http/httptest"
"os"
@ -255,3 +256,13 @@ func copyWithCP(source, target string) error {
}
return nil
}
func makeRandomString(n int) string {
// make a really long string
letters := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]byte, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}