Unify the testcases for the two tests in names_test.go
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
		
							parent
							
								
									9423b38d5f
								
							
						
					
					
						commit
						0d27f70d0c
					
				
					 1 changed files with 76 additions and 153 deletions
				
			
		|  | @ -6,10 +6,18 @@ import ( | ||||||
| 	"testing" | 	"testing" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func TestRepositoryComponentNameRegexp(t *testing.T) { | var ( | ||||||
| 	for _, testcase := range []struct { | 	// regexpTestcases is a unified set of testcases for | ||||||
|  | 	// TestValidateRepositoryName and TestRepositoryNameRegexp. | ||||||
|  | 	// Some of them are valid inputs for one and not the other. | ||||||
|  | 	regexpTestcases = []struct { | ||||||
|  | 		// input is the repository name or name component testcase | ||||||
| 		input string | 		input string | ||||||
| 		err   error | 		// err is the error expected from ValidateRepositoryName, or nil | ||||||
|  | 		err error | ||||||
|  | 		// invalid should be true if the testcase is *not* expected to | ||||||
|  | 		// match RepositoryNameRegexp | ||||||
|  | 		invalid bool | ||||||
| 	}{ | 	}{ | ||||||
| 		{ | 		{ | ||||||
| 			input: "", | 			input: "", | ||||||
|  | @ -37,12 +45,14 @@ func TestRepositoryComponentNameRegexp(t *testing.T) { | ||||||
| 			input: "a/a/a/b/b", | 			input: "a/a/a/b/b", | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "a/a/a/a/", | 			input:   "a/a/a/a/", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "a//a/a", | 			input:   "a//a/a", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "a", | 			input: "a", | ||||||
|  | @ -56,9 +66,27 @@ func TestRepositoryComponentNameRegexp(t *testing.T) { | ||||||
| 		{ | 		{ | ||||||
| 			input: "a/aa/a", | 			input: "a/aa/a", | ||||||
| 		}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			input:   "foo.com/", | ||||||
|  | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			// TODO: this testcase should be valid once we switch to | ||||||
|  | 			// the reference package. | ||||||
|  | 			input:   "foo.com:8080/bar", | ||||||
|  | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			input: "foo.com/bar", | ||||||
|  | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "foo.com/bar/baz", | 			input: "foo.com/bar/baz", | ||||||
| 		}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			input: "foo.com/bar/baz/quux", | ||||||
|  | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "blog.foo.com/bar/baz", | 			input: "blog.foo.com/bar/baz", | ||||||
| 		}, | 		}, | ||||||
|  | @ -66,8 +94,9 @@ func TestRepositoryComponentNameRegexp(t *testing.T) { | ||||||
| 			input: "asdf", | 			input: "asdf", | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "asdf$$^/aa", | 			input:   "asdf$$^/aa", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "aa-a/aa", | 			input: "aa-a/aa", | ||||||
|  | @ -79,8 +108,9 @@ func TestRepositoryComponentNameRegexp(t *testing.T) { | ||||||
| 			input: "a-a/a-a", | 			input: "a-a/a-a", | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "a-/a/a/a", | 			input:   "a-/a/a/a", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: strings.Repeat("a", 255), | 			input: strings.Repeat("a", 255), | ||||||
|  | @ -90,42 +120,57 @@ func TestRepositoryComponentNameRegexp(t *testing.T) { | ||||||
| 			err:   ErrRepositoryNameLong, | 			err:   ErrRepositoryNameLong, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "-foo/bar", | 			input:   "-foo/bar", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "foo/bar-", | 			input:   "foo/bar-", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "foo-/bar", | 			input:   "foo-/bar", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "foo/-bar", | 			input:   "foo/-bar", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "_foo/bar", | 			input:   "_foo/bar", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "foo/bar_", | 			input:   "foo/bar_", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "____/____", | 			input:   "____/____", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "_docker/_docker", | 			input:   "_docker/_docker", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "docker_/docker_", | 			input:   "docker_/docker_", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:     ErrRepositoryNameComponentInvalid, | ||||||
|  | 			invalid: true, | ||||||
| 		}, | 		}, | ||||||
| 	} { | 	} | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | // TestValidateRepositoryName tests the ValidateRepositoryName function, | ||||||
|  | // which uses RepositoryNameComponentAnchoredRegexp for validation | ||||||
|  | func TestValidateRepositoryName(t *testing.T) { | ||||||
|  | 	for _, testcase := range regexpTestcases { | ||||||
| 		failf := func(format string, v ...interface{}) { | 		failf := func(format string, v ...interface{}) { | ||||||
| 			t.Logf(strconv.Quote(testcase.input)+": "+format, v...) | 			t.Logf(strconv.Quote(testcase.input)+": "+format, v...) | ||||||
| 			t.Fail() | 			t.Fail() | ||||||
|  | @ -151,129 +196,7 @@ func TestRepositoryComponentNameRegexp(t *testing.T) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestRepositoryNameRegexp(t *testing.T) { | func TestRepositoryNameRegexp(t *testing.T) { | ||||||
| 	for _, testcase := range []struct { | 	for _, testcase := range regexpTestcases { | ||||||
| 		input   string |  | ||||||
| 		invalid bool |  | ||||||
| 	}{ |  | ||||||
| 		{ |  | ||||||
| 			input: "short", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "simple/name", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "library/ubuntu", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "docker/stevvooe/app", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "aa/aa/aa/aa/aa/aa/aa/aa/aa/bb/bb/bb/bb/bb/bb", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "aa/aa/bb/bb/bb", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "a/a/a/b/b", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "a/a/a/a/", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "a//a/a", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "a", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "a/aa", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "aa/a", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "a/aa/a", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "foo.com/", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			// currently not allowed by the regex |  | ||||||
| 			input:   "foo.com:8080/bar", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "foo.com/bar", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "foo.com/bar/baz", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "foo.com/bar/baz/quux", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "blog.foo.com/bar/baz", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "asdf", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "asdf$$^/aa", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "aa-a/aa", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "aa/aa", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input: "a-a/a-a", |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "a-/a/a/a", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "-foo/bar", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "foo/bar-", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "foo-/bar", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "foo/-bar", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "_foo/bar", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "foo/bar_", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "____/____", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "_docker/_docker", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 		{ |  | ||||||
| 			input:   "docker_/docker_", |  | ||||||
| 			invalid: true, |  | ||||||
| 		}, |  | ||||||
| 	} { |  | ||||||
| 		failf := func(format string, v ...interface{}) { | 		failf := func(format string, v ...interface{}) { | ||||||
| 			t.Logf(strconv.Quote(testcase.input)+": "+format, v...) | 			t.Logf(strconv.Quote(testcase.input)+": "+format, v...) | ||||||
| 			t.Fail() | 			t.Fail() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue