1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix Tag Test for longer tags

Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
This commit is contained in:
Jessica Frazelle 2014-10-07 19:07:51 -07:00
parent 60908acff6
commit de32f48e66
3 changed files with 15 additions and 4 deletions

View file

@ -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")

View file

@ -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)

View file

@ -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)
}