mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add ValidateIndexName testcase
Signed-off-by: chchliang <chen.chuanliang@zte.com.cn>
This commit is contained in:
parent
239d61f04b
commit
0ddc903cec
1 changed files with 61 additions and 0 deletions
|
@ -317,3 +317,64 @@ func TestNewServiceConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateIndexName(t *testing.T) {
|
||||||
|
valid := []struct {
|
||||||
|
index string
|
||||||
|
expect string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
index: "index.docker.io",
|
||||||
|
expect: "docker.io",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
index: "example.com",
|
||||||
|
expect: "example.com",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
index: "127.0.0.1:8080",
|
||||||
|
expect: "127.0.0.1:8080",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
index: "mytest-1.com",
|
||||||
|
expect: "mytest-1.com",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
index: "mirror-1.com/v1/?q=foo",
|
||||||
|
expect: "mirror-1.com/v1/?q=foo",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range valid {
|
||||||
|
result, err := ValidateIndexName(testCase.index)
|
||||||
|
if assert.NoError(t, err) {
|
||||||
|
assert.Equal(t, testCase.expect, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateIndexNameWithError(t *testing.T) {
|
||||||
|
invalid := []struct {
|
||||||
|
index string
|
||||||
|
err string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
index: "docker.io-",
|
||||||
|
err: "invalid index name (docker.io-). Cannot begin or end with a hyphen",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
index: "-example.com",
|
||||||
|
err: "invalid index name (-example.com). Cannot begin or end with a hyphen",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
index: "mirror-1.com/v1/?q=foo-",
|
||||||
|
err: "invalid index name (mirror-1.com/v1/?q=foo-). Cannot begin or end with a hyphen",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, testCase := range invalid {
|
||||||
|
_, err := ValidateIndexName(testCase.index)
|
||||||
|
assert.EqualError(t, err, testCase.err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue