Ver Fonte

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

Fix Tag Test for longer tags
Victor Vieux há 10 anos atrás
pai
commit
0d5daa4a8f

+ 2 - 3
integration-cli/docker_cli_build_test.go

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

+ 2 - 1
integration-cli/docker_cli_tag_test.go

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

+ 11 - 0
integration-cli/utils.go

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