mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
DRY'd tests
This commit is contained in:
parent
c1b803364a
commit
35ceb01222
20
yaml_test.go
20
yaml_test.go
@ -27,17 +27,11 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestReadMap_simple(t *testing.T) {
|
func TestReadMap_simple(t *testing.T) {
|
||||||
result := readMap(parsedData, "b", []string{"c"})
|
assertResult(t, 2, readMap(parsedData, "b", []string{"c"}))
|
||||||
if result != 2 {
|
|
||||||
t.Error("Excpted 2 but got ", result)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadMap_array(t *testing.T) {
|
func TestReadMap_array(t *testing.T) {
|
||||||
result := readMap(parsedData, "b", []string{"d", "1"})
|
assertResult(t, 4, readMap(parsedData, "b", []string{"d", "1"}))
|
||||||
if result != 4 {
|
|
||||||
t.Error("Excpted 4 but got ", result)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWrite_simple(t *testing.T) {
|
func TestWrite_simple(t *testing.T) {
|
||||||
@ -45,8 +39,12 @@ func TestWrite_simple(t *testing.T) {
|
|||||||
write(parsedData, "b", []string{"c"}, "4")
|
write(parsedData, "b", []string{"c"}, "4")
|
||||||
|
|
||||||
b := parsedData["b"].(map[interface{}]interface{})
|
b := parsedData["b"].(map[interface{}]interface{})
|
||||||
c := b["c"].(string)
|
assertResult(t, "4", b["c"].(string))
|
||||||
if c != "4" {
|
}
|
||||||
t.Error("Excepted 4 but got ", c)
|
|
||||||
|
|
||||||
|
func assertResult(t *testing.T, expectedValue interface{}, actualValue interface{}) {
|
||||||
|
if (expectedValue != actualValue) {
|
||||||
|
t.Error("Expected <", expectedValue, "> but got <", actualValue, ">")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user