Skip to content

Commit 35ceb01

Browse files
author
mfarah
committed
DRY'd tests
1 parent c1b8033 commit 35ceb01

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

yaml_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,24 @@ func TestMain(m *testing.M) {
2727
}
2828

2929
func TestReadMap_simple(t *testing.T) {
30-
result := readMap(parsedData, "b", []string{"c"})
31-
if result != 2 {
32-
t.Error("Excpted 2 but got ", result)
33-
}
30+
assertResult(t, 2, readMap(parsedData, "b", []string{"c"}))
3431
}
3532

3633
func TestReadMap_array(t *testing.T) {
37-
result := readMap(parsedData, "b", []string{"d", "1"})
38-
if result != 4 {
39-
t.Error("Excpted 4 but got ", result)
40-
}
34+
assertResult(t, 4, readMap(parsedData, "b", []string{"d", "1"}))
4135
}
4236

4337
func TestWrite_simple(t *testing.T) {
4438

4539
write(parsedData, "b", []string{"c"}, "4")
4640

4741
b := parsedData["b"].(map[interface{}]interface{})
48-
c := b["c"].(string)
49-
if c != "4" {
50-
t.Error("Excepted 4 but got ", c)
42+
assertResult(t, "4", b["c"].(string))
43+
}
44+
45+
46+
func assertResult(t *testing.T, expectedValue interface{}, actualValue interface{}) {
47+
if (expectedValue != actualValue) {
48+
t.Error("Expected <", expectedValue, "> but got <", actualValue, ">")
5149
}
5250
}

0 commit comments

Comments
 (0)