github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/common/common_test.go (about) 1 // Copyright 2017 The rkt Authors 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 common 16 17 import ( 18 "testing" 19 20 "github.com/appc/spec/schema/types" 21 ) 22 23 func TestImageNameToAppName(t *testing.T) { 24 for _, tt := range []struct { 25 in types.ACIdentifier 26 out types.ACName 27 err bool 28 }{ 29 { 30 in: types.ACIdentifier("coreos.com/etcd:v2.0.0"), 31 out: types.ACName("etcd-v2-0-0"), 32 err: false, 33 }, 34 { 35 in: types.ACIdentifier("coreos.com/etcd"), 36 out: types.ACName("etcd"), 37 err: false, 38 }, 39 { 40 in: types.ACIdentifier("docker://registry.hub.docker.com/library/fedora"), 41 out: types.ACName("fedora"), 42 err: false, 43 }, 44 } { 45 appName, err := ImageNameToAppName(tt.in) 46 if err != nil { 47 if !tt.err { 48 t.Fatal(err) 49 } 50 } else if appName == nil { 51 t.Errorf("got nil app name without any error") 52 } else if *appName != tt.out { 53 t.Errorf("got %s app name, expected %s app name", appName, tt.out) 54 } 55 } 56 }