From 35ceb012225989aebab85762c6f52db84fa841da Mon Sep 17 00:00:00 2001 From: mfarah Date: Thu, 1 Oct 2015 14:43:57 +1000 Subject: [PATCH] DRY'd tests --- yaml_test.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/yaml_test.go b/yaml_test.go index 4f27688..30a14f7 100644 --- a/yaml_test.go +++ b/yaml_test.go @@ -27,17 +27,11 @@ func TestMain(m *testing.M) { } func TestReadMap_simple(t *testing.T) { - result := readMap(parsedData, "b", []string{"c"}) - if result != 2 { - t.Error("Excpted 2 but got ", result) - } + assertResult(t, 2, readMap(parsedData, "b", []string{"c"})) } func TestReadMap_array(t *testing.T) { - result := readMap(parsedData, "b", []string{"d", "1"}) - if result != 4 { - t.Error("Excpted 4 but got ", result) - } + assertResult(t, 4, readMap(parsedData, "b", []string{"d", "1"})) } func TestWrite_simple(t *testing.T) { @@ -45,8 +39,12 @@ 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) + assertResult(t, "4", b["c"].(string)) +} + + +func assertResult(t *testing.T, expectedValue interface{}, actualValue interface{}) { + if (expectedValue != actualValue) { + t.Error("Expected <", expectedValue, "> but got <", actualValue, ">") } }