github.com/GoogleContainerTools/kaniko@v1.23.0/pkg/util/bucket/bucket_util_test.go (about) 1 /* 2 Copyright 2018 Google LLC 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package bucket 18 19 import ( 20 "testing" 21 22 "github.com/GoogleContainerTools/kaniko/pkg/constants" 23 "github.com/GoogleContainerTools/kaniko/testutil" 24 ) 25 26 func Test_GetBucketAndItem(t *testing.T) { 27 tests := []struct { 28 name string 29 context string 30 expectedBucket string 31 expectedItem string 32 expectedErr bool 33 }{ 34 { 35 name: "three slashes", 36 context: "gs://test1/test2/test3", 37 expectedBucket: "test1", 38 expectedItem: "test2/test3", 39 }, 40 { 41 name: "two slashes", 42 context: "gs://test1/test2", 43 expectedBucket: "test1", 44 expectedItem: "test2", 45 }, 46 { 47 name: "one slash", 48 context: "gs://test1/", 49 expectedBucket: "test1", 50 expectedItem: constants.ContextTar, 51 }, 52 { 53 name: "zero slash", 54 context: "gs://test1", 55 expectedBucket: "test1", 56 expectedItem: constants.ContextTar, 57 }, 58 } 59 60 for _, test := range tests { 61 t.Run(test.name, func(t *testing.T) { 62 gotBucket, gotItem, err := GetNameAndFilepathFromURI(test.context) 63 testutil.CheckError(t, test.expectedErr, err) 64 testutil.CheckDeepEqual(t, test.expectedBucket, gotBucket) 65 testutil.CheckDeepEqual(t, test.expectedItem, gotItem) 66 }) 67 } 68 69 }