mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
Added test
This commit is contained in:
parent
6550822778
commit
ccd95146fe
41
yaml_test.go
Normal file
41
yaml_test.go
Normal file
@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"gopkg.in/yaml.v2"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
var raw_data = `
|
||||
a: Easy!
|
||||
b:
|
||||
c: 2
|
||||
d: [3, 4]
|
||||
`
|
||||
|
||||
var parsed_data map[interface{}]interface{}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
err := yaml.Unmarshal([]byte(raw_data), &parsed_data)
|
||||
if err != nil {
|
||||
fmt.Println("Error parsing yaml: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestRead_map_simple(t *testing.T) {
|
||||
result := read_map(parsed_data, "b", []string{"c"})
|
||||
if( result != 2) {
|
||||
t.Error("Excpted 2 but got ", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRead_map_array(t *testing.T) {
|
||||
result := read_map(parsed_data, "b", []string{"d", "1"})
|
||||
if( result != 4) {
|
||||
t.Error("Excpted 4 but got ", result)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user