aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/mitchellh/go-testing-interface
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/mitchellh/go-testing-interface')
-rw-r--r--vendor/github.com/mitchellh/go-testing-interface/.travis.yml12
-rw-r--r--vendor/github.com/mitchellh/go-testing-interface/LICENSE21
-rw-r--r--vendor/github.com/mitchellh/go-testing-interface/README.md52
-rw-r--r--vendor/github.com/mitchellh/go-testing-interface/testing.go84
-rw-r--r--vendor/github.com/mitchellh/go-testing-interface/testing_go19.go80
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 @@
1language: go
2
3go:
4 - 1.8
5 - tip
6
7script:
8 - go test
9
10matrix:
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 @@
1The MIT License (MIT)
2
3Copyright (c) 2016 Mitchell Hashimoto
4
5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21THE 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
3go-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
5place.
6
7The purpose of this library is so that you can export test helpers as a
8public API without depending on the "testing" package, since you can't
9create a `*testing.T` struct manually. This lets you, for example, use the
10public testing APIs to generate mock data at runtime, rather than just at
11test time.
12
13## Usage & Example
14
15For usage and examples see the [Godoc](http://godoc.org/github.com/mitchellh/go-testing-interface).
16
17Given 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
25You 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
33You 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
45You probably shouldn't. The only use case I've seen (and I've had) for this
46is to implement a "dev mode" for a service where the test helpers are used
47to populate mock data, create a mock DB, perhaps run service dependencies
48in-memory, etc.
49
50Outside of a "dev mode", I've never seen a use case for this and I think
51there shouldn't be one since the point of the `testing.T` interface is that
52you 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
3package testing
4
5import (
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.
14type 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.
36type RuntimeT struct {
37 failed bool
38}
39
40func (t *RuntimeT) Error(args ...interface{}) {
41 log.Println(fmt.Sprintln(args...))
42 t.Fail()
43}
44
45func (t *RuntimeT) Errorf(format string, args ...interface{}) {
46 log.Println(fmt.Sprintf(format, args...))
47 t.Fail()
48}
49
50func (t *RuntimeT) Fatal(args ...interface{}) {
51 log.Println(fmt.Sprintln(args...))
52 t.FailNow()
53}
54
55func (t *RuntimeT) Fatalf(format string, args ...interface{}) {
56 log.Println(fmt.Sprintf(format, args...))
57 t.FailNow()
58}
59
60func (t *RuntimeT) Fail() {
61 t.failed = true
62}
63
64func (t *RuntimeT) FailNow() {
65 panic("testing.T failed, see logs for output (if any)")
66}
67
68func (t *RuntimeT) Failed() bool {
69 return t.failed
70}
71
72func (t *RuntimeT) Log(args ...interface{}) {
73 log.Println(fmt.Sprintln(args...))
74}
75
76func (t *RuntimeT) Logf(format string, args ...interface{}) {
77 log.Println(fmt.Sprintf(format, args...))
78}
79
80func (t *RuntimeT) Name() string { return "" }
81func (t *RuntimeT) Skip(args ...interface{}) {}
82func (t *RuntimeT) SkipNow() {}
83func (t *RuntimeT) Skipf(format string, args ...interface{}) {}
84func (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
8package testing
9
10import (
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.
19type 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.
36type RuntimeT struct {
37 failed bool
38}
39
40func (t *RuntimeT) Error(args ...interface{}) {
41 log.Println(fmt.Sprintln(args...))
42 t.Fail()
43}
44
45func (t *RuntimeT) Errorf(format string, args ...interface{}) {
46 log.Println(fmt.Sprintf(format, args...))
47 t.Fail()
48}
49
50func (t *RuntimeT) Fatal(args ...interface{}) {
51 log.Println(fmt.Sprintln(args...))
52 t.FailNow()
53}
54
55func (t *RuntimeT) Fatalf(format string, args ...interface{}) {
56 log.Println(fmt.Sprintf(format, args...))
57 t.FailNow()
58}
59
60func (t *RuntimeT) Fail() {
61 t.failed = true
62}
63
64func (t *RuntimeT) FailNow() {
65 panic("testing.T failed, see logs for output (if any)")
66}
67
68func (t *RuntimeT) Failed() bool {
69 return t.failed
70}
71
72func (t *RuntimeT) Helper() {}
73
74func (t *RuntimeT) Log(args ...interface{}) {
75 log.Println(fmt.Sprintln(args...))
76}
77
78func (t *RuntimeT) Logf(format string, args ...interface{}) {
79 log.Println(fmt.Sprintf(format, args...))
80}