github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/github/yaml/util_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 yaml 16 17 import ( 18 "bytes" 19 "testing" 20 ) 21 22 func TestRepairOn(t *testing.T) { 23 tests := []struct { 24 before string 25 after string 26 }{ 27 { 28 before: "on:\n push\n", 29 after: "on:\n push: {}\n", 30 }, 31 { 32 before: "on:\n pull_request:\n types: []\n", 33 after: "on:\n pull_request:\n types: []\n", 34 }, 35 } 36 37 for _, test := range tests { 38 t.Run(test.before, func(t *testing.T) { 39 buf := bytes.NewBufferString(test.before) 40 out := repairOn(buf) 41 if got, want := out.String(), test.after; got != want { 42 t.Errorf("Got repaired yaml %q, want %q", got, want) 43 } 44 }) 45 } 46 47 } 48 49 var invalidOn = ` 50 on: 51 push 52 53 jobs: [] 54 `