From 5f09aabf4cc76a27cecc4bb8556efbf6771bacbc Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 10 Oct 2015 19:18:54 +1100 Subject: [PATCH] Extracted out common test code --- data_navigator_test.go | 26 -------------------------- utils_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 utils_test.go diff --git a/data_navigator_test.go b/data_navigator_test.go index b8c24369..c77ea397 100644 --- a/data_navigator_test.go +++ b/data_navigator_test.go @@ -2,22 +2,10 @@ package main import ( "fmt" - "github.com/mikefarah/yaml/Godeps/_workspace/src/gopkg.in/yaml.v2" - "os" "sort" "testing" ) -func parseData(rawData string) map[interface{}]interface{} { - var parsedData map[interface{}]interface{} - err := yaml.Unmarshal([]byte(rawData), &parsedData) - if err != nil { - fmt.Println("Error parsing yaml: %v", err) - os.Exit(1) - } - return parsedData -} - func TestReadMap_simple(t *testing.T) { var data = parseData(` --- @@ -130,17 +118,3 @@ b: b := data["b"] assertResult(t, "4", fmt.Sprintf("%v", b)) } - -func assertResult(t *testing.T, expectedValue interface{}, actualValue interface{}) { - if expectedValue != actualValue { - t.Error("Expected <", expectedValue, "> but got <", actualValue, ">", fmt.Sprintf("%T", actualValue)) - } -} - -func assertResultWithContext(t *testing.T, expectedValue interface{}, actualValue interface{}, context interface{}) { - - if expectedValue != actualValue { - t.Error(context) - t.Error(": expected <", expectedValue, "> but got <", actualValue, ">") - } -} diff --git a/utils_test.go b/utils_test.go new file mode 100644 index 00000000..3c7a75d1 --- /dev/null +++ b/utils_test.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "github.com/mikefarah/yaml/Godeps/_workspace/src/gopkg.in/yaml.v2" + "os" + "testing" +) + +func parseData(rawData string) map[interface{}]interface{} { + var parsedData map[interface{}]interface{} + err := yaml.Unmarshal([]byte(rawData), &parsedData) + if err != nil { + fmt.Println("Error parsing yaml: %v", err) + os.Exit(1) + } + return parsedData +} + +func assertResult(t *testing.T, expectedValue interface{}, actualValue interface{}) { + if expectedValue != actualValue { + t.Error("Expected <", expectedValue, "> but got <", actualValue, ">", fmt.Sprintf("%T", actualValue)) + } +} + +func assertResultWithContext(t *testing.T, expectedValue interface{}, actualValue interface{}, context interface{}) { + + if expectedValue != actualValue { + t.Error(context) + t.Error(": expected <", expectedValue, "> but got <", actualValue, ">") + } +}