Skip to content

Commit

Permalink
more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcorbyeaglen committed Jan 23, 2018
1 parent a1f2ce6 commit 9bb7767
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 17 deletions.
2 changes: 1 addition & 1 deletion base/testingt.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package base

//TestingT is a convenience interface that matches some methods of `testing.T`
//TestingT is a convenience interface that matches Some methods of `testing.T`
type TestingT interface {
Failed() bool
Logf(format string, args ...interface{})
Expand Down
6 changes: 3 additions & 3 deletions base/testmetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
)

// TestMetaData holds some information about the test, it's id, whether it failed or not
// TestMetaData holds Some information about the test, it's id, whether it failed or not
// and the output it sent to t.Errorf or t.Error etc.
type TestMetaData struct {
sync.RWMutex
Expand Down Expand Up @@ -47,13 +47,13 @@ func (t *TestMetaData) FailNow() {
t.failed = true
}

//Helper does nothing. It's just in case some package that consumes t
//Helper does nothing. It's just in case Some package that consumes t
// calls it.
func (t *TestMetaData) Helper() {
// do nothing
}

//Name returns the id (the test name, possibly with some uniqueid appended)
//Name returns the id (the test name, possibly with Some uniqueid appended)
func (t *TestMetaData) Name() string {
t.RLock()
defer t.RUnlock()
Expand Down
4 changes: 2 additions & 2 deletions base/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"github.com/corbym/gogiven/testdata"
)

// GivenData is a func type that gets given some interesting givens as a parameter
// GivenData is a func type that gets given Some interesting givens as a parameter
type GivenData func(givens testdata.InterestingGivens)

// CapturedIOData is a func type that gets given a reference to some CapturedIO data for the test
// CapturedIOData is a func type that gets given a reference to Some CapturedIO data for the test
type CapturedIOData func(capturedIO testdata.CapturedIO)

//CapturedIOGivenData is a combination of GivenData and CapturedIOData types
Expand Down
10 changes: 6 additions & 4 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ func GenerateTestOutput() {
value, _ := globalTestContextMap.Load(key)
currentTestContext := value.(*TestContext)
tests := currentTestContext.SomeTests()
pageData := &generator.PageData{
Title: transformFileNameToHeader(currentTestContext.FileName()),
SomeMap: tests.AsMapOfSome(),
}

pageData := generator.NewPageData(
transformFileNameToHeader(currentTestContext.fileName),
tests.asMapOfSome(),
)

output := Generator.Generate(pageData)
extension := Generator.FileExtension()

Expand Down
60 changes: 57 additions & 3 deletions generator/pagedata.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,63 @@
package generator

import "github.com/corbym/gogiven/base"
import (
"github.com/corbym/gogiven/base"
"github.com/corbym/gogiven/testdata"
)

type TestResult struct {
TestId string
Failed bool
Skipped bool
TestOutput string
}

func NewTestResult(data *base.TestMetaData) (result *TestResult) {
result = &TestResult{
Skipped: data.Skipped(),
TestId: data.Name(),
TestOutput: data.TestOutput(),
Failed: data.Failed(),
}
return
}

type TestData struct {
TestResult *TestResult
TestTitle string
InterestingGivens testdata.InterestingGivens
CapturedIO testdata.CapturedIO
GivenWhenThen []string
}

func NewTestData(some *base.Some) (testData *TestData) {
testData = &TestData{
TestResult: NewTestResult(some.TestMetaData()),
InterestingGivens: some.InterestingGivens(),
CapturedIO: some.CapturedIO(),
GivenWhenThen: some.GivenWhenThen(),
TestTitle: some.TestTitle(),
}
return
}

//PageData is the struct that populates the template with data from the test output.
type PageData struct {
Title string
SomeMap *base.SomeMap
Title string
TestResults map[string]*TestData
}

func NewPageData(title string, someMap *base.SomeMap) (pageData *PageData) {
pageData = new(PageData)
pageData.Title = title
pageData.TestResults = copyTestResults(someMap)
return
}

func copyTestResults(someMap *base.SomeMap) (testData map[string]*TestData) {
testData = make(map[string]*TestData)
for k, v := range *someMap {
testData[k] = NewTestData(v)
}
return
}
3 changes: 1 addition & 2 deletions generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ func TestGenerateTestOutput(t *testing.T) {
func TestGenerateTestOutput_DefaultsToCurrentDir(t *testing.T) {
old := os.Getenv("GOGIVENS_OUTPUT_DIR")
defer func() {
remove := os.Remove("./generator_test.html")
then.AssertThat(t, remove, is.Nil())
os.Remove("./generator_test.html")
}()
defer func() { os.Setenv("GOGIVENS_OUTPUT_DIR", old) }()
os.Setenv("GOGIVENS_OUTPUT_DIR", "doesnotexist")
Expand Down
3 changes: 1 addition & 2 deletions safemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ func (rm *safeMap) Keys() []string {
return keys
}

// AsMapOfSome copies the safeMap into a normal map[string]*Some type
func (rm *safeMap) AsMapOfSome() *base.SomeMap {
func (rm *safeMap) asMapOfSome() *base.SomeMap {
rm.RLock()
defer rm.RUnlock()
var newMap = &base.SomeMap{}
Expand Down

0 comments on commit 9bb7767

Please sign in to comment.