2015-09-28 01:39:16 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-09-28 02:00:38 +00:00
|
|
|
"fmt"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
"os"
|
|
|
|
"testing"
|
2015-09-28 01:39:16 +00:00
|
|
|
)
|
|
|
|
|
2015-09-28 01:58:56 +00:00
|
|
|
var rawData = `
|
2015-09-28 01:39:16 +00:00
|
|
|
a: Easy!
|
|
|
|
b:
|
|
|
|
c: 2
|
|
|
|
d: [3, 4]
|
|
|
|
`
|
|
|
|
|
2015-09-28 01:58:56 +00:00
|
|
|
var parsedData map[interface{}]interface{}
|
2015-09-28 01:39:16 +00:00
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2015-09-28 01:58:56 +00:00
|
|
|
err := yaml.Unmarshal([]byte(rawData), &parsedData)
|
2015-09-28 02:00:38 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error parsing yaml: %v", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2015-09-28 01:39:16 +00:00
|
|
|
|
2015-09-28 02:00:38 +00:00
|
|
|
os.Exit(m.Run())
|
2015-09-28 01:39:16 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 01:58:56 +00:00
|
|
|
func TestReadMap_simple(t *testing.T) {
|
|
|
|
result := readMap(parsedData, "b", []string{"c"})
|
2015-09-28 02:00:38 +00:00
|
|
|
if result != 2 {
|
|
|
|
t.Error("Excpted 2 but got ", result)
|
|
|
|
}
|
2015-09-28 01:39:16 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 01:58:56 +00:00
|
|
|
func TestReadMap_array(t *testing.T) {
|
|
|
|
result := readMap(parsedData, "b", []string{"d", "1"})
|
2015-09-28 02:00:38 +00:00
|
|
|
if result != 4 {
|
|
|
|
t.Error("Excpted 4 but got ", result)
|
|
|
|
}
|
2015-09-28 01:39:16 +00:00
|
|
|
}
|
2015-09-29 00:56:28 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|