From ea771f19efa79c0941d9b4329cd8ab0298c06485 Mon Sep 17 00:00:00 2001 From: Matt Corby Date: Tue, 23 Jan 2018 21:05:26 +0000 Subject: [PATCH] updating based on latest gogivens --- generator_test.go | 65 ++++++++++++++++++++++---------------------- model/jsondata.go | 6 ++-- model/testresults.go | 14 ++++++---- model/teststate.go | 14 +++++----- 4 files changed, 51 insertions(+), 48 deletions(-) diff --git a/generator_test.go b/generator_test.go index 2a9c252..e3a41de 100644 --- a/generator_test.go +++ b/generator_test.go @@ -6,9 +6,7 @@ import ( "github.com/corbym/gocrest" "github.com/corbym/gocrest/is" . "github.com/corbym/gocrest/then" - "github.com/corbym/gogiven/base" "github.com/corbym/gogiven/generator" - "github.com/corbym/gogiven/testdata" "github.com/corbym/jsonspec" "testing" ) @@ -27,14 +25,14 @@ func TestTestOutputGenerator_Generate(testing *testing.T) { `{ "title": "Generator Test", "test_state": { - "foo": { + "test title": { "test_results": { - "id": "foo", - "failed": false, - "skipped": false, - "test_output": "" + "id": "abc2124", + "failed": true, + "skipped": true, + "test_output": "well alrighty then" }, - "test_title": "Generator Test", + "test_title": "test title", "interesting_givens": { "faff": "flap" }, @@ -42,7 +40,9 @@ func TestTestOutputGenerator_Generate(testing *testing.T) { "foob": "barb" }, "given_when_then": [ - "GivenWhenThen" + "given", + "when", + "then" ] } } @@ -64,7 +64,7 @@ func isValidJson() *gocrest.Matcher { func TestTestOutputGenerator_GenerateConcurrently(testing *testing.T) { for i := 0; i < 15; i++ { go func() { - data := newPageData(newSomeMap()) + data := newPageData(false, false) html := underTest.Generate(data) AssertThat(testing, html, is.ValueContaining("Generator Test")) @@ -81,33 +81,34 @@ func TestTestOutputGenerator_Panics(t *testing.T) { recovered := recover() AssertThat(t, recovered, is.Not(is.Nil())) }() - data := newPageData(newSomeMap()) - data.SomeMap = nil - - underTest.Generate(data) + underTest.Generate(nil) } func fileIsConverted() { - jsonString = underTest.Generate(newPageData(newSomeMap())) -} - -func newSomeMap() *base.SomeMap { - testingT := new(base.TestMetaData) - some := base.NewSome(testingT, - "Generator Test", - base.NewTestMetaData("foo"), - []string{"GivenWhenThen"}, - func(givens testdata.InterestingGivens) { - givens["faff"] = "flap" - }) - some.CapturedIO()["foob"] = "barb" - someMap := &base.SomeMap{"foo": some} - return someMap + jsonString = underTest.Generate(newPageData(true, true)) } -func newPageData(someMap *base.SomeMap) *generator.PageData { +func newPageData(skipped bool, failed bool) *generator.PageData { + testData := make(map[string]*generator.TestData) + capturedIO := make(map[interface{}]interface{}) + capturedIO["foob"] = "barb" + interestingGivens := make(map[interface{}]interface{}) + interestingGivens["faff"] = "flap" + testData["test title"] = &generator.TestData{ + TestTitle: "test title", + GivenWhenThen: []string{"given", "when", "then"}, + CapturedIO: capturedIO, + InterestingGivens: interestingGivens, + TestResult: &generator.TestResult{ + Failed: failed, + Skipped: skipped, + TestOutput: "well alrighty then", + TestId: "abc2124", + }, + } return &generator.PageData{ - Title: "Generator Test", - SomeMap: someMap, + TestResults: testData, + Title: "Generator Test", } } + diff --git a/model/jsondata.go b/model/jsondata.go index 7b171d3..606e368 100644 --- a/model/jsondata.go +++ b/model/jsondata.go @@ -11,9 +11,9 @@ type jsonData struct { func NewJsonData(pageData *generator.PageData) (jsonPageData *jsonData) { jsonPageData = new(jsonData) jsonPageData.Title = pageData.Title - jsonPageData.TestState = make(map[string]*testState, len(*pageData.SomeMap)) - for k, v := range *pageData.SomeMap { - jsonPageData.TestState[k] = NewTestState(v) + jsonPageData.TestState = make(map[string]*testState, len(pageData.TestResults)) + for k, v := range pageData.TestResults { + jsonPageData.TestState[k] = NewTestState(*v) } return } diff --git a/model/testresults.go b/model/testresults.go index cf27955..27ddd96 100644 --- a/model/testresults.go +++ b/model/testresults.go @@ -1,6 +1,8 @@ package model -import "github.com/corbym/gogiven/base" +import ( + "github.com/corbym/gogiven/generator" +) type testResults struct { Id string `json:"id"` @@ -10,10 +12,10 @@ type testResults struct { } //NewTestResults is internal and creates a new json data object for marshalling test data -func NewTestResults(data *base.TestMetaData) *testResults { - return &testResults{Failed: data.Failed(), - TestOutput: data.TestOutput(), - Id: data.TestId, - Skipped: data.Skipped(), +func NewTestResults(data *generator.TestResult) *testResults { + return &testResults{Failed: data.Failed, + TestOutput: data.TestOutput, + Id: data.TestId, + Skipped: data.Skipped, } } diff --git a/model/teststate.go b/model/teststate.go index 047ad52..432fdd6 100644 --- a/model/teststate.go +++ b/model/teststate.go @@ -2,7 +2,7 @@ package model import ( "fmt" - "github.com/corbym/gogiven/base" + "github.com/corbym/gogiven/generator" ) type testState struct { @@ -14,13 +14,13 @@ type testState struct { } //NewTestState is internal and creates a new json data object for marshalling test data -func NewTestState(some *base.Some) *testState { +func NewTestState(testData generator.TestData) *testState { return &testState{ - TestResults: NewTestResults(some.TestingT), - TestTitle: some.TestTitle, - InterestingGivens: convertToMapStringInterface(some.InterestingGivens()), - CapturedIO: convertToMapStringInterface(some.CapturedIO()), - GivenWhenThen: some.GivenWhenThen, + TestResults: NewTestResults(testData.TestResult), + TestTitle: testData.TestTitle, + InterestingGivens: convertToMapStringInterface(testData.InterestingGivens), + CapturedIO: convertToMapStringInterface(testData.CapturedIO), + GivenWhenThen: testData.GivenWhenThen, } }