github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/image/save/save_test.go (about) 1 // Copyright © 2021 Alibaba Group Holding Ltd. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package save 16 17 import ( 18 "testing" 19 ) 20 21 /* func TestSaveImages(t *testing.T) { 22 tests := []string{"ubuntu", "ubuntu:18.04", "registry.aliyuncs.com/google_containers/coredns:1.6.5", "fanux/lvscare", "kubernetesui/dashboard:v2.2.0", "multiarch/ubuntu-core:arm64-focal"} 23 is := NewImageSaver(context.Background()) 24 err := is.SaveImages(tests, "/var/lib/registry", v1.Platform{OS: "linux", Architecture: "amd64"}) 25 if err != nil { 26 t.Error(err) 27 } 28 } 29 */ 30 31 func Test_splitDockerDomain(t *testing.T) { 32 tests := []struct { 33 name string 34 imageName string 35 wantDomain string 36 wantRemain string 37 }{ 38 { 39 name: "test1", 40 imageName: "docker.io/library/alpine:latest", 41 wantDomain: defaultDomain, 42 wantRemain: "library/alpine:latest", 43 }, 44 { 45 name: "test2", 46 imageName: "ubuntu", 47 wantDomain: defaultDomain, 48 wantRemain: "library/ubuntu", 49 }, 50 { 51 name: "test3", 52 imageName: "registry.k8s.io/kube-apiserver", 53 wantDomain: "registry.k8s.io", 54 wantRemain: "kube-apiserver", 55 }, 56 } 57 for _, tt := range tests { 58 t.Run(tt.name, func(t *testing.T) { 59 if domain, remainer := splitDockerDomain(tt.imageName, ""); domain != tt.wantDomain || remainer != tt.wantRemain { 60 t.Errorf("split image %s error", tt.name) 61 } 62 }) 63 } 64 } 65 66 func Test_parseNormalizedNamed(t *testing.T) { 67 tests := []struct { 68 name string 69 imageName string 70 wantDomain string 71 wantRepo string 72 wantTag string 73 }{ 74 { 75 name: "test1", 76 imageName: "docker.io/library/alpine:latest", 77 wantDomain: defaultDomain, 78 wantRepo: "library/alpine", 79 wantTag: defaultTag, 80 }, 81 { 82 name: "test2", 83 imageName: "ubuntu", 84 wantDomain: defaultDomain, 85 wantRepo: "library/ubuntu", 86 wantTag: defaultTag, 87 }, 88 { 89 name: "test3", 90 imageName: "registry.k8s.io/kube-apiserver", 91 wantDomain: "registry.k8s.io", 92 wantRepo: "kube-apiserver", 93 wantTag: defaultTag, 94 }, 95 { 96 name: "test4", 97 imageName: "fanux/lvscare", 98 wantDomain: defaultDomain, 99 wantRepo: "fanux/lvscare", 100 wantTag: defaultTag, 101 }, 102 { 103 name: "test5", 104 imageName: "alpine", 105 wantDomain: defaultDomain, 106 wantRepo: "library/alpine", 107 wantTag: defaultTag, 108 }, 109 } 110 111 for _, tt := range tests { 112 t.Run(tt.name, func(t *testing.T) { 113 if named, err := ParseNormalizedNamed(tt.imageName, ""); err != nil || named.Domain() != tt.wantDomain || named.Repo() != tt.wantRepo || named.tag != tt.wantTag { 114 t.Errorf("parse image %s error", tt.name) 115 } 116 }) 117 } 118 }