Browse code

Fix Tag Test for longer tags

Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)

Jessica Frazelle authored on 2014/10/08 11:07:51
Showing 3 changed files
... ...
@@ -2394,13 +2394,12 @@ func TestBuildOnBuildOutput(t *testing.T) {
2394 2394
 }
2395 2395
 
2396 2396
 func TestBuildInvalidTag(t *testing.T) {
2397
-	name := "abcd:A0123456789B0123456789C0123456789"
2397
+	name := "abcd:" + makeRandomString(200)
2398 2398
 	defer deleteImages(name)
2399 2399
 	_, out, err := buildImageWithOut(name, "FROM scratch\nMAINTAINER quux\n", true)
2400 2400
 	// if the error doesnt check for illegal tag name, or the image is built
2401 2401
 	// then this should fail
2402
-	if !strings.Contains(err.Error(), "Illegal tag name") ||
2403
-		strings.Contains(out, "Sending build context to Docker daemon") {
2402
+	if !strings.Contains(out, "Illegal tag name") || strings.Contains(out, "Sending build context to Docker daemon") {
2404 2403
 		t.Fatalf("failed to stop before building. Error: %s, Output: %s", err, out)
2405 2404
 	}
2406 2405
 	logDone("build - invalid tag")
... ...
@@ -54,8 +54,9 @@ func TestTagInvalidUnprefixedRepo(t *testing.T) {
54 54
 
55 55
 // ensure we don't allow the use of invalid tags; these tag operations should fail
56 56
 func TestTagInvalidPrefixedRepo(t *testing.T) {
57
+	long_tag := makeRandomString(121)
57 58
 
58
-	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:.."}
59
+	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}
59 60
 
60 61
 	for _, repotag := range invalidTags {
61 62
 		tagCmd := exec.Command(dockerBinary, "tag", "busybox", repotag)
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"encoding/json"
6 6
 	"fmt"
7 7
 	"io"
8
+	"math/rand"
8 9
 	"net/http"
9 10
 	"net/http/httptest"
10 11
 	"os"
... ...
@@ -255,3 +256,13 @@ func copyWithCP(source, target string) error {
255 255
 	}
256 256
 	return nil
257 257
 }
258
+
259
+func makeRandomString(n int) string {
260
+	// make a really long string
261
+	letters := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
262
+	b := make([]byte, n)
263
+	for i := range b {
264
+		b[i] = letters[rand.Intn(len(letters))]
265
+	}
266
+	return string(b)
267
+}