github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/build/buildpacks/metadata_test.go (about) 1 /* 2 Copyright 2019 The Skaffold Authors 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 buildpacks 18 19 import ( 20 "testing" 21 22 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" 23 "github.com/GoogleContainerTools/skaffold/testutil" 24 ) 25 26 func TestSyncRules(t *testing.T) { 27 tests := []struct { 28 description string 29 labels map[string]string 30 expectedRules []*latest.SyncRule 31 shouldErr bool 32 }{ 33 { 34 description: "missing labels", 35 labels: map[string]string{}, 36 }, 37 { 38 description: "invalid labels", 39 labels: map[string]string{ 40 "io.buildpacks.build.metadata": "invalid", 41 }, 42 shouldErr: true, 43 }, 44 { 45 description: "valid labels", 46 labels: map[string]string{ 47 "io.buildpacks.build.metadata": `{ 48 "bom":[{ 49 "metadata":{ 50 "devmode.sync": [ 51 {"src":"src-value1","dest":"dest-value1"}, 52 {"src":"src-value2","dest":"dest-value2"} 53 ] 54 } 55 }] 56 }`, 57 }, 58 expectedRules: []*latest.SyncRule{ 59 {Src: "src-value1", Dest: "dest-value1"}, 60 {Src: "src-value2", Dest: "dest-value2"}, 61 }, 62 }, 63 } 64 for _, test := range tests { 65 testutil.Run(t, test.description, func(t *testutil.T) { 66 rules, err := SyncRules(test.labels) 67 68 t.CheckErrorAndDeepEqual(test.shouldErr, err, test.expectedRules, rules) 69 }) 70 } 71 }