diff options
Diffstat (limited to 'vendor/github.com/mitchellh/go-testing-interface/README.md')
-rw-r--r-- | vendor/github.com/mitchellh/go-testing-interface/README.md | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/vendor/github.com/mitchellh/go-testing-interface/README.md b/vendor/github.com/mitchellh/go-testing-interface/README.md new file mode 100644 index 0000000..26781bb --- /dev/null +++ b/vendor/github.com/mitchellh/go-testing-interface/README.md | |||
@@ -0,0 +1,52 @@ | |||
1 | # go-testing-interface | ||
2 | |||
3 | go-testing-interface is a Go library that exports an interface that | ||
4 | `*testing.T` implements as well as a runtime version you can use in its | ||
5 | place. | ||
6 | |||
7 | The purpose of this library is so that you can export test helpers as a | ||
8 | public API without depending on the "testing" package, since you can't | ||
9 | create a `*testing.T` struct manually. This lets you, for example, use the | ||
10 | public testing APIs to generate mock data at runtime, rather than just at | ||
11 | test time. | ||
12 | |||
13 | ## Usage & Example | ||
14 | |||
15 | For usage and examples see the [Godoc](http://godoc.org/github.com/mitchellh/go-testing-interface). | ||
16 | |||
17 | Given a test helper written using `go-testing-interface` like this: | ||
18 | |||
19 | import "github.com/mitchellh/go-testing-interface" | ||
20 | |||
21 | func TestHelper(t testing.T) { | ||
22 | t.Fatal("I failed") | ||
23 | } | ||
24 | |||
25 | You can call the test helper in a real test easily: | ||
26 | |||
27 | import "testing" | ||
28 | |||
29 | func TestThing(t *testing.T) { | ||
30 | TestHelper(t) | ||
31 | } | ||
32 | |||
33 | You can also call the test helper at runtime if needed: | ||
34 | |||
35 | import "github.com/mitchellh/go-testing-interface" | ||
36 | |||
37 | func main() { | ||
38 | TestHelper(&testing.RuntimeT{}) | ||
39 | } | ||
40 | |||
41 | ## Why?! | ||
42 | |||
43 | **Why would I call a test helper that takes a *testing.T at runtime?** | ||
44 | |||
45 | You probably shouldn't. The only use case I've seen (and I've had) for this | ||
46 | is to implement a "dev mode" for a service where the test helpers are used | ||
47 | to populate mock data, create a mock DB, perhaps run service dependencies | ||
48 | in-memory, etc. | ||
49 | |||
50 | Outside of a "dev mode", I've never seen a use case for this and I think | ||
51 | there shouldn't be one since the point of the `testing.T` interface is that | ||
52 | you can fail immediately. | ||