forked from corbym/gogiven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestcontext.go
45 lines (39 loc) · 1.18 KB
/
testcontext.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gogiven
import (
"io/ioutil"
)
//GivenContext is the interface that exports the internals of TestContext
type GivenContext interface {
SomeTests() map[string]interface{}
FileName() string
}
//TestContext contains a safeMap of the TestMetaData for the current test file being processed and
// a copy of the fileName with it's file content.
type TestContext struct {
someTests *safeMap
fileName string
fileContent string
}
//NewTestContext creates a new context. This will read the whole contents of filename
// in using ioutil.ReadFile into memory.
func NewTestContext(fileName string) *TestContext {
content, err := ioutil.ReadFile(fileName)
if err != nil {
panic("file not found:" + err.Error())
}
context := new(TestContext)
context.someTests = newSafeMap()
context.fileName = fileName
context.fileContent = string(content[:])
return context
}
//SomeTests is a map containing the TestMetaData for this TestContext's tests
// that are being executed.
func (c *TestContext) SomeTests() *safeMap {
return c.someTests
}
//FileName is a string containing the filename of the test
// that are being executed.
func (c *TestContext) FileName() string {
return c.fileName
}