github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/travis/yaml/parse_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 "io/ioutil" 19 "testing" 20 ) 21 22 func TestParseString(t *testing.T) { 23 out, _ := ioutil.ReadFile("testdata/golang.yaml") 24 _, err := ParseString(string(out)) 25 if err != nil { 26 t.Error(err) 27 } 28 } 29 30 func TestParseString_Error(t *testing.T) { 31 _, err := ParseString("[]") 32 if err == nil { 33 t.Errorf("Expect error when yaml is invalid") 34 } 35 } 36 37 func TestParseFile(t *testing.T) { 38 _, err := ParseFile("testdata/golang.yaml") 39 if err != nil { 40 t.Error(err) 41 } 42 } 43 44 func TestParseFile_Error(t *testing.T) { 45 _, err := ParseFile("testdata/file-does-not-exist.yaml") 46 if err == nil { 47 t.Errorf("Expect error when file not exists") 48 } 49 }