diff options
Diffstat (limited to 'vendor/github.com/mitchellh/go-testing-interface')
5 files changed, 249 insertions, 0 deletions
diff --git a/vendor/github.com/mitchellh/go-testing-interface/.travis.yml b/vendor/github.com/mitchellh/go-testing-interface/.travis.yml new file mode 100644 index 0000000..4c83109 --- /dev/null +++ b/vendor/github.com/mitchellh/go-testing-interface/.travis.yml | |||
@@ -0,0 +1,12 @@ | |||
1 | language: go | ||
2 | |||
3 | go: | ||
4 | - 1.8 | ||
5 | - tip | ||
6 | |||
7 | script: | ||
8 | - go test | ||
9 | |||
10 | matrix: | ||
11 | allow_failures: | ||
12 | - go: tip | ||
diff --git a/vendor/github.com/mitchellh/go-testing-interface/LICENSE b/vendor/github.com/mitchellh/go-testing-interface/LICENSE new file mode 100644 index 0000000..a3866a2 --- /dev/null +++ b/vendor/github.com/mitchellh/go-testing-interface/LICENSE | |||
@@ -0,0 +1,21 @@ | |||
1 | The MIT License (MIT) | ||
2 | |||
3 | Copyright (c) 2016 Mitchell Hashimoto | ||
4 | |||
5 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
6 | of this software and associated documentation files (the "Software"), to deal | ||
7 | in the Software without restriction, including without limitation the rights | ||
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
9 | copies of the Software, and to permit persons to whom the Software is | ||
10 | furnished to do so, subject to the following conditions: | ||
11 | |||
12 | The above copyright notice and this permission notice shall be included in | ||
13 | all copies or substantial portions of the Software. | ||
14 | |||
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
21 | THE SOFTWARE. | ||
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. | ||
diff --git a/vendor/github.com/mitchellh/go-testing-interface/testing.go b/vendor/github.com/mitchellh/go-testing-interface/testing.go new file mode 100644 index 0000000..204afb4 --- /dev/null +++ b/vendor/github.com/mitchellh/go-testing-interface/testing.go | |||
@@ -0,0 +1,84 @@ | |||
1 | // +build !go1.9 | ||
2 | |||
3 | package testing | ||
4 | |||
5 | import ( | ||
6 | "fmt" | ||
7 | "log" | ||
8 | ) | ||
9 | |||
10 | // T is the interface that mimics the standard library *testing.T. | ||
11 | // | ||
12 | // In unit tests you can just pass a *testing.T struct. At runtime, outside | ||
13 | // of tests, you can pass in a RuntimeT struct from this package. | ||
14 | type T interface { | ||
15 | Error(args ...interface{}) | ||
16 | Errorf(format string, args ...interface{}) | ||
17 | Fail() | ||
18 | FailNow() | ||
19 | Failed() bool | ||
20 | Fatal(args ...interface{}) | ||
21 | Fatalf(format string, args ...interface{}) | ||
22 | Log(args ...interface{}) | ||
23 | Logf(format string, args ...interface{}) | ||
24 | Name() string | ||
25 | Skip(args ...interface{}) | ||
26 | SkipNow() | ||
27 | Skipf(format string, args ...interface{}) | ||
28 | Skipped() bool | ||
29 | } | ||
30 | |||
31 | // RuntimeT implements T and can be instantiated and run at runtime to | ||
32 | // mimic *testing.T behavior. Unlike *testing.T, this will simply panic | ||
33 | // for calls to Fatal. For calls to Error, you'll have to check the errors | ||
34 | // list to determine whether to exit yourself. Name and Skip methods are | ||
35 | // unimplemented noops. | ||
36 | type RuntimeT struct { | ||
37 | failed bool | ||
38 | } | ||
39 | |||
40 | func (t *RuntimeT) Error(args ...interface{}) { | ||
41 | log.Println(fmt.Sprintln(args...)) | ||
42 | t.Fail() | ||
43 | } | ||
44 | |||
45 | func (t *RuntimeT) Errorf(format string, args ...interface{}) { | ||
46 | log.Println(fmt.Sprintf(format, args...)) | ||
47 | t.Fail() | ||
48 | } | ||
49 | |||
50 | func (t *RuntimeT) Fatal(args ...interface{}) { | ||
51 | log.Println(fmt.Sprintln(args...)) | ||
52 | t.FailNow() | ||
53 | } | ||
54 | |||
55 | func (t *RuntimeT) Fatalf(format string, args ...interface{}) { | ||
56 | log.Println(fmt.Sprintf(format, args...)) | ||
57 | t.FailNow() | ||
58 | } | ||
59 | |||
60 | func (t *RuntimeT) Fail() { | ||
61 | t.failed = true | ||
62 | } | ||
63 | |||
64 | func (t *RuntimeT) FailNow() { | ||
65 | panic("testing.T failed, see logs for output (if any)") | ||
66 | } | ||
67 | |||
68 | func (t *RuntimeT) Failed() bool { | ||
69 | return t.failed | ||
70 | } | ||
71 | |||
72 | func (t *RuntimeT) Log(args ...interface{}) { | ||
73 | log.Println(fmt.Sprintln(args...)) | ||
74 | } | ||
75 | |||
76 | func (t *RuntimeT) Logf(format string, args ...interface{}) { | ||
77 | log.Println(fmt.Sprintf(format, args...)) | ||
78 | } | ||
79 | |||
80 | func (t *RuntimeT) Name() string { return "" } | ||
81 | func (t *RuntimeT) Skip(args ...interface{}) {} | ||
82 | func (t *RuntimeT) SkipNow() {} | ||
83 | func (t *RuntimeT) Skipf(format string, args ...interface{}) {} | ||
84 | func (t *RuntimeT) Skipped() bool { return false } | ||
diff --git a/vendor/github.com/mitchellh/go-testing-interface/testing_go19.go b/vendor/github.com/mitchellh/go-testing-interface/testing_go19.go new file mode 100644 index 0000000..07fbcb5 --- /dev/null +++ b/vendor/github.com/mitchellh/go-testing-interface/testing_go19.go | |||
@@ -0,0 +1,80 @@ | |||
1 | // +build go1.9 | ||
2 | |||
3 | // NOTE: This is a temporary copy of testing.go for Go 1.9 with the addition | ||
4 | // of "Helper" to the T interface. Go 1.9 at the time of typing is in RC | ||
5 | // and is set for release shortly. We'll support this on master as the default | ||
6 | // as soon as 1.9 is released. | ||
7 | |||
8 | package testing | ||
9 | |||
10 | import ( | ||
11 | "fmt" | ||
12 | "log" | ||
13 | ) | ||
14 | |||
15 | // T is the interface that mimics the standard library *testing.T. | ||
16 | // | ||
17 | // In unit tests you can just pass a *testing.T struct. At runtime, outside | ||
18 | // of tests, you can pass in a RuntimeT struct from this package. | ||
19 | type T interface { | ||
20 | Error(args ...interface{}) | ||
21 | Errorf(format string, args ...interface{}) | ||
22 | Fatal(args ...interface{}) | ||
23 | Fatalf(format string, args ...interface{}) | ||
24 | Fail() | ||
25 | FailNow() | ||
26 | Failed() bool | ||
27 | Helper() | ||
28 | Log(args ...interface{}) | ||
29 | Logf(format string, args ...interface{}) | ||
30 | } | ||
31 | |||
32 | // RuntimeT implements T and can be instantiated and run at runtime to | ||
33 | // mimic *testing.T behavior. Unlike *testing.T, this will simply panic | ||
34 | // for calls to Fatal. For calls to Error, you'll have to check the errors | ||
35 | // list to determine whether to exit yourself. | ||
36 | type RuntimeT struct { | ||
37 | failed bool | ||
38 | } | ||
39 | |||
40 | func (t *RuntimeT) Error(args ...interface{}) { | ||
41 | log.Println(fmt.Sprintln(args...)) | ||
42 | t.Fail() | ||
43 | } | ||
44 | |||
45 | func (t *RuntimeT) Errorf(format string, args ...interface{}) { | ||
46 | log.Println(fmt.Sprintf(format, args...)) | ||
47 | t.Fail() | ||
48 | } | ||
49 | |||
50 | func (t *RuntimeT) Fatal(args ...interface{}) { | ||
51 | log.Println(fmt.Sprintln(args...)) | ||
52 | t.FailNow() | ||
53 | } | ||
54 | |||
55 | func (t *RuntimeT) Fatalf(format string, args ...interface{}) { | ||
56 | log.Println(fmt.Sprintf(format, args...)) | ||
57 | t.FailNow() | ||
58 | } | ||
59 | |||
60 | func (t *RuntimeT) Fail() { | ||
61 | t.failed = true | ||
62 | } | ||
63 | |||
64 | func (t *RuntimeT) FailNow() { | ||
65 | panic("testing.T failed, see logs for output (if any)") | ||
66 | } | ||
67 | |||
68 | func (t *RuntimeT) Failed() bool { | ||
69 | return t.failed | ||
70 | } | ||
71 | |||
72 | func (t *RuntimeT) Helper() {} | ||
73 | |||
74 | func (t *RuntimeT) Log(args ...interface{}) { | ||
75 | log.Println(fmt.Sprintln(args...)) | ||
76 | } | ||
77 | |||
78 | func (t *RuntimeT) Logf(format string, args ...interface{}) { | ||
79 | log.Println(fmt.Sprintf(format, args...)) | ||
80 | } | ||