mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
53 lines
875 B
Go
53 lines
875 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"gopkg.in/yaml.v2"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
var rawData = `
|
|
a: Easy!
|
|
b:
|
|
c: 2
|
|
d: [3, 4]
|
|
`
|
|
|
|
var parsedData map[interface{}]interface{}
|
|
|
|
func TestMain(m *testing.M) {
|
|
err := yaml.Unmarshal([]byte(rawData), &parsedData)
|
|
if err != nil {
|
|
fmt.Println("Error parsing yaml: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func TestReadMap_simple(t *testing.T) {
|
|
result := readMap(parsedData, "b", []string{"c"})
|
|
if result != 2 {
|
|
t.Error("Excpted 2 but got ", result)
|
|
}
|
|
}
|
|
|
|
func TestReadMap_array(t *testing.T) {
|
|
result := readMap(parsedData, "b", []string{"d", "1"})
|
|
if result != 4 {
|
|
t.Error("Excpted 4 but got ", result)
|
|
}
|
|
}
|
|
|
|
func TestWrite_simple(t *testing.T) {
|
|
|
|
write(parsedData, "b", []string{"c"}, "4")
|
|
|
|
b := parsedData["b"].(map[interface{}]interface{})
|
|
c := b["c"].(string)
|
|
if c != "4" {
|
|
t.Error("Excepted 4 but got ", c)
|
|
}
|
|
}
|