|
@@ -10,6 +10,8 @@ import (
|
|
|
|
|
|
"github.com/docker/distribution/reference"
|
|
|
"github.com/docker/distribution/registry/client/transport"
|
|
|
+ "github.com/docker/docker/api/types"
|
|
|
+ registrytypes "github.com/docker/docker/api/types/registry"
|
|
|
)
|
|
|
|
|
|
var (
|
|
@@ -49,7 +51,7 @@ func spawnTestRegistrySession(t *testing.T) *Session {
|
|
|
}
|
|
|
|
|
|
func TestPingRegistryEndpoint(t *testing.T) {
|
|
|
- testPing := func(index *IndexInfo, expectedStandalone bool, assertMessage string) {
|
|
|
+ testPing := func(index *registrytypes.IndexInfo, expectedStandalone bool, assertMessage string) {
|
|
|
ep, err := NewEndpoint(index, nil, APIVersionUnknown)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
@@ -69,7 +71,7 @@ func TestPingRegistryEndpoint(t *testing.T) {
|
|
|
|
|
|
func TestEndpoint(t *testing.T) {
|
|
|
// Simple wrapper to fail test if err != nil
|
|
|
- expandEndpoint := func(index *IndexInfo) *Endpoint {
|
|
|
+ expandEndpoint := func(index *registrytypes.IndexInfo) *Endpoint {
|
|
|
endpoint, err := NewEndpoint(index, nil, APIVersionUnknown)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
@@ -77,7 +79,7 @@ func TestEndpoint(t *testing.T) {
|
|
|
return endpoint
|
|
|
}
|
|
|
|
|
|
- assertInsecureIndex := func(index *IndexInfo) {
|
|
|
+ assertInsecureIndex := func(index *registrytypes.IndexInfo) {
|
|
|
index.Secure = true
|
|
|
_, err := NewEndpoint(index, nil, APIVersionUnknown)
|
|
|
assertNotEqual(t, err, nil, index.Name+": Expected error for insecure index")
|
|
@@ -85,7 +87,7 @@ func TestEndpoint(t *testing.T) {
|
|
|
index.Secure = false
|
|
|
}
|
|
|
|
|
|
- assertSecureIndex := func(index *IndexInfo) {
|
|
|
+ assertSecureIndex := func(index *registrytypes.IndexInfo) {
|
|
|
index.Secure = true
|
|
|
_, err := NewEndpoint(index, nil, APIVersionUnknown)
|
|
|
assertNotEqual(t, err, nil, index.Name+": Expected cert error for secure index")
|
|
@@ -93,7 +95,7 @@ func TestEndpoint(t *testing.T) {
|
|
|
index.Secure = false
|
|
|
}
|
|
|
|
|
|
- index := &IndexInfo{}
|
|
|
+ index := ®istrytypes.IndexInfo{}
|
|
|
index.Name = makeURL("/v1/")
|
|
|
endpoint := expandEndpoint(index)
|
|
|
assertEqual(t, endpoint.String(), index.Name, "Expected endpoint to be "+index.Name)
|
|
@@ -363,7 +365,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
|
|
|
expectedRepoInfos := map[string]RepositoryInfo{
|
|
|
"fooo/bar": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
|
},
|
|
@@ -373,7 +375,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"library/ubuntu": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
|
},
|
|
@@ -383,7 +385,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: true,
|
|
|
},
|
|
|
"nonlibrary/ubuntu": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
|
},
|
|
@@ -393,7 +395,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"ubuntu": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
|
},
|
|
@@ -403,7 +405,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: true,
|
|
|
},
|
|
|
"other/library": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
|
},
|
|
@@ -413,7 +415,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"127.0.0.1:8000/private/moonbase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: "127.0.0.1:8000",
|
|
|
Official: false,
|
|
|
},
|
|
@@ -423,7 +425,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"127.0.0.1:8000/privatebase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: "127.0.0.1:8000",
|
|
|
Official: false,
|
|
|
},
|
|
@@ -433,7 +435,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"localhost:8000/private/moonbase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: "localhost:8000",
|
|
|
Official: false,
|
|
|
},
|
|
@@ -443,7 +445,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"localhost:8000/privatebase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: "localhost:8000",
|
|
|
Official: false,
|
|
|
},
|
|
@@ -453,7 +455,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"example.com/private/moonbase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: "example.com",
|
|
|
Official: false,
|
|
|
},
|
|
@@ -463,7 +465,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"example.com/privatebase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: "example.com",
|
|
|
Official: false,
|
|
|
},
|
|
@@ -473,7 +475,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"example.com:8000/private/moonbase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: "example.com:8000",
|
|
|
Official: false,
|
|
|
},
|
|
@@ -483,7 +485,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"example.com:8000/privatebase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: "example.com:8000",
|
|
|
Official: false,
|
|
|
},
|
|
@@ -493,7 +495,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"localhost/private/moonbase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: "localhost",
|
|
|
Official: false,
|
|
|
},
|
|
@@ -503,7 +505,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"localhost/privatebase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: "localhost",
|
|
|
Official: false,
|
|
|
},
|
|
@@ -513,7 +515,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
IndexName + "/public/moonbase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
|
},
|
|
@@ -523,7 +525,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"index." + IndexName + "/public/moonbase": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
|
},
|
|
@@ -533,7 +535,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: false,
|
|
|
},
|
|
|
"ubuntu-12.04-base": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
|
},
|
|
@@ -543,7 +545,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: true,
|
|
|
},
|
|
|
IndexName + "/ubuntu-12.04-base": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
|
},
|
|
@@ -553,7 +555,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
Official: true,
|
|
|
},
|
|
|
"index." + IndexName + "/ubuntu-12.04-base": {
|
|
|
- Index: &IndexInfo{
|
|
|
+ Index: ®istrytypes.IndexInfo{
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
|
},
|
|
@@ -585,9 +587,9 @@ func TestParseRepositoryInfo(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestNewIndexInfo(t *testing.T) {
|
|
|
- testIndexInfo := func(config *ServiceConfig, expectedIndexInfos map[string]*IndexInfo) {
|
|
|
+ testIndexInfo := func(config *registrytypes.ServiceConfig, expectedIndexInfos map[string]*registrytypes.IndexInfo) {
|
|
|
for indexName, expectedIndexInfo := range expectedIndexInfos {
|
|
|
- index, err := config.NewIndexInfo(indexName)
|
|
|
+ index, err := newIndexInfo(config, indexName)
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
} else {
|
|
@@ -601,7 +603,7 @@ func TestNewIndexInfo(t *testing.T) {
|
|
|
|
|
|
config := NewServiceConfig(nil)
|
|
|
noMirrors := []string{}
|
|
|
- expectedIndexInfos := map[string]*IndexInfo{
|
|
|
+ expectedIndexInfos := map[string]*registrytypes.IndexInfo{
|
|
|
IndexName: {
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
@@ -632,7 +634,7 @@ func TestNewIndexInfo(t *testing.T) {
|
|
|
publicMirrors := []string{"http://mirror1.local", "http://mirror2.local"}
|
|
|
config = makeServiceConfig(publicMirrors, []string{"example.com"})
|
|
|
|
|
|
- expectedIndexInfos = map[string]*IndexInfo{
|
|
|
+ expectedIndexInfos = map[string]*registrytypes.IndexInfo{
|
|
|
IndexName: {
|
|
|
Name: IndexName,
|
|
|
Official: true,
|
|
@@ -679,7 +681,7 @@ func TestNewIndexInfo(t *testing.T) {
|
|
|
testIndexInfo(config, expectedIndexInfos)
|
|
|
|
|
|
config = makeServiceConfig(nil, []string{"42.42.0.0/16"})
|
|
|
- expectedIndexInfos = map[string]*IndexInfo{
|
|
|
+ expectedIndexInfos = map[string]*registrytypes.IndexInfo{
|
|
|
"example.com": {
|
|
|
Name: "example.com",
|
|
|
Official: false,
|
|
@@ -981,7 +983,7 @@ func TestIsSecureIndex(t *testing.T) {
|
|
|
}
|
|
|
for _, tt := range tests {
|
|
|
config := makeServiceConfig(nil, tt.insecureRegistries)
|
|
|
- if sec := config.isSecureIndex(tt.addr); sec != tt.expected {
|
|
|
+ if sec := isSecureIndex(config, tt.addr); sec != tt.expected {
|
|
|
t.Errorf("isSecureIndex failed for %q %v, expected %v got %v", tt.addr, tt.insecureRegistries, tt.expected, sec)
|
|
|
}
|
|
|
}
|