github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/azure/convert_test.go (about) 1 // Copyright 2022 Harness, Inc. 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 azure 16 17 import ( 18 "io/ioutil" 19 "path/filepath" 20 "testing" 21 22 "github.com/google/go-cmp/cmp" 23 "gopkg.in/yaml.v3" 24 ) 25 26 func TestConvert(t *testing.T) { 27 tests, err := filepath.Glob("testdata/*/*.yaml") 28 if err != nil { 29 t.Error(err) 30 return 31 } 32 33 for _, test := range tests { 34 t.Run(test, func(t *testing.T) { 35 // convert the yaml file from azure to harness 36 converter := New() 37 tmp1, err := converter.ConvertFile(test) 38 if err != nil { 39 t.Error(err) 40 return 41 } 42 43 // unmarshal the converted yaml file to a map 44 got := map[string]interface{}{} 45 if err := yaml.Unmarshal(tmp1, &got); err != nil { 46 t.Error(err) 47 return 48 } 49 50 // parse the golden yaml file 51 data, err := ioutil.ReadFile(test + ".golden") 52 if err != nil { 53 t.Error(err) 54 return 55 } 56 57 // unmarshal the golden yaml file to a map 58 want := map[string]interface{}{} 59 if err := yaml.Unmarshal(data, &want); err != nil { 60 t.Error(err) 61 return 62 } 63 64 // compare the converted yaml to the golden file 65 if diff := cmp.Diff(got, want); diff != "" { 66 t.Errorf("Unexpected conversion result") 67 t.Log(diff) 68 } 69 }) 70 } 71 }