Deprecating ResolveRepositoryName
Passing RepositoryInfo to ResolveAuthConfig, pullRepository, and pushRepository Moving --registry-mirror configuration to registry config Created resolve_repository job Repo names with 'index.docker.io' or 'docker.io' are now synonymous with omitting an index name. Adding test for RepositoryInfo Adding tests for opts.StringSetOpts and registry.ValidateMirror Fixing search term use of repoInfo Adding integration tests for registry mirror configuration Normalizing LookupImage image name to match LocalName parsing rules Normalizing repository LocalName to avoid multiple references to an official image Removing errorOut use in tests Removing TODO comment gofmt changes golint comments cleanup. renaming RegistryOptions => registry.Options, and RegistryServiceConfig => registry.ServiceConfig Splitting out builtins.Registry and registry.NewService calls Stray whitespace cleanup Moving integration tests for Mirrors and InsecureRegistries into TestNewIndexInfo unit test Factoring out ValidateRepositoryName from NewRepositoryInfo Removing unused IndexServerURL Allowing json marshaling of ServiceConfig. Exposing ServiceConfig in /info Switching to CamelCase for json marshaling PR cleanup; removing 'Is' prefix from boolean members. Removing unneeded json tags. Removing non-cleanup related fix for 'localhost:[port]' in splitReposName Merge fixes for gh9735 Fixing integration test Reapplying #9754 Adding comment on config.IndexConfigs use from isSecureIndex Remove unused error return value from isSecureIndex Signed-off-by: Don Kjer <don.kjer@gmail.com> Adding back comment in isSecureIndex Signed-off-by: Don Kjer <don.kjer@gmail.com>
This commit is contained in:
parent
eb9ddb7b86
commit
64b000c3ea
11 changed files with 1179 additions and 156 deletions
|
@ -15,15 +15,16 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/opts"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
testHTTPServer *httptest.Server
|
||||
insecureRegistries []string
|
||||
testLayers = map[string]map[string]string{
|
||||
testHTTPServer *httptest.Server
|
||||
testHTTPSServer *httptest.Server
|
||||
testLayers = map[string]map[string]string{
|
||||
"77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20": {
|
||||
"json": `{"id":"77dbf71da1d00e3fbddc480176eac8994025630c6590d11cfc8fe1209c2a1d20",
|
||||
"comment":"test base image","created":"2013-03-23T12:53:11.10432-07:00",
|
||||
|
@ -86,6 +87,7 @@ var (
|
|||
"": {net.ParseIP("0.0.0.0")},
|
||||
"localhost": {net.ParseIP("127.0.0.1"), net.ParseIP("::1")},
|
||||
"example.com": {net.ParseIP("42.42.42.42")},
|
||||
"other.com": {net.ParseIP("43.43.43.43")},
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -108,11 +110,7 @@ func init() {
|
|||
r.HandleFunc("/v2/version", handlerGetPing).Methods("GET")
|
||||
|
||||
testHTTPServer = httptest.NewServer(handlerAccessLog(r))
|
||||
URL, err := url.Parse(testHTTPServer.URL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
insecureRegistries = []string{URL.Host}
|
||||
testHTTPSServer = httptest.NewTLSServer(handlerAccessLog(r))
|
||||
|
||||
// override net.LookupIP
|
||||
lookupIP = func(host string) ([]net.IP, error) {
|
||||
|
@ -146,6 +144,52 @@ func makeURL(req string) string {
|
|||
return testHTTPServer.URL + req
|
||||
}
|
||||
|
||||
func makeHttpsURL(req string) string {
|
||||
return testHTTPSServer.URL + req
|
||||
}
|
||||
|
||||
func makeIndex(req string) *IndexInfo {
|
||||
index := &IndexInfo{
|
||||
Name: makeURL(req),
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
func makeHttpsIndex(req string) *IndexInfo {
|
||||
index := &IndexInfo{
|
||||
Name: makeHttpsURL(req),
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
func makePublicIndex() *IndexInfo {
|
||||
index := &IndexInfo{
|
||||
Name: IndexServerAddress(),
|
||||
Secure: true,
|
||||
Official: true,
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
func makeServiceConfig(mirrors []string, insecure_registries []string) *ServiceConfig {
|
||||
options := &Options{
|
||||
Mirrors: opts.NewListOpts(nil),
|
||||
InsecureRegistries: opts.NewListOpts(nil),
|
||||
}
|
||||
if mirrors != nil {
|
||||
for _, mirror := range mirrors {
|
||||
options.Mirrors.Set(mirror)
|
||||
}
|
||||
}
|
||||
if insecure_registries != nil {
|
||||
for _, insecure_registries := range insecure_registries {
|
||||
options.InsecureRegistries.Set(insecure_registries)
|
||||
}
|
||||
}
|
||||
|
||||
return NewServiceConfig(options)
|
||||
}
|
||||
|
||||
func writeHeaders(w http.ResponseWriter) {
|
||||
h := w.Header()
|
||||
h.Add("Server", "docker-tests/mock")
|
||||
|
@ -193,6 +237,40 @@ func assertEqual(t *testing.T, a interface{}, b interface{}, message string) {
|
|||
t.Fatal(message)
|
||||
}
|
||||
|
||||
func assertNotEqual(t *testing.T, a interface{}, b interface{}, message string) {
|
||||
if a != b {
|
||||
return
|
||||
}
|
||||
if len(message) == 0 {
|
||||
message = fmt.Sprintf("%v == %v", a, b)
|
||||
}
|
||||
t.Fatal(message)
|
||||
}
|
||||
|
||||
// Similar to assertEqual, but does not stop test
|
||||
func checkEqual(t *testing.T, a interface{}, b interface{}, messagePrefix string) {
|
||||
if a == b {
|
||||
return
|
||||
}
|
||||
message := fmt.Sprintf("%v != %v", a, b)
|
||||
if len(messagePrefix) != 0 {
|
||||
message = messagePrefix + ": " + message
|
||||
}
|
||||
t.Error(message)
|
||||
}
|
||||
|
||||
// Similar to assertNotEqual, but does not stop test
|
||||
func checkNotEqual(t *testing.T, a interface{}, b interface{}, messagePrefix string) {
|
||||
if a != b {
|
||||
return
|
||||
}
|
||||
message := fmt.Sprintf("%v == %v", a, b)
|
||||
if len(messagePrefix) != 0 {
|
||||
message = messagePrefix + ": " + message
|
||||
}
|
||||
t.Error(message)
|
||||
}
|
||||
|
||||
func requiresAuth(w http.ResponseWriter, r *http.Request) bool {
|
||||
writeCookie := func() {
|
||||
value := fmt.Sprintf("FAKE-SESSION-%d", time.Now().UnixNano())
|
||||
|
@ -271,6 +349,7 @@ func handlerGetDeleteTags(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
repositoryName := mux.Vars(r)["repository"]
|
||||
repositoryName = NormalizeLocalName(repositoryName)
|
||||
tags, exists := testRepositories[repositoryName]
|
||||
if !exists {
|
||||
apiError(w, "Repository not found", 404)
|
||||
|
@ -290,6 +369,7 @@ func handlerGetTag(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
vars := mux.Vars(r)
|
||||
repositoryName := vars["repository"]
|
||||
repositoryName = NormalizeLocalName(repositoryName)
|
||||
tagName := vars["tag"]
|
||||
tags, exists := testRepositories[repositoryName]
|
||||
if !exists {
|
||||
|
@ -310,6 +390,7 @@ func handlerPutTag(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
vars := mux.Vars(r)
|
||||
repositoryName := vars["repository"]
|
||||
repositoryName = NormalizeLocalName(repositoryName)
|
||||
tagName := vars["tag"]
|
||||
tags, exists := testRepositories[repositoryName]
|
||||
if !exists {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue