github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/artifactory/utils/docker/docker_test.go (about) 1 package docker 2 3 import ( 4 "testing" 5 ) 6 7 func TestGetImagePath(t *testing.T) { 8 var imageTags = []struct { 9 in string 10 expected string 11 }{ 12 {"domain:8080/path:1.0", "/path/1.0"}, 13 {"domain:8080/path/in/artifactory:1.0", "/path/in/artifactory/1.0"}, 14 {"domain:8080/path/in/artifactory", "/path/in/artifactory/latest"}, 15 {"domain/path:1.0", "/path/1.0"}, 16 {"domain/path/in/artifactory:1.0", "/path/in/artifactory/1.0"}, 17 {"domain/path/in/artifactory", "/path/in/artifactory/latest"}, 18 } 19 20 for _, v := range imageTags { 21 result := New(v.in).Path() 22 if result != v.expected { 23 t.Errorf("Path(\"%s\") => '%s', want '%s'", v.in, result, v.expected) 24 } 25 } 26 } 27 28 func TestGetImageName(t *testing.T) { 29 var imageTags = []struct { 30 in string 31 expected string 32 }{ 33 {"domain:8080/path:1.0", "path:1.0"}, 34 {"domain:8080/path/in/artifactory:1.0", "artifactory:1.0"}, 35 {"domain:8080/path/in/artifactory", "artifactory:latest"}, 36 {"domain/path:1.0", "path:1.0"}, 37 {"domain/path/in/artifactory:1.0", "artifactory:1.0"}, 38 {"domain/path/in/artifactory", "artifactory:latest"}, 39 } 40 41 for _, v := range imageTags { 42 result := New(v.in).Name() 43 if result != v.expected { 44 t.Errorf("Name(\"%s\") => '%s', want '%s'", v.in, result, v.expected) 45 } 46 } 47 } 48 49 func TestResolveRegistryFromTag(t *testing.T) { 50 var imageTags = []struct { 51 in string 52 expected string 53 expectingError bool 54 }{ 55 {"domain:8080/path:1.0", "domain:8080", false}, 56 {"domain:8080/path/in/artifactory:1.0", "domain:8080/path", false}, 57 {"domain:8080/path/in/artifactory", "domain:8080/path", false}, 58 {"domain/path:1.0", "domain", false}, 59 {"domain/path/in/artifactory:1.0", "domain/path", false}, 60 {"domain/path/in/artifactory", "domain/path", false}, 61 {"domain:8081", "", true}, 62 } 63 64 for _, v := range imageTags { 65 result, err := ResolveRegistryFromTag(v.in) 66 if err != nil && !v.expectingError { 67 t.Error(err.Error()) 68 } 69 if result != v.expected { 70 t.Errorf("ResolveRegistryFromTag(\"%s\") => '%s', expected '%s'", v.in, result, v.expected) 71 } 72 } 73 } 74 75 func TestDockerClientApiVersionRegex(t *testing.T) { 76 var versionStrings = []struct { 77 in string 78 expected bool 79 }{ 80 {"1", false}, 81 {"1.1", true}, 82 {"1.11", true}, 83 {"12.12", true}, 84 {"1.1.11", false}, 85 {"1.illegal", false}, 86 {"1 11", false}, 87 } 88 89 for _, v := range versionStrings { 90 result := ApiVersionRegex.Match([]byte(v.in)) 91 if result != v.expected { 92 t.Errorf("Version(\"%s\") => '%v', want '%v'", v.in, result, v.expected) 93 } 94 } 95 }