github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/build/jib/jib_non_windows_test.go (about) 1 //go:build !windows 2 // +build !windows 3 4 /* 5 Copyright 2019 The Skaffold Authors 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 */ 19 20 package jib 21 22 import ( 23 "testing" 24 25 "github.com/GoogleContainerTools/skaffold/testutil" 26 ) 27 28 func TestRelativize(t *testing.T) { 29 tests := []struct { 30 description string 31 path string 32 roots []string 33 shouldErr bool 34 result string 35 }{ 36 {"relative passthrough 0", "relative", []string{}, false, "relative"}, 37 {"relative passthrough 1", "relative", []string{"/a"}, false, "relative"}, 38 {"error if abs and no roots", "/abs", []string{}, true, ""}, 39 {"error if not relative to roots", "/abs", []string{"/a", "/b", "/c"}, true, ""}, 40 {"found in root 0", "/a/z", []string{"/a"}, false, "z"}, 41 {"found in root 1", "/b/z", []string{"/a", "/b"}, false, "z"}, 42 {"multilevel found", "/b/c/d/z", []string{"/a", "/b"}, false, "c/d/z"}, 43 } 44 for _, test := range tests { 45 testutil.Run(t, test.description, func(t *testutil.T) { 46 rel, err := relativize(test.path, test.roots...) 47 48 t.CheckErrorAndDeepEqual(test.shouldErr, err, test.result, rel) 49 }) 50 } 51 }