|
@@ -1,6 +1,7 @@
|
|
|
package registry
|
|
|
|
|
|
import (
|
|
|
+ "strings"
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
@@ -48,3 +49,57 @@ func TestValidateMirror(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestLoadInsecureRegistries(t *testing.T) {
|
|
|
+ testCases := []struct {
|
|
|
+ registries []string
|
|
|
+ index string
|
|
|
+ err string
|
|
|
+ }{
|
|
|
+ {
|
|
|
+ registries: []string{"http://mytest.com"},
|
|
|
+ index: "mytest.com",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ registries: []string{"https://mytest.com"},
|
|
|
+ index: "mytest.com",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ registries: []string{"HTTP://mytest.com"},
|
|
|
+ index: "mytest.com",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ registries: []string{"svn://mytest.com"},
|
|
|
+ err: "insecure registry svn://mytest.com should not contain '://'",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ registries: []string{"-invalid-registry"},
|
|
|
+ err: "Cannot begin or end with a hyphen",
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, testCase := range testCases {
|
|
|
+ config := newServiceConfig(ServiceOptions{})
|
|
|
+ err := config.LoadInsecureRegistries(testCase.registries)
|
|
|
+ if testCase.err == "" {
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("expect no error, got '%s'", err)
|
|
|
+ }
|
|
|
+ match := false
|
|
|
+ for index := range config.IndexConfigs {
|
|
|
+ if index == testCase.index {
|
|
|
+ match = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !match {
|
|
|
+ t.Fatalf("expect index configs to contain '%s', got %+v", testCase.index, config.IndexConfigs)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if err == nil {
|
|
|
+ t.Fatalf("expect error '%s', got no error", testCase.err)
|
|
|
+ }
|
|
|
+ if !strings.Contains(err.Error(), testCase.err) {
|
|
|
+ t.Fatalf("expect error '%s', got '%s'", testCase.err, err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|