github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/bitbucket/converter_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 bitbucket 16 17 import ( 18 "io/ioutil" 19 "testing" 20 21 "github.com/google/go-cmp/cmp" 22 "gopkg.in/yaml.v3" 23 ) 24 25 func TestConvert(t *testing.T) { 26 // tests, err := filepath.Glob("testdata/*/*.yaml") 27 // if err != nil { 28 // t.Error(err) 29 // return 30 // } 31 32 // TODO use glob once we have more test cases complete 33 tests := []string{ 34 "testdata/clone/example1.yaml", 35 "testdata/clone/example2.yaml", 36 "testdata/clone/example3.yaml", // TODO LFS 37 "testdata/clone/example4.yaml", // TODO convert BITBUCKET_ variables 38 "testdata/clone/example5.yaml", 39 "testdata/clone/example6.yaml", 40 "testdata/clone/example7.yaml", 41 "testdata/clone/example8.yaml", // TODO LFS 42 "testdata/clone/example9.yaml", // TODO LFS 43 "testdata/clone/example10.yaml", 44 45 "testdata/definitions/example1.yaml", 46 // "testdata/definitions/example2.yaml", // TODO handle non-default pipelines 47 "testdata/definitions/example3.yaml", 48 "testdata/definitions/example4.yaml", 49 "testdata/definitions/example5.yaml", 50 "testdata/definitions/example6.yaml", 51 "testdata/definitions/example7.yaml", 52 "testdata/definitions/example8.yaml", 53 "testdata/definitions/example9.yaml", 54 55 "testdata/global/example1.yaml", 56 "testdata/global/example2.yaml", 57 "testdata/global/example3.yaml", 58 "testdata/global/example4.yaml", 59 "testdata/global/example5.yaml", 60 61 "testdata/image/example3.yaml", 62 // "testdata/image/example4.yaml", // username, password 63 "testdata/image/example5.yaml", 64 "testdata/image/example6.yaml", 65 "testdata/image/example7.yaml", 66 // "testdata/image/example8.yaml", // username, password 67 // "testdata/image/example9.yaml", // username, password 68 // "testdata/image/example10.yaml", // username, password 69 // "testdata/image/example11.yaml", // username, password 70 // "testdata/image/example12.yaml", // services, username, password 71 "testdata/image/example13.yaml", 72 "testdata/image/example14.yaml", 73 "testdata/image/example15.yaml", 74 // "testdata/image/example16.yaml", // aws 75 // "testdata/image/example17.yaml", // aws 76 // "testdata/image/example18.yaml", // aws 77 // "testdata/image/example19.yaml", // aws 78 // "testdata/image/example20.yaml", // aws, services 79 80 "testdata/parallel/example1.yaml", 81 "testdata/parallel/example2.yaml", 82 "testdata/parallel/example3.yaml", // TODO fail-fast 83 "testdata/parallel/example4.yaml", // TODO fail-fast 84 85 "testdata/stages/example1.yaml", 86 "testdata/stages/example2.yaml", 87 "testdata/stages/example3.yaml", // TODO changesets 88 "testdata/stages/example4.yaml", // TODO changesets 89 "testdata/stages/example5.yaml", // TODO deploy, trigger 90 "testdata/stages/example6.yaml", 91 "testdata/stages/example7.yaml", // TODO trigger 92 93 "testdata/steps/example1.yaml", 94 "testdata/steps/example2.yaml", 95 "testdata/steps/example3.yaml", 96 "testdata/steps/example4.yaml", 97 "testdata/steps/example5.yaml", 98 "testdata/steps/example6.yaml", 99 "testdata/steps/example7.yaml", 100 "testdata/steps/example8.yaml", 101 "testdata/steps/example9.yaml", // TODO trigger, deploy 102 "testdata/steps/example10.yaml", // TODO oidc 103 "testdata/steps/example11.yaml", // TODO trigger 104 "testdata/steps/example12.yaml", // TODO artifacts 105 "testdata/steps/example13.yaml", // TODO changeset 106 "testdata/steps/example14.yaml", // TODO changeset 107 "testdata/steps/example15.yaml", 108 "testdata/steps/example16.yaml", 109 "testdata/steps/example17.yaml", 110 "testdata/steps/example18.yaml", // TODO artifacts 111 "testdata/steps/example19.yaml", // TODO artifacts 112 "testdata/steps/example20.yaml", 113 } 114 115 for _, test := range tests { 116 t.Run(test, func(t *testing.T) { 117 // convert the yaml file from bitbucket to harness 118 // tmp1, err := FromFile(test) 119 // if err != nil { 120 // t.Error(err) 121 // return 122 // } 123 124 // convert the yaml file from bitbucket to harness 125 converter := New() 126 tmp1, err := converter.ConvertFile(test) 127 if err != nil { 128 t.Error(err) 129 return 130 } 131 132 // unmarshal the converted yaml file to a map 133 got := map[string]interface{}{} 134 if err := yaml.Unmarshal(tmp1, &got); err != nil { 135 t.Error(err) 136 return 137 } 138 139 // parse the golden yaml file 140 data, err := ioutil.ReadFile(test + ".golden") 141 if err != nil { 142 t.Error(err) 143 return 144 } 145 146 // unmarshal the golden yaml file to a map 147 want := map[string]interface{}{} 148 if err := yaml.Unmarshal(data, &want); err != nil { 149 t.Error(err) 150 return 151 } 152 153 // compare the converted yaml to the golden file 154 if diff := cmp.Diff(got, want); diff != "" { 155 t.Errorf("Unexpected conversion result") 156 t.Log(diff) 157 } 158 }) 159 } 160 }