Browse Source

Unit tests for token and update models

Ethan Koenig 3 years ago
parent
commit
de8b73dd92
41 changed files with 11919 additions and 0 deletions
  1. 23 0
      models/fixtures/access_token.yml
  2. 20 0
      models/fixtures/update_task.yml
  3. 47 0
      models/setup_for_test.go
  4. 107 0
      models/token_test.go
  5. 124 0
      models/update_test.go
  6. 28 0
      vendor/github.com/stretchr/testify/require/doc.go
  7. 16 0
      vendor/github.com/stretchr/testify/require/forward_requirements.go
  8. 429 0
      vendor/github.com/stretchr/testify/require/require.go
  9. 6 0
      vendor/github.com/stretchr/testify/require/require.go.tmpl
  10. 353 0
      vendor/github.com/stretchr/testify/require/require_forward.go
  11. 4 0
      vendor/github.com/stretchr/testify/require/require_forward.go.tmpl
  12. 9 0
      vendor/github.com/stretchr/testify/require/requirements.go
  13. 21 0
      vendor/gopkg.in/testfixtures.v2/LICENSE
  14. 323 0
      vendor/gopkg.in/testfixtures.v2/README.md
  15. 59 0
      vendor/gopkg.in/testfixtures.v2/deprecated.go
  16. 38 0
      vendor/gopkg.in/testfixtures.v2/helper.go
  17. 45 0
      vendor/gopkg.in/testfixtures.v2/mysql.go
  18. 19 0
      vendor/gopkg.in/testfixtures.v2/options.go
  19. 132 0
      vendor/gopkg.in/testfixtures.v2/oracle.go
  20. 211 0
      vendor/gopkg.in/testfixtures.v2/postgresql.go
  21. 40 0
      vendor/gopkg.in/testfixtures.v2/sqlite.go
  22. 110 0
      vendor/gopkg.in/testfixtures.v2/sqlserver.go
  23. 279 0
      vendor/gopkg.in/testfixtures.v2/testfixtures.go
  24. 36 0
      vendor/gopkg.in/testfixtures.v2/time.go
  25. 13 0
      vendor/gopkg.in/yaml.v2/LICENSE
  26. 31 0
      vendor/gopkg.in/yaml.v2/LICENSE.libyaml
  27. 131 0
      vendor/gopkg.in/yaml.v2/README.md
  28. 742 0
      vendor/gopkg.in/yaml.v2/apic.go
  29. 683 0
      vendor/gopkg.in/yaml.v2/decode.go
  30. 1685 0
      vendor/gopkg.in/yaml.v2/emitterc.go
  31. 306 0
      vendor/gopkg.in/yaml.v2/encode.go
  32. 1096 0
      vendor/gopkg.in/yaml.v2/parserc.go
  33. 394 0
      vendor/gopkg.in/yaml.v2/readerc.go
  34. 203 0
      vendor/gopkg.in/yaml.v2/resolve.go
  35. 2710 0
      vendor/gopkg.in/yaml.v2/scannerc.go
  36. 104 0
      vendor/gopkg.in/yaml.v2/sorter.go
  37. 89 0
      vendor/gopkg.in/yaml.v2/writerc.go
  38. 346 0
      vendor/gopkg.in/yaml.v2/yaml.go
  39. 716 0
      vendor/gopkg.in/yaml.v2/yamlh.go
  40. 173 0
      vendor/gopkg.in/yaml.v2/yamlprivateh.go
  41. 18 0
      vendor/vendor.json

+ 23 - 0
models/fixtures/access_token.yml

@@ -0,0 +1,23 @@
1
+-
2
+  id: 1
3
+  uid: 1
4
+  name: Token A
5
+  sha1: hash1
6
+  created_unix: 946687980
7
+  updated_unix: 946687980
8
+
9
+-
10
+  id: 2
11
+  uid: 1
12
+  name: Token B
13
+  sha1: hash2
14
+  created_unix: 946687980
15
+  updated_unix: 946687980
16
+
17
+-
18
+  id: 3
19
+  uid: 2
20
+  name: Token A
21
+  sha1: hash3
22
+  created_unix: 946687980
23
+  updated_unix: 946687980

+ 20 - 0
models/fixtures/update_task.yml

@@ -0,0 +1,20 @@
1
+-
2
+  id: 1
3
+  uuid: uuid1
4
+  ref_name: refName1
5
+  old_commit_id: oldCommitId1
6
+  new_commit_id: newCommitId1
7
+
8
+-
9
+  id: 2
10
+  uuid: uuid2
11
+  ref_name: refName2
12
+  old_commit_id: oldCommitId2
13
+  new_commit_id: newCommitId2
14
+
15
+-
16
+  id: 3
17
+  uuid: uuid3
18
+  ref_name: refName3
19
+  old_commit_id: oldCommitId3
20
+  new_commit_id: newCommitId3

+ 47 - 0
models/setup_for_test.go

@@ -0,0 +1,47 @@
1
+// Copyright 2016 The Gitea Authors. All rights reserved.
2
+// Use of this source code is governed by a MIT-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package models
6
+
7
+import (
8
+	"fmt"
9
+	"os"
10
+	"testing"
11
+
12
+	"github.com/go-xorm/core"
13
+	"github.com/go-xorm/xorm"
14
+	_ "github.com/mattn/go-sqlite3" // for the test engine
15
+	"gopkg.in/testfixtures.v2"
16
+)
17
+
18
+func TestMain(m *testing.M) {
19
+	if err := CreateTestEngine(); err != nil {
20
+		fmt.Printf("Error creating test engine: %v\n", err)
21
+		os.Exit(1)
22
+	}
23
+	os.Exit(m.Run())
24
+}
25
+
26
+var fixtures *testfixtures.Context
27
+
28
+// CreateTestEngine create an xorm engine for testing
29
+func CreateTestEngine() error {
30
+	testfixtures.SkipDatabaseNameCheck(true)
31
+	var err error
32
+	x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
33
+	if err != nil {
34
+		return err
35
+	}
36
+	x.SetMapper(core.GonicMapper{})
37
+	if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
38
+		return err
39
+	}
40
+	fixtures, err = testfixtures.NewFolder(x.DB().DB, &testfixtures.SQLite{}, "fixtures/")
41
+	return err
42
+}
43
+
44
+// PrepareTestDatabase load test fixtures into test database
45
+func PrepareTestDatabase() error {
46
+	return fixtures.Load()
47
+}

+ 107 - 0
models/token_test.go

@@ -0,0 +1,107 @@
1
+// Copyright 2016 The Gitea Authors. All rights reserved.
2
+// Use of this source code is governed by a MIT-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package models
6
+
7
+import (
8
+	"testing"
9
+
10
+	"github.com/stretchr/testify/assert"
11
+)
12
+
13
+func TestNewAccessToken(t *testing.T) {
14
+	assert.NoError(t, PrepareTestDatabase())
15
+	token := &AccessToken{
16
+		UID:  3,
17
+		Name: "Token C",
18
+	}
19
+	assert.NoError(t, NewAccessToken(token))
20
+	sess := x.NewSession()
21
+	defer sess.Close()
22
+	has, err := sess.Get(*token)
23
+	assert.NoError(t, err)
24
+	assert.True(t, has)
25
+	assert.Equal(t, int64(3), token.UID)
26
+	assert.Equal(t, "Token C", token.Name)
27
+
28
+	invalidToken := &AccessToken{
29
+		ID:   token.ID, // duplicate
30
+		UID:  2,
31
+		Name: "Token F",
32
+	}
33
+	assert.Error(t, NewAccessToken(invalidToken))
34
+}
35
+
36
+func TestGetAccessTokenBySHA(t *testing.T) {
37
+	assert.NoError(t, PrepareTestDatabase())
38
+	token, err := GetAccessTokenBySHA("hash1")
39
+	assert.NoError(t, err)
40
+	assert.Equal(t, int64(1), token.UID)
41
+	assert.Equal(t, "Token A", token.Name)
42
+	assert.Equal(t, "hash1", token.Sha1)
43
+
44
+	token, err = GetAccessTokenBySHA("notahash")
45
+	assert.Error(t, err)
46
+	assert.True(t, IsErrAccessTokenNotExist(err))
47
+
48
+	token, err = GetAccessTokenBySHA("")
49
+	assert.Error(t, err)
50
+	assert.True(t, IsErrAccessTokenEmpty(err))
51
+}
52
+
53
+func TestListAccessTokens(t *testing.T) {
54
+	assert.NoError(t, PrepareTestDatabase())
55
+	tokens, err := ListAccessTokens(1)
56
+	assert.NoError(t, err)
57
+	assert.Len(t, tokens, 2)
58
+	assert.Equal(t, int64(1), tokens[0].UID)
59
+	assert.Equal(t, int64(1), tokens[1].UID)
60
+	assert.Contains(t, []string{tokens[0].Name, tokens[1].Name}, "Token A")
61
+	assert.Contains(t, []string{tokens[0].Name, tokens[1].Name}, "Token B")
62
+
63
+	tokens, err = ListAccessTokens(2)
64
+	assert.NoError(t, err)
65
+	assert.Len(t, tokens, 1)
66
+	assert.Equal(t, int64(2), tokens[0].UID)
67
+	assert.Equal(t, "Token A", tokens[0].Name)
68
+
69
+	tokens, err = ListAccessTokens(100)
70
+	assert.NoError(t, err)
71
+	assert.Empty(t, tokens)
72
+}
73
+
74
+func TestUpdateAccessToken(t *testing.T) {
75
+	assert.NoError(t, PrepareTestDatabase())
76
+	token, err := GetAccessTokenBySHA("hash2")
77
+	assert.NoError(t, err)
78
+	token.Name = "Token Z"
79
+
80
+	assert.NoError(t, UpdateAccessToken(token))
81
+
82
+	sess := x.NewSession()
83
+	defer sess.Close()
84
+	has, err := sess.Get(token)
85
+	assert.NoError(t, err)
86
+	assert.True(t, has)
87
+	assert.Equal(t, token.Name, "Token Z")
88
+}
89
+
90
+func TestDeleteAccessTokenByID(t *testing.T) {
91
+	assert.NoError(t, PrepareTestDatabase())
92
+
93
+	token, err := GetAccessTokenBySHA("hash2")
94
+	assert.NoError(t, err)
95
+	assert.Equal(t, int64(1), token.UID)
96
+
97
+	assert.NoError(t, DeleteAccessTokenByID(token.ID, 1))
98
+	sess := x.NewSession()
99
+	defer sess.Close()
100
+	has, err := sess.Get(token)
101
+	assert.NoError(t, err)
102
+	assert.False(t, has)
103
+
104
+	err = DeleteAccessTokenByID(100, 100)
105
+	assert.Error(t, err)
106
+	assert.True(t, IsErrAccessTokenNotExist(err))
107
+}

+ 124 - 0
models/update_test.go

@@ -0,0 +1,124 @@
1
+// Copyright 2016 The Gitea Authors. All rights reserved.
2
+// Use of this source code is governed by a MIT-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package models
6
+
7
+import (
8
+	"container/list"
9
+	"testing"
10
+	"time"
11
+
12
+	"code.gitea.io/git"
13
+
14
+	"github.com/stretchr/testify/assert"
15
+)
16
+
17
+func TestAddUpdateTask(t *testing.T) {
18
+	assert.NoError(t, PrepareTestDatabase())
19
+	task := &UpdateTask{
20
+		UUID:        "uuid4",
21
+		RefName:     "refName4",
22
+		OldCommitID: "oldCommitId4",
23
+		NewCommitID: "newCommitId4",
24
+	}
25
+	assert.NoError(t, AddUpdateTask(task))
26
+
27
+	sess := x.NewSession()
28
+	defer sess.Close()
29
+	has, err := sess.Get(task)
30
+	assert.NoError(t, err)
31
+	assert.True(t, has)
32
+	assert.Equal(t, "uuid4", task.UUID)
33
+}
34
+
35
+func TestGetUpdateTaskByUUID(t *testing.T) {
36
+	assert.NoError(t, PrepareTestDatabase())
37
+	task, err := GetUpdateTaskByUUID("uuid1")
38
+	assert.NoError(t, err)
39
+	assert.Equal(t, "uuid1", task.UUID)
40
+	assert.Equal(t, "refName1", task.RefName)
41
+	assert.Equal(t, "oldCommitId1", task.OldCommitID)
42
+	assert.Equal(t, "newCommitId1", task.NewCommitID)
43
+}
44
+
45
+func TestDeleteUpdateTaskByUUID(t *testing.T) {
46
+	assert.NoError(t, PrepareTestDatabase())
47
+	assert.NoError(t, DeleteUpdateTaskByUUID("uuid1"))
48
+	sess := x.NewSession()
49
+	defer sess.Close()
50
+	has, err := sess.Get(&UpdateTask{UUID: "uuid1"})
51
+	assert.NoError(t, err)
52
+	assert.False(t, has)
53
+
54
+	assert.NoError(t, DeleteUpdateTaskByUUID("invalid"))
55
+}
56
+
57
+func TestCommitToPushCommit(t *testing.T) {
58
+	now := time.Now()
59
+	sig := &git.Signature{
60
+		Email: "example@example.com",
61
+		Name:  "John Doe",
62
+		When:  now,
63
+	}
64
+	const hexString = "0123456789abcdef0123456789abcdef01234567"
65
+	sha1, err := git.NewIDFromString(hexString)
66
+	assert.NoError(t, err)
67
+	pushCommit := CommitToPushCommit(&git.Commit{
68
+		ID:            sha1,
69
+		Author:        sig,
70
+		Committer:     sig,
71
+		CommitMessage: "Commit Message",
72
+	})
73
+	assert.Equal(t, hexString, pushCommit.Sha1)
74
+	assert.Equal(t, "Commit Message", pushCommit.Message)
75
+	assert.Equal(t, "example@example.com", pushCommit.AuthorEmail)
76
+	assert.Equal(t, "John Doe", pushCommit.AuthorName)
77
+	assert.Equal(t, "example@example.com", pushCommit.CommitterEmail)
78
+	assert.Equal(t, "John Doe", pushCommit.CommitterName)
79
+	assert.Equal(t, now, pushCommit.Timestamp)
80
+}
81
+
82
+func TestListToPushCommits(t *testing.T) {
83
+	now := time.Now()
84
+	sig := &git.Signature{
85
+		Email: "example@example.com",
86
+		Name:  "John Doe",
87
+		When:  now,
88
+	}
89
+
90
+	const hexString1 = "0123456789abcdef0123456789abcdef01234567"
91
+	hash1, err := git.NewIDFromString(hexString1)
92
+	assert.NoError(t, err)
93
+	const hexString2 = "fedcba9876543210fedcba9876543210fedcba98"
94
+	hash2, err := git.NewIDFromString(hexString2)
95
+	assert.NoError(t, err)
96
+
97
+	l := list.New()
98
+	l.PushBack(&git.Commit{
99
+		ID:            hash1,
100
+		Author:        sig,
101
+		Committer:     sig,
102
+		CommitMessage: "Message1",
103
+	})
104
+	l.PushBack(&git.Commit{
105
+		ID:            hash2,
106
+		Author:        sig,
107
+		Committer:     sig,
108
+		CommitMessage: "Message2",
109
+	})
110
+
111
+	pushCommits := ListToPushCommits(l)
112
+	assert.Equal(t, 2, pushCommits.Len)
113
+	assert.Equal(t, 2, len(pushCommits.Commits))
114
+
115
+	assert.Equal(t, "Message1", pushCommits.Commits[0].Message)
116
+	assert.Equal(t, hexString1, pushCommits.Commits[0].Sha1)
117
+	assert.Equal(t, "example@example.com", pushCommits.Commits[0].AuthorEmail)
118
+	assert.Equal(t, now, pushCommits.Commits[0].Timestamp)
119
+
120
+	assert.Equal(t, "Message2", pushCommits.Commits[1].Message)
121
+	assert.Equal(t, hexString2, pushCommits.Commits[1].Sha1)
122
+	assert.Equal(t, "example@example.com", pushCommits.Commits[1].AuthorEmail)
123
+	assert.Equal(t, now, pushCommits.Commits[1].Timestamp)
124
+}

+ 28 - 0
vendor/github.com/stretchr/testify/require/doc.go

@@ -0,0 +1,28 @@
1
+// Package require implements the same assertions as the `assert` package but
2
+// stops test execution when a test fails.
3
+//
4
+// Example Usage
5
+//
6
+// The following is a complete example using require in a standard test function:
7
+//    import (
8
+//      "testing"
9
+//      "github.com/stretchr/testify/require"
10
+//    )
11
+//
12
+//    func TestSomething(t *testing.T) {
13
+//
14
+//      var a string = "Hello"
15
+//      var b string = "Hello"
16
+//
17
+//      require.Equal(t, a, b, "The two words should be the same.")
18
+//
19
+//    }
20
+//
21
+// Assertions
22
+//
23
+// The `require` package have same global functions as in the `assert` package,
24
+// but instead of returning a boolean result they call `t.FailNow()`.
25
+//
26
+// Every assertion function also takes an optional string message as the final argument,
27
+// allowing custom error messages to be appended to the message the assertion method outputs.
28
+package require

+ 16 - 0
vendor/github.com/stretchr/testify/require/forward_requirements.go

@@ -0,0 +1,16 @@
1
+package require
2
+
3
+// Assertions provides assertion methods around the
4
+// TestingT interface.
5
+type Assertions struct {
6
+	t TestingT
7
+}
8
+
9
+// New makes a new Assertions object for the specified TestingT.
10
+func New(t TestingT) *Assertions {
11
+	return &Assertions{
12
+		t: t,
13
+	}
14
+}
15
+
16
+//go:generate go run ../_codegen/main.go -output-package=require -template=require_forward.go.tmpl

+ 429 - 0
vendor/github.com/stretchr/testify/require/require.go

@@ -0,0 +1,429 @@
1
+/*
2
+* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
3
+* THIS FILE MUST NOT BE EDITED BY HAND
4
+ */
5
+
6
+package require
7
+
8
+import (
9
+	assert "github.com/stretchr/testify/assert"
10
+	http "net/http"
11
+	url "net/url"
12
+	time "time"
13
+)
14
+
15
+// Condition uses a Comparison to assert a complex condition.
16
+func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) {
17
+	if !assert.Condition(t, comp, msgAndArgs...) {
18
+		t.FailNow()
19
+	}
20
+}
21
+
22
+// Contains asserts that the specified string, list(array, slice...) or map contains the
23
+// specified substring or element.
24
+//
25
+//    assert.Contains(t, "Hello World", "World", "But 'Hello World' does contain 'World'")
26
+//    assert.Contains(t, ["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'")
27
+//    assert.Contains(t, {"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'")
28
+//
29
+// Returns whether the assertion was successful (true) or not (false).
30
+func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
31
+	if !assert.Contains(t, s, contains, msgAndArgs...) {
32
+		t.FailNow()
33
+	}
34
+}
35
+
36
+// Empty asserts that the specified object is empty.  I.e. nil, "", false, 0 or either
37
+// a slice or a channel with len == 0.
38
+//
39
+//  assert.Empty(t, obj)
40
+//
41
+// Returns whether the assertion was successful (true) or not (false).
42
+func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
43
+	if !assert.Empty(t, object, msgAndArgs...) {
44
+		t.FailNow()
45
+	}
46
+}
47
+
48
+// Equal asserts that two objects are equal.
49
+//
50
+//    assert.Equal(t, 123, 123, "123 and 123 should be equal")
51
+//
52
+// Returns whether the assertion was successful (true) or not (false).
53
+//
54
+// Pointer variable equality is determined based on the equality of the
55
+// referenced values (as opposed to the memory addresses).
56
+func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
57
+	if !assert.Equal(t, expected, actual, msgAndArgs...) {
58
+		t.FailNow()
59
+	}
60
+}
61
+
62
+// EqualError asserts that a function returned an error (i.e. not `nil`)
63
+// and that it is equal to the provided error.
64
+//
65
+//   actualObj, err := SomeFunction()
66
+//   assert.EqualError(t, err,  expectedErrorString, "An error was expected")
67
+//
68
+// Returns whether the assertion was successful (true) or not (false).
69
+func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) {
70
+	if !assert.EqualError(t, theError, errString, msgAndArgs...) {
71
+		t.FailNow()
72
+	}
73
+}
74
+
75
+// EqualValues asserts that two objects are equal or convertable to the same types
76
+// and equal.
77
+//
78
+//    assert.EqualValues(t, uint32(123), int32(123), "123 and 123 should be equal")
79
+//
80
+// Returns whether the assertion was successful (true) or not (false).
81
+func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
82
+	if !assert.EqualValues(t, expected, actual, msgAndArgs...) {
83
+		t.FailNow()
84
+	}
85
+}
86
+
87
+// Error asserts that a function returned an error (i.e. not `nil`).
88
+//
89
+//   actualObj, err := SomeFunction()
90
+//   if assert.Error(t, err, "An error was expected") {
91
+// 	   assert.Equal(t, err, expectedError)
92
+//   }
93
+//
94
+// Returns whether the assertion was successful (true) or not (false).
95
+func Error(t TestingT, err error, msgAndArgs ...interface{}) {
96
+	if !assert.Error(t, err, msgAndArgs...) {
97
+		t.FailNow()
98
+	}
99
+}
100
+
101
+// Exactly asserts that two objects are equal is value and type.
102
+//
103
+//    assert.Exactly(t, int32(123), int64(123), "123 and 123 should NOT be equal")
104
+//
105
+// Returns whether the assertion was successful (true) or not (false).
106
+func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
107
+	if !assert.Exactly(t, expected, actual, msgAndArgs...) {
108
+		t.FailNow()
109
+	}
110
+}
111
+
112
+// Fail reports a failure through
113
+func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
114
+	if !assert.Fail(t, failureMessage, msgAndArgs...) {
115
+		t.FailNow()
116
+	}
117
+}
118
+
119
+// FailNow fails test
120
+func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
121
+	if !assert.FailNow(t, failureMessage, msgAndArgs...) {
122
+		t.FailNow()
123
+	}
124
+}
125
+
126
+// False asserts that the specified value is false.
127
+//
128
+//    assert.False(t, myBool, "myBool should be false")
129
+//
130
+// Returns whether the assertion was successful (true) or not (false).
131
+func False(t TestingT, value bool, msgAndArgs ...interface{}) {
132
+	if !assert.False(t, value, msgAndArgs...) {
133
+		t.FailNow()
134
+	}
135
+}
136
+
137
+// HTTPBodyContains asserts that a specified handler returns a
138
+// body that contains a string.
139
+//
140
+//  assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
141
+//
142
+// Returns whether the assertion was successful (true) or not (false).
143
+func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) {
144
+	if !assert.HTTPBodyContains(t, handler, method, url, values, str) {
145
+		t.FailNow()
146
+	}
147
+}
148
+
149
+// HTTPBodyNotContains asserts that a specified handler returns a
150
+// body that does not contain a string.
151
+//
152
+//  assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
153
+//
154
+// Returns whether the assertion was successful (true) or not (false).
155
+func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) {
156
+	if !assert.HTTPBodyNotContains(t, handler, method, url, values, str) {
157
+		t.FailNow()
158
+	}
159
+}
160
+
161
+// HTTPError asserts that a specified handler returns an error status code.
162
+//
163
+//  assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
164
+//
165
+// Returns whether the assertion was successful (true) or not (false).
166
+func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) {
167
+	if !assert.HTTPError(t, handler, method, url, values) {
168
+		t.FailNow()
169
+	}
170
+}
171
+
172
+// HTTPRedirect asserts that a specified handler returns a redirect status code.
173
+//
174
+//  assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
175
+//
176
+// Returns whether the assertion was successful (true) or not (false).
177
+func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) {
178
+	if !assert.HTTPRedirect(t, handler, method, url, values) {
179
+		t.FailNow()
180
+	}
181
+}
182
+
183
+// HTTPSuccess asserts that a specified handler returns a success status code.
184
+//
185
+//  assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil)
186
+//
187
+// Returns whether the assertion was successful (true) or not (false).
188
+func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) {
189
+	if !assert.HTTPSuccess(t, handler, method, url, values) {
190
+		t.FailNow()
191
+	}
192
+}
193
+
194
+// Implements asserts that an object is implemented by the specified interface.
195
+//
196
+//    assert.Implements(t, (*MyInterface)(nil), new(MyObject), "MyObject")
197
+func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
198
+	if !assert.Implements(t, interfaceObject, object, msgAndArgs...) {
199
+		t.FailNow()
200
+	}
201
+}
202
+
203
+// InDelta asserts that the two numerals are within delta of each other.
204
+//
205
+// 	 assert.InDelta(t, math.Pi, (22 / 7.0), 0.01)
206
+//
207
+// Returns whether the assertion was successful (true) or not (false).
208
+func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
209
+	if !assert.InDelta(t, expected, actual, delta, msgAndArgs...) {
210
+		t.FailNow()
211
+	}
212
+}
213
+
214
+// InDeltaSlice is the same as InDelta, except it compares two slices.
215
+func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
216
+	if !assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) {
217
+		t.FailNow()
218
+	}
219
+}
220
+
221
+// InEpsilon asserts that expected and actual have a relative error less than epsilon
222
+//
223
+// Returns whether the assertion was successful (true) or not (false).
224
+func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
225
+	if !assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) {
226
+		t.FailNow()
227
+	}
228
+}
229
+
230
+// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
231
+func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
232
+	if !assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) {
233
+		t.FailNow()
234
+	}
235
+}
236
+
237
+// IsType asserts that the specified objects are of the same type.
238
+func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
239
+	if !assert.IsType(t, expectedType, object, msgAndArgs...) {
240
+		t.FailNow()
241
+	}
242
+}
243
+
244
+// JSONEq asserts that two JSON strings are equivalent.
245
+//
246
+//  assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
247
+//
248
+// Returns whether the assertion was successful (true) or not (false).
249
+func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
250
+	if !assert.JSONEq(t, expected, actual, msgAndArgs...) {
251
+		t.FailNow()
252
+	}
253
+}
254
+
255
+// Len asserts that the specified object has specific length.
256
+// Len also fails if the object has a type that len() not accept.
257
+//
258
+//    assert.Len(t, mySlice, 3, "The size of slice is not 3")
259
+//
260
+// Returns whether the assertion was successful (true) or not (false).
261
+func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) {
262
+	if !assert.Len(t, object, length, msgAndArgs...) {
263
+		t.FailNow()
264
+	}
265
+}
266
+
267
+// Nil asserts that the specified object is nil.
268
+//
269
+//    assert.Nil(t, err, "err should be nothing")
270
+//
271
+// Returns whether the assertion was successful (true) or not (false).
272
+func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
273
+	if !assert.Nil(t, object, msgAndArgs...) {
274
+		t.FailNow()
275
+	}
276
+}
277
+
278
+// NoError asserts that a function returned no error (i.e. `nil`).
279
+//
280
+//   actualObj, err := SomeFunction()
281
+//   if assert.NoError(t, err) {
282
+// 	   assert.Equal(t, actualObj, expectedObj)
283
+//   }
284
+//
285
+// Returns whether the assertion was successful (true) or not (false).
286
+func NoError(t TestingT, err error, msgAndArgs ...interface{}) {
287
+	if !assert.NoError(t, err, msgAndArgs...) {
288
+		t.FailNow()
289
+	}
290
+}
291
+
292
+// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
293
+// specified substring or element.
294
+//
295
+//    assert.NotContains(t, "Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'")
296
+//    assert.NotContains(t, ["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'")
297
+//    assert.NotContains(t, {"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'")
298
+//
299
+// Returns whether the assertion was successful (true) or not (false).
300
+func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
301
+	if !assert.NotContains(t, s, contains, msgAndArgs...) {
302
+		t.FailNow()
303
+	}
304
+}
305
+
306
+// NotEmpty asserts that the specified object is NOT empty.  I.e. not nil, "", false, 0 or either
307
+// a slice or a channel with len == 0.
308
+//
309
+//  if assert.NotEmpty(t, obj) {
310
+//    assert.Equal(t, "two", obj[1])
311
+//  }
312
+//
313
+// Returns whether the assertion was successful (true) or not (false).
314
+func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
315
+	if !assert.NotEmpty(t, object, msgAndArgs...) {
316
+		t.FailNow()
317
+	}
318
+}
319
+
320
+// NotEqual asserts that the specified values are NOT equal.
321
+//
322
+//    assert.NotEqual(t, obj1, obj2, "two objects shouldn't be equal")
323
+//
324
+// Returns whether the assertion was successful (true) or not (false).
325
+//
326
+// Pointer variable equality is determined based on the equality of the
327
+// referenced values (as opposed to the memory addresses).
328
+func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
329
+	if !assert.NotEqual(t, expected, actual, msgAndArgs...) {
330
+		t.FailNow()
331
+	}
332
+}
333
+
334
+// NotNil asserts that the specified object is not nil.
335
+//
336
+//    assert.NotNil(t, err, "err should be something")
337
+//
338
+// Returns whether the assertion was successful (true) or not (false).
339
+func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
340
+	if !assert.NotNil(t, object, msgAndArgs...) {
341
+		t.FailNow()
342
+	}
343
+}
344
+
345
+// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
346
+//
347
+//   assert.NotPanics(t, func(){
348
+//     RemainCalm()
349
+//   }, "Calling RemainCalm() should NOT panic")
350
+//
351
+// Returns whether the assertion was successful (true) or not (false).
352
+func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
353
+	if !assert.NotPanics(t, f, msgAndArgs...) {
354
+		t.FailNow()
355
+	}
356
+}
357
+
358
+// NotRegexp asserts that a specified regexp does not match a string.
359
+//
360
+//  assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
361
+//  assert.NotRegexp(t, "^start", "it's not starting")
362
+//
363
+// Returns whether the assertion was successful (true) or not (false).
364
+func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
365
+	if !assert.NotRegexp(t, rx, str, msgAndArgs...) {
366
+		t.FailNow()
367
+	}
368
+}
369
+
370
+// NotZero asserts that i is not the zero value for its type and returns the truth.
371
+func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
372
+	if !assert.NotZero(t, i, msgAndArgs...) {
373
+		t.FailNow()
374
+	}
375
+}
376
+
377
+// Panics asserts that the code inside the specified PanicTestFunc panics.
378
+//
379
+//   assert.Panics(t, func(){
380
+//     GoCrazy()
381
+//   }, "Calling GoCrazy() should panic")
382
+//
383
+// Returns whether the assertion was successful (true) or not (false).
384
+func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
385
+	if !assert.Panics(t, f, msgAndArgs...) {
386
+		t.FailNow()
387
+	}
388
+}
389
+
390
+// Regexp asserts that a specified regexp matches a string.
391
+//
392
+//  assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
393
+//  assert.Regexp(t, "start...$", "it's not starting")
394
+//
395
+// Returns whether the assertion was successful (true) or not (false).
396
+func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
397
+	if !assert.Regexp(t, rx, str, msgAndArgs...) {
398
+		t.FailNow()
399
+	}
400
+}
401
+
402
+// True asserts that the specified value is true.
403
+//
404
+//    assert.True(t, myBool, "myBool should be true")
405
+//
406
+// Returns whether the assertion was successful (true) or not (false).
407
+func True(t TestingT, value bool, msgAndArgs ...interface{}) {
408
+	if !assert.True(t, value, msgAndArgs...) {
409
+		t.FailNow()
410
+	}
411
+}
412
+
413
+// WithinDuration asserts that the two times are within duration delta of each other.
414
+//
415
+//   assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s")
416
+//
417
+// Returns whether the assertion was successful (true) or not (false).
418
+func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
419
+	if !assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {
420
+		t.FailNow()
421
+	}
422
+}
423
+
424
+// Zero asserts that i is the zero value for its type and returns the truth.
425
+func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
426
+	if !assert.Zero(t, i, msgAndArgs...) {
427
+		t.FailNow()
428
+	}
429
+}

+ 6 - 0
vendor/github.com/stretchr/testify/require/require.go.tmpl

@@ -0,0 +1,6 @@
1
+{{.Comment}}
2
+func {{.DocInfo.Name}}(t TestingT, {{.Params}}) {
3
+	if !assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) {
4
+		t.FailNow()
5
+	}
6
+}

+ 353 - 0
vendor/github.com/stretchr/testify/require/require_forward.go

@@ -0,0 +1,353 @@
1
+/*
2
+* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
3
+* THIS FILE MUST NOT BE EDITED BY HAND
4
+ */
5
+
6
+package require
7
+
8
+import (
9
+	assert "github.com/stretchr/testify/assert"
10
+	http "net/http"
11
+	url "net/url"
12
+	time "time"
13
+)
14
+
15
+// Condition uses a Comparison to assert a complex condition.
16
+func (a *Assertions) Condition(comp assert.Comparison, msgAndArgs ...interface{}) {
17
+	Condition(a.t, comp, msgAndArgs...)
18
+}
19
+
20
+// Contains asserts that the specified string, list(array, slice...) or map contains the
21
+// specified substring or element.
22
+//
23
+//    a.Contains("Hello World", "World", "But 'Hello World' does contain 'World'")
24
+//    a.Contains(["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'")
25
+//    a.Contains({"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'")
26
+//
27
+// Returns whether the assertion was successful (true) or not (false).
28
+func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) {
29
+	Contains(a.t, s, contains, msgAndArgs...)
30
+}
31
+
32
+// Empty asserts that the specified object is empty.  I.e. nil, "", false, 0 or either
33
+// a slice or a channel with len == 0.
34
+//
35
+//  a.Empty(obj)
36
+//
37
+// Returns whether the assertion was successful (true) or not (false).
38
+func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) {
39
+	Empty(a.t, object, msgAndArgs...)
40
+}
41
+
42
+// Equal asserts that two objects are equal.
43
+//
44
+//    a.Equal(123, 123, "123 and 123 should be equal")
45
+//
46
+// Returns whether the assertion was successful (true) or not (false).
47
+//
48
+// Pointer variable equality is determined based on the equality of the
49
+// referenced values (as opposed to the memory addresses).
50
+func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
51
+	Equal(a.t, expected, actual, msgAndArgs...)
52
+}
53
+
54
+// EqualError asserts that a function returned an error (i.e. not `nil`)
55
+// and that it is equal to the provided error.
56
+//
57
+//   actualObj, err := SomeFunction()
58
+//   a.EqualError(err,  expectedErrorString, "An error was expected")
59
+//
60
+// Returns whether the assertion was successful (true) or not (false).
61
+func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) {
62
+	EqualError(a.t, theError, errString, msgAndArgs...)
63
+}
64
+
65
+// EqualValues asserts that two objects are equal or convertable to the same types
66
+// and equal.
67
+//
68
+//    a.EqualValues(uint32(123), int32(123), "123 and 123 should be equal")
69
+//
70
+// Returns whether the assertion was successful (true) or not (false).
71
+func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
72
+	EqualValues(a.t, expected, actual, msgAndArgs...)
73
+}
74
+
75
+// Error asserts that a function returned an error (i.e. not `nil`).
76
+//
77
+//   actualObj, err := SomeFunction()
78
+//   if a.Error(err, "An error was expected") {
79
+// 	   assert.Equal(t, err, expectedError)
80
+//   }
81
+//
82
+// Returns whether the assertion was successful (true) or not (false).
83
+func (a *Assertions) Error(err error, msgAndArgs ...interface{}) {
84
+	Error(a.t, err, msgAndArgs...)
85
+}
86
+
87
+// Exactly asserts that two objects are equal is value and type.
88
+//
89
+//    a.Exactly(int32(123), int64(123), "123 and 123 should NOT be equal")
90
+//
91
+// Returns whether the assertion was successful (true) or not (false).
92
+func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
93
+	Exactly(a.t, expected, actual, msgAndArgs...)
94
+}
95
+
96
+// Fail reports a failure through
97
+func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) {
98
+	Fail(a.t, failureMessage, msgAndArgs...)
99
+}
100
+
101
+// FailNow fails test
102
+func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) {
103
+	FailNow(a.t, failureMessage, msgAndArgs...)
104
+}
105
+
106
+// False asserts that the specified value is false.
107
+//
108
+//    a.False(myBool, "myBool should be false")
109
+//
110
+// Returns whether the assertion was successful (true) or not (false).
111
+func (a *Assertions) False(value bool, msgAndArgs ...interface{}) {
112
+	False(a.t, value, msgAndArgs...)
113
+}
114
+
115
+// HTTPBodyContains asserts that a specified handler returns a
116
+// body that contains a string.
117
+//
118
+//  a.HTTPBodyContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky")
119
+//
120
+// Returns whether the assertion was successful (true) or not (false).
121
+func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) {
122
+	HTTPBodyContains(a.t, handler, method, url, values, str)
123
+}
124
+
125
+// HTTPBodyNotContains asserts that a specified handler returns a
126
+// body that does not contain a string.
127
+//
128
+//  a.HTTPBodyNotContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky")
129
+//
130
+// Returns whether the assertion was successful (true) or not (false).
131
+func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) {
132
+	HTTPBodyNotContains(a.t, handler, method, url, values, str)
133
+}
134
+
135
+// HTTPError asserts that a specified handler returns an error status code.
136
+//
137
+//  a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
138
+//
139
+// Returns whether the assertion was successful (true) or not (false).
140
+func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values) {
141
+	HTTPError(a.t, handler, method, url, values)
142
+}
143
+
144
+// HTTPRedirect asserts that a specified handler returns a redirect status code.
145
+//
146
+//  a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
147
+//
148
+// Returns whether the assertion was successful (true) or not (false).
149
+func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values) {
150
+	HTTPRedirect(a.t, handler, method, url, values)
151
+}
152
+
153
+// HTTPSuccess asserts that a specified handler returns a success status code.
154
+//
155
+//  a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)
156
+//
157
+// Returns whether the assertion was successful (true) or not (false).
158
+func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values) {
159
+	HTTPSuccess(a.t, handler, method, url, values)
160
+}
161
+
162
+// Implements asserts that an object is implemented by the specified interface.
163
+//
164
+//    a.Implements((*MyInterface)(nil), new(MyObject), "MyObject")
165
+func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
166
+	Implements(a.t, interfaceObject, object, msgAndArgs...)
167
+}
168
+
169
+// InDelta asserts that the two numerals are within delta of each other.
170
+//
171
+// 	 a.InDelta(math.Pi, (22 / 7.0), 0.01)
172
+//
173
+// Returns whether the assertion was successful (true) or not (false).
174
+func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
175
+	InDelta(a.t, expected, actual, delta, msgAndArgs...)
176
+}
177
+
178
+// InDeltaSlice is the same as InDelta, except it compares two slices.
179
+func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
180
+	InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...)
181
+}
182
+
183
+// InEpsilon asserts that expected and actual have a relative error less than epsilon
184
+//
185
+// Returns whether the assertion was successful (true) or not (false).
186
+func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
187
+	InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...)
188
+}
189
+
190
+// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
191
+func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
192
+	InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...)
193
+}
194
+
195
+// IsType asserts that the specified objects are of the same type.
196
+func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
197
+	IsType(a.t, expectedType, object, msgAndArgs...)
198
+}
199
+
200
+// JSONEq asserts that two JSON strings are equivalent.
201
+//
202
+//  a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
203
+//
204
+// Returns whether the assertion was successful (true) or not (false).
205
+func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) {
206
+	JSONEq(a.t, expected, actual, msgAndArgs...)
207
+}
208
+
209
+// Len asserts that the specified object has specific length.
210
+// Len also fails if the object has a type that len() not accept.
211
+//
212
+//    a.Len(mySlice, 3, "The size of slice is not 3")
213
+//
214
+// Returns whether the assertion was successful (true) or not (false).
215
+func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) {
216
+	Len(a.t, object, length, msgAndArgs...)
217
+}
218
+
219
+// Nil asserts that the specified object is nil.
220
+//
221
+//    a.Nil(err, "err should be nothing")
222
+//
223
+// Returns whether the assertion was successful (true) or not (false).
224
+func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) {
225
+	Nil(a.t, object, msgAndArgs...)
226
+}
227
+
228
+// NoError asserts that a function returned no error (i.e. `nil`).
229
+//
230
+//   actualObj, err := SomeFunction()
231
+//   if a.NoError(err) {
232
+// 	   assert.Equal(t, actualObj, expectedObj)
233
+//   }
234
+//
235
+// Returns whether the assertion was successful (true) or not (false).
236
+func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) {
237
+	NoError(a.t, err, msgAndArgs...)
238
+}
239
+
240
+// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
241
+// specified substring or element.
242
+//
243
+//    a.NotContains("Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'")
244
+//    a.NotContains(["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'")
245
+//    a.NotContains({"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'")
246
+//
247
+// Returns whether the assertion was successful (true) or not (false).
248
+func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) {
249
+	NotContains(a.t, s, contains, msgAndArgs...)
250
+}
251
+
252
+// NotEmpty asserts that the specified object is NOT empty.  I.e. not nil, "", false, 0 or either
253
+// a slice or a channel with len == 0.
254
+//
255
+//  if a.NotEmpty(obj) {
256
+//    assert.Equal(t, "two", obj[1])
257
+//  }
258
+//
259
+// Returns whether the assertion was successful (true) or not (false).
260
+func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) {
261
+	NotEmpty(a.t, object, msgAndArgs...)
262
+}
263
+
264
+// NotEqual asserts that the specified values are NOT equal.
265
+//
266
+//    a.NotEqual(obj1, obj2, "two objects shouldn't be equal")
267
+//
268
+// Returns whether the assertion was successful (true) or not (false).
269
+//
270
+// Pointer variable equality is determined based on the equality of the
271
+// referenced values (as opposed to the memory addresses).
272
+func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
273
+	NotEqual(a.t, expected, actual, msgAndArgs...)
274
+}
275
+
276
+// NotNil asserts that the specified object is not nil.
277
+//
278
+//    a.NotNil(err, "err should be something")
279
+//
280
+// Returns whether the assertion was successful (true) or not (false).
281
+func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) {
282
+	NotNil(a.t, object, msgAndArgs...)
283
+}
284
+
285
+// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
286
+//
287
+//   a.NotPanics(func(){
288
+//     RemainCalm()
289
+//   }, "Calling RemainCalm() should NOT panic")
290
+//
291
+// Returns whether the assertion was successful (true) or not (false).
292
+func (a *Assertions) NotPanics(f assert.PanicTestFunc, msgAndArgs ...interface{}) {
293
+	NotPanics(a.t, f, msgAndArgs...)
294
+}
295
+
296
+// NotRegexp asserts that a specified regexp does not match a string.
297
+//
298
+//  a.NotRegexp(regexp.MustCompile("starts"), "it's starting")
299
+//  a.NotRegexp("^start", "it's not starting")
300
+//
301
+// Returns whether the assertion was successful (true) or not (false).
302
+func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) {
303
+	NotRegexp(a.t, rx, str, msgAndArgs...)
304
+}
305
+
306
+// NotZero asserts that i is not the zero value for its type and returns the truth.
307
+func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) {
308
+	NotZero(a.t, i, msgAndArgs...)
309
+}
310
+
311
+// Panics asserts that the code inside the specified PanicTestFunc panics.
312
+//
313
+//   a.Panics(func(){
314
+//     GoCrazy()
315
+//   }, "Calling GoCrazy() should panic")
316
+//
317
+// Returns whether the assertion was successful (true) or not (false).
318
+func (a *Assertions) Panics(f assert.PanicTestFunc, msgAndArgs ...interface{}) {
319
+	Panics(a.t, f, msgAndArgs...)
320
+}
321
+
322
+// Regexp asserts that a specified regexp matches a string.
323
+//
324
+//  a.Regexp(regexp.MustCompile("start"), "it's starting")
325
+//  a.Regexp("start...$", "it's not starting")
326
+//
327
+// Returns whether the assertion was successful (true) or not (false).
328
+func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) {
329
+	Regexp(a.t, rx, str, msgAndArgs...)
330
+}
331
+
332
+// True asserts that the specified value is true.
333
+//
334
+//    a.True(myBool, "myBool should be true")
335
+//
336
+// Returns whether the assertion was successful (true) or not (false).
337
+func (a *Assertions) True(value bool, msgAndArgs ...interface{}) {
338
+	True(a.t, value, msgAndArgs...)
339
+}
340
+
341
+// WithinDuration asserts that the two times are within duration delta of each other.
342
+//
343
+//   a.WithinDuration(time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s")
344
+//
345
+// Returns whether the assertion was successful (true) or not (false).
346
+func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
347
+	WithinDuration(a.t, expected, actual, delta, msgAndArgs...)
348
+}
349
+
350
+// Zero asserts that i is the zero value for its type and returns the truth.
351
+func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) {
352
+	Zero(a.t, i, msgAndArgs...)
353
+}

+ 4 - 0
vendor/github.com/stretchr/testify/require/require_forward.go.tmpl

@@ -0,0 +1,4 @@
1
+{{.CommentWithoutT "a"}}
2
+func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) {
3
+	{{.DocInfo.Name}}(a.t, {{.ForwardedParams}})
4
+}

+ 9 - 0
vendor/github.com/stretchr/testify/require/requirements.go

@@ -0,0 +1,9 @@
1
+package require
2
+
3
+// TestingT is an interface wrapper around *testing.T
4
+type TestingT interface {
5
+	Errorf(format string, args ...interface{})
6
+	FailNow()
7
+}
8
+
9
+//go:generate go run ../_codegen/main.go -output-package=require -template=require.go.tmpl

+ 21 - 0
vendor/gopkg.in/testfixtures.v2/LICENSE

@@ -0,0 +1,21 @@
1
+The MIT License (MIT)
2
+
3
+Copyright (c) 2016 Andrey Nering
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 all
13
+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 THE
21
+SOFTWARE.

+ 323 - 0
vendor/gopkg.in/testfixtures.v2/README.md

@@ -0,0 +1,323 @@
1
+# Go Test Fixtures
2
+
3
+[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/go-testfixtures/testfixtures/blob/master/LICENSE)
4
+[![Join the chat at https://gitter.im/go-testfixtures/testfixtures](https://badges.gitter.im/go-testfixtures/testfixtures.svg)](https://gitter.im/go-testfixtures/testfixtures?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5
+[![GoDoc](https://godoc.org/gopkg.in/testfixtures.v1?status.svg)](https://godoc.org/gopkg.in/testfixtures.v1)
6
+[![Build Status](https://travis-ci.org/go-testfixtures/testfixtures.svg?branch=master)](https://travis-ci.org/go-testfixtures/testfixtures)
7
+[![Go Report Card](https://goreportcard.com/badge/github.com/go-testfixtures/testfixtures)](https://goreportcard.com/report/github.com/go-testfixtures/testfixtures)
8
+
9
+> ***Warning***: this package will wipe the database data before loading the
10
+fixtures! It is supposed to be used on a test database. Please, double check
11
+if you are running it against the correct database.
12
+
13
+Writing tests is hard, even more when you have to deal with an SQL database.
14
+This package aims to make writing functional tests for web apps written in
15
+Go easier.
16
+
17
+Basically this package mimics the ["Rails' way"][railstests] of writing tests
18
+for database applications, where sample data is kept in fixtures files. Before
19
+the execution of every test, the test database is cleaned and the fixture data
20
+is loaded into the database.
21
+
22
+The idea is running tests against a real database, instead of relying in mocks,
23
+which is boring to setup and may lead to production bugs not to being catch in
24
+the tests.
25
+
26
+## Installation
27
+
28
+First, get it:
29
+
30
+```bash
31
+go get -u gopkg.in/testfixtures.v2
32
+```
33
+
34
+## Usage
35
+
36
+Create a folder for the fixture files. Each file should contain data for a
37
+single table and have the name `<table-name>.yml`:
38
+
39
+```yml
40
+myapp
41
+  - myapp.go
42
+  - myapp_test.go
43
+  - ...
44
+  - fixtures:
45
+    - posts.yml
46
+    - comments.yml
47
+    - tags.yml
48
+    - posts_tags.yml
49
+    - ...
50
+```
51
+
52
+The file would look like this (it can have as many record you want):
53
+
54
+```yml
55
+# comments.yml
56
+-
57
+    id: 1
58
+    post_id: 1
59
+    content: This post is awesome!
60
+    author_name: John Doe
61
+    author_email: john@doe.com
62
+    created_at: 2016-01-01 12:30:12
63
+    updated_at: 2016-01-01 12:30:12
64
+
65
+-
66
+    id: 2
67
+    post_id: 2
68
+    content: Are you kidding me?
69
+    author_name: John Doe
70
+    author_email: john@doe.com
71
+    created_at: 2016-01-01 12:30:12
72
+    updated_at: 2016-01-01 12:30:12
73
+
74
+# ...
75
+```
76
+
77
+Your tests would look like this:
78
+
79
+```go
80
+package myapp
81
+
82
+import (
83
+    "database/sql"
84
+    "log"
85
+
86
+    _ "github.com/lib/pq"
87
+    "gopkg.in/testfixtures.v2"
88
+)
89
+
90
+var (
91
+    db *sql.DB
92
+	fixtures *testfixtures.Context
93
+)
94
+
95
+func TestMain(m *testing.M) {
96
+    var err error
97
+
98
+    // Open connection with the test database.
99
+    // Do NOT import fixtures in a production database!
100
+    // Existing data would be deleted
101
+    db, err = sql.Open("postgres", "dbname=myapp_test")
102
+    if err != nil {
103
+        log.Fatal(err)
104
+    }
105
+
106
+    // creating the context that hold the fixtures
107
+    // see about all compatible databases in this page below
108
+    c, err = testfixtures.NewFolder(db, &testfixtures.PostgreSQL{}, "testdata/fixtures")
109
+    if err != nil {
110
+        log.Fatal(err)
111
+	}
112
+
113
+    os.Exit(m.Run())
114
+}
115
+
116
+func prepareTestDatabase() {
117
+    if err := fixtures.Load(); err != nil {
118
+        log.Fatal(err)
119
+    }
120
+}
121
+
122
+func TestX(t *testing.T) {
123
+    prepareTestDatabase()
124
+    // your test here ...
125
+}
126
+
127
+func TestY(t *testing.T) {
128
+    prepareTestDatabase()
129
+    // your test here ...
130
+}
131
+
132
+func TestZ(t *testing.T) {
133
+    prepareTestDatabase()
134
+    // your test here ...
135
+}
136
+```
137
+
138
+Alternatively, you can use the `NewFiles` function, to specify which
139
+files you want to load into the database:
140
+
141
+```go
142
+fixtures, err := testfixtures.NewFiles(db, &testfixtures.PostgreSQL{},
143
+    "fixtures/orders.yml",
144
+    "fixtures/customers.yml",
145
+    // add as many files you want
146
+)
147
+if err != nil {
148
+	log.Fatal(err)
149
+}
150
+```
151
+
152
+## Security check
153
+
154
+In order to prevent you from accidentally wiping the wrong database, this
155
+package will refuse to load fixtures if the database name (or database
156
+filename for SQLite) doesn't contains "test". If you want to disable this
157
+check, use:
158
+
159
+```go
160
+testfixtures.SkipDatabaseNameCheck(true)
161
+```
162
+
163
+## Sequences
164
+
165
+For PostgreSQL or Oracle, this package also resets all sequences to a high
166
+number to prevent duplicated primary keys while running the tests.
167
+The default is 10000, but you can change that with:
168
+
169
+```go
170
+testfixtures.ResetSequencesTo(10000)
171
+```
172
+
173
+## Compatible databases
174
+
175
+### PostgreSQL
176
+
177
+This package has two approaches to disable foreign keys while importing fixtures
178
+in PostgreSQL databases:
179
+
180
+#### With `DISABLE TRIGGER`
181
+
182
+This is the default approach. For that use:
183
+
184
+```go
185
+&testfixtures.PostgreSQL{}
186
+```
187
+
188
+With the above snippet this package will use `DISABLE TRIGGER` to temporarily
189
+disabling foreign key constraints while loading fixtures. This work with any
190
+version of PostgreSQL, but it is **required** to be connected in the database
191
+as a SUPERUSER. You can make a PostgreSQL user a SUPERUSER with:
192
+
193
+```sql
194
+ALTER USER your_user SUPERUSER;
195
+```
196
+
197
+#### With `ALTER CONSTRAINT`
198
+
199
+This approach don't require to be connected as a SUPERUSER, but only work with
200
+PostgreSQL versions >= 9.4. Try this if you are getting foreign key violation
201
+errors with the previous approach. It is as simple as using:
202
+
203
+```go
204
+&testfixtures.PostgreSQL{UseAlterConstraint: true}
205
+```
206
+
207
+### MySQL
208
+
209
+Just make sure the connection string have
210
+[the multistatement parameter](https://github.com/go-sql-driver/mysql#multistatements)
211
+set to true, and use:
212
+
213
+```go
214
+&testfixtures.MySQL{}
215
+```
216
+
217
+### SQLite
218
+
219
+SQLite is also supported. It is recommended to create foreign keys as
220
+`DEFERRABLE` (the default) to prevent problems. See more
221
+[on the SQLite documentation](https://www.sqlite.org/foreignkeys.html#fk_deferred).
222
+(Foreign key constraints are no-op by default on SQLite, but enabling it is
223
+recommended).
224
+
225
+```go
226
+&testfixtures.SQLite{}
227
+```
228
+
229
+### Microsoft SQL Server
230
+
231
+SQL Server support requires SQL Server >= 2008. Inserting on `IDENTITY` columns
232
+are handled as well. Just make sure you are logged in with a user with
233
+`ALTER TABLE` permission.
234
+
235
+```go
236
+&testfixtures.SQLServer{}
237
+```
238
+
239
+### Oracle
240
+
241
+Oracle is supported as well. Use:
242
+
243
+```go
244
+&testfixtures.Oracle{}
245
+```
246
+
247
+## Contributing
248
+
249
+Tests were written to ensure everything work as expected. You can run the tests
250
+with:
251
+
252
+```bash
253
+# running tests for PostgreSQL
254
+go test -tags postgresql
255
+
256
+# running test for MySQL
257
+go test -tags mysql
258
+
259
+# running tests for SQLite
260
+go test -tags sqlite
261
+
262
+# running tests for SQL Server
263
+go test -tags sqlserver
264
+
265
+# running tests for Oracle
266
+go test -tags oracle
267
+
268
+# running test for multiple databases at once
269
+go test -tags 'sqlite postgresql mysql'
270
+
271
+# running tests + benchmark
272
+go test -v -bench=. -tags postgresql
273
+```
274
+
275
+Travis runs tests for PostgreSQL, MySQL and SQLite.
276
+
277
+To set the connection string of tests for each database, edit the `.env`
278
+file, but do not include the changes a in pull request.
279
+
280
+## Changes in v2
281
+
282
+A context was created to allow cache of some SQL statements. See in the
283
+documentation above how to use it.
284
+
285
+The helpers were renamed to have a smaller name:
286
+
287
+```go
288
+PostgreSQLHelper{} -> PostgreSQL{}
289
+MySQLHelper{}      -> MySQL{}
290
+SQLiteHelper{}     -> SQLite{}
291
+SQLServerHelper{}  -> SQLServer{}
292
+OracleHelper{}     -> Oracle{}
293
+```
294
+
295
+The old functions and helpers are still available for backward compatibility.
296
+See the file [deprecated.go](https://github.com/go-testfixtures/testfixtures/blob/master/LICENSE)
297
+
298
+## Alternatives
299
+
300
+If you don't think using fixtures is a good idea, you can try one of these
301
+packages instead:
302
+
303
+- [factory-go][factorygo]: Factory for Go. Inspired by Python's Factory Boy
304
+and Ruby's Factory Girl
305
+- [go-txdb (Single transaction SQL driver for Go)][gotxdb]: Use a single
306
+database transaction for each functional test, so you can rollback to
307
+previous state between tests to have the same database state in all tests
308
+- [go-sqlmock][gosqlmock]: A mock for the sql.DB interface. This allow you to unit
309
+test database code without having to connect to a real database
310
+
311
+There's also these other implementations of test fixtures for Go:
312
+
313
+- [go-fixtures][gofixtures]: Django style fixtures for Go
314
+- [mongofixtures][mongofixtures]: Fixtures for MongoDB
315
+- [fixturer][fixturer]: Another fixture loader supporting MySQL
316
+
317
+[railstests]: http://guides.rubyonrails.org/testing.html#the-test-database
318
+[gotxdb]: https://github.com/DATA-DOG/go-txdb
319
+[gosqlmock]: https://github.com/DATA-DOG/go-sqlmock
320
+[gofixtures]: https://github.com/AreaHQ/go-fixtures
321
+[mongofixtures]: https://github.com/OwlyCode/mongofixtures
322
+[fixturer]: https://github.com/44hapa/fixturer
323
+[factorygo]: https://github.com/bluele/factory-go

+ 59 - 0
vendor/gopkg.in/testfixtures.v2/deprecated.go

@@ -0,0 +1,59 @@
1
+package testfixtures
2
+
3
+import (
4
+	"database/sql"
5
+)
6
+
7
+type (
8
+	DataBaseHelper Helper // Deprecated: Use Helper instead
9
+
10
+	PostgreSQLHelper struct { // Deprecated: Use PostgreSQL{} instead
11
+		PostgreSQL
12
+		UseAlterConstraint bool
13
+	}
14
+	MySQLHelper struct { // Deprecated: Use MySQL{} instead
15
+		MySQL
16
+	}
17
+	SQLiteHelper struct { // Deprecated: Use SQLite{} instead
18
+		SQLite
19
+	}
20
+	SQLServerHelper struct { // Deprecated: Use SQLServer{} instead
21
+		SQLServer
22
+	}
23
+	OracleHelper struct { // Deprecated: Use Oracle{} instead
24
+		Oracle
25
+	}
26
+)
27
+
28
+func (h *PostgreSQLHelper) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) error {
29
+	h.PostgreSQL.UseAlterConstraint = h.UseAlterConstraint
30
+	return h.PostgreSQL.disableReferentialIntegrity(db, loadFn)
31
+}
32
+
33
+// LoadFixtureFiles load all specified fixtures files into database:
34
+// 		LoadFixtureFiles(db, &PostgreSQL{},
35
+// 			"fixtures/customers.yml", "fixtures/orders.yml")
36
+//			// add as many files you want
37
+//
38
+// Deprecated: Use NewFiles() and Load() instead.
39
+func LoadFixtureFiles(db *sql.DB, helper Helper, files ...string) error {
40
+	c, err := NewFiles(db, helper, files...)
41
+	if err != nil {
42
+		return err
43
+	}
44
+
45
+	return c.Load()
46
+}
47
+
48
+// LoadFixtures loads all fixtures in a given folder into the database:
49
+// 		LoadFixtures("myfixturesfolder", db, &PostgreSQL{})
50
+//
51
+// Deprecated: Use NewFolder() and Load() instead.
52
+func LoadFixtures(folderName string, db *sql.DB, helper Helper) error {
53
+	c, err := NewFolder(db, helper, folderName)
54
+	if err != nil {
55
+		return err
56
+	}
57
+
58
+	return c.Load()
59
+}

+ 38 - 0
vendor/gopkg.in/testfixtures.v2/helper.go

@@ -0,0 +1,38 @@
1
+package testfixtures
2
+
3
+import (
4
+	"database/sql"
5
+	"fmt"
6
+)
7
+
8
+const (
9
+	paramTypeDollar = iota + 1
10
+	paramTypeQuestion
11
+	paramTypeColon
12
+)
13
+
14
+type loadFunction func(tx *sql.Tx) error
15
+
16
+// Helper is the generic interface for the database helper
17
+type Helper interface {
18
+	init(*sql.DB) error
19
+	disableReferentialIntegrity(*sql.DB, loadFunction) error
20
+	paramType() int
21
+	databaseName(*sql.DB) string
22
+	quoteKeyword(string) string
23
+	whileInsertOnTable(*sql.Tx, string, func() error) error
24
+}
25
+
26
+type baseHelper struct{}
27
+
28
+func (*baseHelper) init(_ *sql.DB) error {
29
+	return nil
30
+}
31
+
32
+func (*baseHelper) quoteKeyword(str string) string {
33
+	return fmt.Sprintf(`"%s"`, str)
34
+}
35
+
36
+func (*baseHelper) whileInsertOnTable(_ *sql.Tx, _ string, fn func() error) error {
37
+	return fn()
38
+}

+ 45 - 0
vendor/gopkg.in/testfixtures.v2/mysql.go

@@ -0,0 +1,45 @@
1
+package testfixtures
2
+
3
+import (
4
+	"database/sql"
5
+	"fmt"
6
+)
7
+
8
+// MySQL is the MySQL helper for this package
9
+type MySQL struct {
10
+	baseHelper
11
+}
12
+
13
+func (*MySQL) paramType() int {
14
+	return paramTypeQuestion
15
+}
16
+
17
+func (*MySQL) quoteKeyword(str string) string {
18
+	return fmt.Sprintf("`%s`", str)
19
+}
20
+
21
+func (*MySQL) databaseName(db *sql.DB) (dbName string) {
22
+	db.QueryRow("SELECT DATABASE()").Scan(&dbName)
23
+	return
24
+}
25
+
26
+func (h *MySQL) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) error {
27
+	// re-enable after load
28
+	defer db.Exec("SET FOREIGN_KEY_CHECKS = 1")
29
+
30
+	tx, err := db.Begin()
31
+	if err != nil {
32
+		return err
33
+	}
34
+
35
+	if _, err = tx.Exec("SET FOREIGN_KEY_CHECKS = 0"); err != nil {
36
+		return err
37
+	}
38
+
39
+	if err = loadFn(tx); err != nil {
40
+		tx.Rollback()
41
+		return err
42
+	}
43
+
44
+	return tx.Commit()
45
+}

+ 19 - 0
vendor/gopkg.in/testfixtures.v2/options.go

@@ -0,0 +1,19 @@
1
+package testfixtures
2
+
3
+var (
4
+	skipDatabaseNameCheck bool
5
+	resetSequencesTo      int64 = 10000
6
+)
7
+
8
+// SkipDatabaseNameCheck If true, loading fixtures will not check if the database
9
+// name constaint "test". Use with caution!
10
+func SkipDatabaseNameCheck(value bool) {
11
+	skipDatabaseNameCheck = value
12
+}
13
+
14
+// ResetSequencesTo sets the value the sequences will be reset to.
15
+// This is used by PostgreSQL and Oracle.
16
+// Defaults to 10000.
17
+func ResetSequencesTo(value int64) {
18
+	resetSequencesTo = value
19
+}

+ 132 - 0
vendor/gopkg.in/testfixtures.v2/oracle.go

@@ -0,0 +1,132 @@
1
+package testfixtures
2
+
3
+import (
4
+	"database/sql"
5
+	"fmt"
6
+	"strings"
7
+)
8
+
9
+// Oracle is the Oracle database helper for this package
10
+type Oracle struct {
11
+	baseHelper
12
+
13
+	enabledConstraints []oracleConstraint
14
+	sequences          []string
15
+}
16
+
17
+type oracleConstraint struct {
18
+	tableName      string
19
+	constraintName string
20
+}
21
+
22
+func (h *Oracle) init(db *sql.DB) error {
23
+	var err error
24
+
25
+	h.enabledConstraints, err = h.getEnabledConstraints(db)
26
+	if err != nil {
27
+		return err
28
+	}
29
+
30
+	h.sequences, err = h.getSequences(db)
31
+	if err != nil {
32
+		return err
33
+	}
34
+
35
+	return nil
36
+}
37
+
38
+func (*Oracle) paramType() int {
39
+	return paramTypeColon
40
+}
41
+
42
+func (*Oracle) quoteKeyword(str string) string {
43
+	return fmt.Sprintf("\"%s\"", strings.ToUpper(str))
44
+}
45
+
46
+func (*Oracle) databaseName(db *sql.DB) (dbName string) {
47
+	db.QueryRow("SELECT user FROM DUAL").Scan(&dbName)
48
+	return
49
+}
50
+
51
+func (*Oracle) getEnabledConstraints(db *sql.DB) ([]oracleConstraint, error) {
52
+	constraints := make([]oracleConstraint, 0)
53
+	rows, err := db.Query(`
54
+        SELECT table_name, constraint_name
55
+        FROM user_constraints
56
+        WHERE constraint_type = 'R'
57
+          AND status = 'ENABLED'
58
+    `)
59
+	if err != nil {
60
+		return nil, err
61
+	}
62
+	defer rows.Close()
63
+	for rows.Next() {
64
+		var constraint oracleConstraint
65
+		rows.Scan(&constraint.tableName, &constraint.constraintName)
66
+		constraints = append(constraints, constraint)
67
+	}
68
+	return constraints, nil
69
+}
70
+
71
+func (*Oracle) getSequences(db *sql.DB) ([]string, error) {
72
+	sequences := make([]string, 0)
73
+	rows, err := db.Query("SELECT sequence_name FROM user_sequences")
74
+	if err != nil {
75
+		return nil, err
76
+	}
77
+
78
+	defer rows.Close()
79
+	for rows.Next() {
80
+		var sequence string
81
+		rows.Scan(&sequence)
82
+		sequences = append(sequences, sequence)
83
+	}
84
+	return sequences, nil
85
+}
86
+
87
+func (h *Oracle) resetSequences(db *sql.DB) error {
88
+	for _, sequence := range h.sequences {
89
+		_, err := db.Exec(fmt.Sprintf("DROP SEQUENCE %s", h.quoteKeyword(sequence)))
90
+		if err != nil {
91
+			return err
92
+		}
93
+		_, err = db.Exec(fmt.Sprintf("CREATE SEQUENCE %s START WITH %d", h.quoteKeyword(sequence), resetSequencesTo))
94
+		if err != nil {
95
+			return err
96
+		}
97
+	}
98
+	return nil
99
+}
100
+
101
+func (h *Oracle) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) error {
102
+	// re-enable after load
103
+	defer func() {
104
+		for _, c := range h.enabledConstraints {
105
+			db.Exec(fmt.Sprintf("ALTER TABLE %s ENABLE CONSTRAINT %s", h.quoteKeyword(c.tableName), h.quoteKeyword(c.constraintName)))
106
+		}
107
+	}()
108
+
109
+	// disable foreign keys
110
+	for _, c := range h.enabledConstraints {
111
+		_, err := db.Exec(fmt.Sprintf("ALTER TABLE %s DISABLE CONSTRAINT %s", h.quoteKeyword(c.tableName), h.quoteKeyword(c.constraintName)))
112
+		if err != nil {
113
+			return err
114
+		}
115
+	}
116
+
117
+	tx, err := db.Begin()
118
+	if err != nil {
119
+		return err
120
+	}
121
+
122
+	if err = loadFn(tx); err != nil {
123
+		tx.Rollback()
124
+		return err
125
+	}
126
+
127
+	if err = tx.Commit(); err != nil {
128
+		return err
129
+	}
130
+
131
+	return h.resetSequences(db)
132
+}

+ 211 - 0
vendor/gopkg.in/testfixtures.v2/postgresql.go

@@ -0,0 +1,211 @@
1
+package testfixtures
2
+
3
+import (
4
+	"database/sql"
5
+	"fmt"
6
+)
7
+
8
+// PostgreSQL is the PG helper for this package
9
+type PostgreSQL struct {
10
+	baseHelper
11
+
12
+	// UseAlterConstraint If true, the contraint disabling will do
13
+	// using ALTER CONTRAINT sintax, only allowed in PG >= 9.4.
14
+	// If false, the constraint disabling will use DISABLE TRIGGER ALL,
15
+	// which requires SUPERUSER privileges.
16
+	UseAlterConstraint bool
17
+
18
+	tables                   []string
19
+	sequences                []string
20
+	nonDeferrableConstraints []pgConstraint
21
+}
22
+
23
+type pgConstraint struct {
24
+	tableName      string
25
+	constraintName string
26
+}
27
+
28
+func (h *PostgreSQL) init(db *sql.DB) error {
29
+	var err error
30
+
31
+	h.tables, err = h.getTables(db)
32
+	if err != nil {
33
+		return err
34
+	}
35
+
36
+	h.sequences, err = h.getSequences(db)
37
+	if err != nil {
38
+		return err
39
+	}
40
+
41
+	h.nonDeferrableConstraints, err = h.getNonDeferrableConstraints(db)
42
+	if err != nil {
43
+		return err
44
+	}
45
+
46
+	return nil
47
+}
48
+
49
+func (*PostgreSQL) paramType() int {
50
+	return paramTypeDollar
51
+}
52
+
53
+func (*PostgreSQL) databaseName(db *sql.DB) (dbName string) {
54
+	db.QueryRow("SELECT current_database()").Scan(&dbName)
55
+	return
56
+}
57
+
58
+func (h *PostgreSQL) getTables(db *sql.DB) ([]string, error) {
59
+	var tables []string
60
+
61
+	sql := `
62
+SELECT table_name
63
+FROM information_schema.tables
64
+WHERE table_schema = 'public'
65
+  AND table_type = 'BASE TABLE';
66
+`
67
+	rows, err := db.Query(sql)
68
+	if err != nil {
69
+		return nil, err
70
+	}
71
+
72
+	defer rows.Close()
73
+	for rows.Next() {
74
+		var table string
75
+		rows.Scan(&table)
76
+		tables = append(tables, table)
77
+	}
78
+	return tables, nil
79
+}
80
+
81
+func (h *PostgreSQL) getSequences(db *sql.DB) ([]string, error) {
82
+	var sequences []string
83
+
84
+	sql := "SELECT relname FROM pg_class WHERE relkind = 'S'"
85
+	rows, err := db.Query(sql)
86
+	if err != nil {
87
+		return nil, err
88
+	}
89
+
90
+	defer rows.Close()
91
+	for rows.Next() {
92
+		var sequence string
93
+		if err = rows.Scan(&sequence); err != nil {
94
+			return nil, err
95
+		}
96
+		sequences = append(sequences, sequence)
97
+	}
98
+	return sequences, nil
99
+}
100
+
101
+func (*PostgreSQL) getNonDeferrableConstraints(db *sql.DB) ([]pgConstraint, error) {
102
+	var constraints []pgConstraint
103
+
104
+	sql := `
105
+SELECT table_name, constraint_name
106
+FROM information_schema.table_constraints
107
+WHERE constraint_type = 'FOREIGN KEY'
108
+  AND is_deferrable = 'NO'`
109
+	rows, err := db.Query(sql)
110
+	if err != nil {
111
+		return nil, err
112
+	}
113
+
114
+	defer rows.Close()
115
+	for rows.Next() {
116
+		var constraint pgConstraint
117
+		err = rows.Scan(&constraint.tableName, &constraint.constraintName)
118
+		if err != nil {
119
+			return nil, err
120
+		}
121
+		constraints = append(constraints, constraint)
122
+	}
123
+	return constraints, nil
124
+}
125
+
126
+func (h *PostgreSQL) disableTriggers(db *sql.DB, loadFn loadFunction) error {
127
+	defer func() {
128
+		// re-enable triggers after load
129
+		var sql string
130
+		for _, table := range h.tables {
131
+			sql += fmt.Sprintf("ALTER TABLE %s ENABLE TRIGGER ALL;", h.quoteKeyword(table))
132
+		}
133
+		db.Exec(sql)
134
+	}()
135
+
136
+	tx, err := db.Begin()
137
+	if err != nil {
138
+		return err
139
+	}
140
+
141
+	var sql string
142
+	for _, table := range h.tables {
143
+		sql += fmt.Sprintf("ALTER TABLE %s DISABLE TRIGGER ALL;", h.quoteKeyword(table))
144
+	}
145
+	if _, err = tx.Exec(sql); err != nil {
146
+		return err
147
+	}
148
+
149
+	if err = loadFn(tx); err != nil {
150
+		tx.Rollback()
151
+		return err
152
+	}
153
+
154
+	return tx.Commit()
155
+}
156
+
157
+func (h *PostgreSQL) makeConstraintsDeferrable(db *sql.DB, loadFn loadFunction) error {
158
+	defer func() {
159
+		// ensure constraint being not deferrable again after load
160
+		var sql string
161
+		for _, constraint := range h.nonDeferrableConstraints {
162
+			sql += fmt.Sprintf("ALTER TABLE %s ALTER CONSTRAINT %s NOT DEFERRABLE;", h.quoteKeyword(constraint.tableName), h.quoteKeyword(constraint.constraintName))
163
+		}
164
+		db.Exec(sql)
165
+	}()
166
+
167
+	var sql string
168
+	for _, constraint := range h.nonDeferrableConstraints {
169
+		sql += fmt.Sprintf("ALTER TABLE %s ALTER CONSTRAINT %s DEFERRABLE;", h.quoteKeyword(constraint.tableName), h.quoteKeyword(constraint.constraintName))
170
+	}
171
+	if _, err := db.Exec(sql); err != nil {
172
+		return err
173
+	}
174
+
175
+	tx, err := db.Begin()
176
+	if err != nil {
177
+		return err
178
+	}
179
+
180
+	if _, err = tx.Exec("SET CONSTRAINTS ALL DEFERRED"); err != nil {
181
+		return nil
182
+	}
183
+
184
+	if err = loadFn(tx); err != nil {
185
+		tx.Rollback()
186
+		return err
187
+	}
188
+
189
+	return tx.Commit()
190
+}
191
+
192
+func (h *PostgreSQL) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) error {
193
+	// ensure sequences being reset after load
194
+	defer h.resetSequences(db)
195
+
196
+	if h.UseAlterConstraint {
197
+		return h.makeConstraintsDeferrable(db, loadFn)
198
+	} else {
199
+		return h.disableTriggers(db, loadFn)
200
+	}
201
+}
202
+
203
+func (h *PostgreSQL) resetSequences(db *sql.DB) error {
204
+	for _, sequence := range h.sequences {
205
+		_, err := db.Exec(fmt.Sprintf("SELECT SETVAL('%s', %d)", sequence, resetSequencesTo))
206
+		if err != nil {
207
+			return err
208
+		}
209
+	}
210
+	return nil
211
+}

+ 40 - 0
vendor/gopkg.in/testfixtures.v2/sqlite.go

@@ -0,0 +1,40 @@
1
+package testfixtures
2
+
3
+import (
4
+	"database/sql"
5
+	"path/filepath"
6
+)
7
+
8
+// SQLite is the SQLite Helper for this package
9
+type SQLite struct {
10
+	baseHelper
11
+}
12
+
13
+func (*SQLite) paramType() int {
14
+	return paramTypeQuestion
15
+}
16
+
17
+func (*SQLite) databaseName(db *sql.DB) (dbName string) {
18
+	var seq int
19
+	var main string
20
+	db.QueryRow("PRAGMA database_list").Scan(&seq, &main, &dbName)
21
+	dbName = filepath.Base(dbName)
22
+	return
23
+}
24
+
25
+func (*SQLite) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) error {
26
+	tx, err := db.Begin()
27
+	if err != nil {
28
+		return err
29
+	}
30
+
31
+	if _, err = tx.Exec("PRAGMA defer_foreign_keys = ON"); err != nil {
32
+		return err
33
+	}
34
+
35
+	if err = loadFn(tx); err != nil {
36
+		return err
37
+	}
38
+
39
+	return tx.Commit()
40
+}

+ 110 - 0
vendor/gopkg.in/testfixtures.v2/sqlserver.go

@@ -0,0 +1,110 @@
1
+package testfixtures
2
+
3
+import (
4
+	"database/sql"
5
+	"fmt"
6
+)
7
+
8
+// SQLServer is the helper for SQL Server for this package.
9
+// SQL Server >= 2008 is required.
10
+type SQLServer struct {
11
+	baseHelper
12
+
13
+	tables []string
14
+}
15
+
16
+func (h *SQLServer) init(db *sql.DB) error {
17
+	var err error
18
+
19
+	h.tables, err = h.getTables(db)
20
+	if err != nil {
21
+		return err
22
+	}
23
+
24
+	return nil
25
+}
26
+
27
+func (*SQLServer) paramType() int {
28
+	return paramTypeQuestion
29
+}
30
+
31
+func (*SQLServer) quoteKeyword(str string) string {
32
+	return fmt.Sprintf("[%s]", str)
33
+}
34
+
35
+func (*SQLServer) databaseName(db *sql.DB) (dbname string) {
36
+	db.QueryRow("SELECT DB_NAME()").Scan(&dbname)
37
+	return
38
+}
39
+
40
+func (*SQLServer) getTables(db *sql.DB) ([]string, error) {
41
+	rows, err := db.Query("SELECT table_name FROM information_schema.tables")
42
+	if err != nil {
43
+		return nil, err
44
+	}
45
+
46
+	tables := make([]string, 0)
47
+	defer rows.Close()
48
+	for rows.Next() {
49
+		var table string
50
+		rows.Scan(&table)
51
+		tables = append(tables, table)
52
+	}
53
+	return tables, nil
54
+}
55
+
56
+func (*SQLServer) tableHasIdentityColumn(tx *sql.Tx, tableName string) bool {
57
+	sql := `
58
+SELECT COUNT(*)
59
+FROM SYS.IDENTITY_COLUMNS
60
+WHERE OBJECT_NAME(OBJECT_ID) = ?
61
+`
62
+	var count int
63
+	tx.QueryRow(sql, tableName).Scan(&count)
64
+	return count > 0
65
+
66
+}
67
+
68
+func (h *SQLServer) whileInsertOnTable(tx *sql.Tx, tableName string, fn func() error) error {
69
+	if h.tableHasIdentityColumn(tx, tableName) {
70
+		defer tx.Exec(fmt.Sprintf("SET IDENTITY_INSERT %s OFF", h.quoteKeyword(tableName)))
71
+		_, err := tx.Exec(fmt.Sprintf("SET IDENTITY_INSERT %s ON", h.quoteKeyword(tableName)))
72
+		if err != nil {
73
+			return err
74
+		}
75
+	}
76
+	return fn()
77
+}
78
+
79
+func (h *SQLServer) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) error {
80
+	// ensure the triggers are re-enable after all
81
+	defer func() {
82
+		sql := ""
83
+		for _, table := range h.tables {
84
+			sql += fmt.Sprintf("ALTER TABLE %s WITH CHECK CHECK CONSTRAINT ALL;", h.quoteKeyword(table))
85
+		}
86
+		if _, err := db.Exec(sql); err != nil {
87
+			fmt.Printf("Error on re-enabling constraints: %v\n", err)
88
+		}
89
+	}()
90
+
91
+	sql := ""
92
+	for _, table := range h.tables {
93
+		sql += fmt.Sprintf("ALTER TABLE %s NOCHECK CONSTRAINT ALL;", h.quoteKeyword(table))
94
+	}
95
+	if _, err := db.Exec(sql); err != nil {
96
+		return err
97
+	}
98
+
99
+	tx, err := db.Begin()
100
+	if err != nil {
101
+		return err
102
+	}
103
+
104
+	if err = loadFn(tx); err != nil {
105
+		tx.Rollback()
106
+		return err
107
+	}
108
+
109
+	return tx.Commit()
110
+}

+ 279 - 0
vendor/gopkg.in/testfixtures.v2/testfixtures.go

@@ -0,0 +1,279 @@
1
+package testfixtures
2
+
3
+import (
4
+	"database/sql"
5
+	"errors"
6
+	"fmt"
7
+	"io/ioutil"
8
+	"path"
9
+	"path/filepath"
10
+	"regexp"
11
+	"strings"
12
+
13
+	"gopkg.in/yaml.v2"
14
+)
15
+
16
+// Context holds the fixtures to be loaded in the database.
17
+type Context struct {
18
+	db            *sql.DB
19
+	helper        Helper
20
+	fixturesFiles []*fixtureFile
21
+}
22
+
23
+type fixtureFile struct {
24
+	path       string
25
+	fileName   string
26
+	content    []byte
27
+	insertSQLs []insertSQL
28
+}
29
+
30
+type insertSQL struct {
31
+	sql    string
32
+	params []interface{}
33
+}
34
+
35
+var (
36
+	// ErrWrongCastNotAMap is returned when a map is not a map[interface{}]interface{}
37
+	ErrWrongCastNotAMap = errors.New("Could not cast record: not a map[interface{}]interface{}")
38
+
39
+	// ErrFileIsNotSliceOrMap is returned the the fixture file is not a slice or map.
40
+	ErrFileIsNotSliceOrMap = errors.New("The fixture file is not a slice or map")
41
+
42
+	// ErrKeyIsNotString is returned when a record is not of type string
43
+	ErrKeyIsNotString = errors.New("Record map key is not string")
44
+
45
+	// ErrNotTestDatabase is returned when the database name doesn't contains "test"
46
+	ErrNotTestDatabase = errors.New(`Loading aborted because the database name does not contains "test"`)
47
+
48
+	dbnameRegexp = regexp.MustCompile("(?i)test")
49
+)
50
+
51
+// NewFolder craetes a context for all fixtures in a given folder into the database:
52
+//     NewFolder(db, &PostgreSQL{}, "my/fixtures/folder")
53
+func NewFolder(db *sql.DB, helper Helper, folderName string) (*Context, error) {
54
+	fixtures, err := fixturesFromFolder(folderName)
55
+	if err != nil {
56
+		return nil, err
57
+	}
58
+
59
+	c, err := newContext(db, helper, fixtures)
60
+	if err != nil {
61
+		return nil, err
62
+	}
63
+
64
+	return c, nil
65
+}
66
+
67
+// NewFiles craetes a context for all specified fixtures files into database:
68
+//     NewFiles(db, &PostgreSQL{},
69
+//         "fixtures/customers.yml",
70
+//         "fixtures/orders.yml"
71
+//         // add as many files you want
72
+//     )
73
+func NewFiles(db *sql.DB, helper Helper, fileNames ...string) (*Context, error) {
74
+	fixtures, err := fixturesFromFiles(fileNames...)
75
+	if err != nil {
76
+		return nil, err
77
+	}
78
+
79
+	c, err := newContext(db, helper, fixtures)
80
+	if err != nil {
81
+		return nil, err
82
+	}
83
+
84
+	return c, nil
85
+}
86
+
87
+func newContext(db *sql.DB, helper Helper, fixtures []*fixtureFile) (*Context, error) {
88
+	c := &Context{
89
+		db:            db,
90
+		helper:        helper,
91
+		fixturesFiles: fixtures,
92
+	}
93
+
94
+	if err := c.helper.init(c.db); err != nil {
95
+		return nil, err
96
+	}
97
+
98
+	if err := c.buildInsertSQLs(); err != nil {
99
+		return nil, err
100
+	}
101
+
102
+	return c, nil
103
+}
104
+
105
+// Load wipes and after load all fixtures in the database.
106
+//     if err := fixtures.Load(); err != nil {
107
+//         log.Fatal(err)
108
+//     }
109
+func (c *Context) Load() error {
110
+	if !skipDatabaseNameCheck {
111
+		if !dbnameRegexp.MatchString(c.helper.databaseName(c.db)) {
112
+			return ErrNotTestDatabase
113
+		}
114
+	}
115
+
116
+	err := c.helper.disableReferentialIntegrity(c.db, func(tx *sql.Tx) error {
117
+		for _, file := range c.fixturesFiles {
118
+			if err := file.delete(tx, c.helper); err != nil {
119
+				return err
120
+			}
121
+
122
+			err := c.helper.whileInsertOnTable(tx, file.fileNameWithoutExtension(), func() error {
123
+				for _, i := range file.insertSQLs {
124
+					if _, err := tx.Exec(i.sql, i.params...); err != nil {
125
+						return err
126
+					}
127
+				}
128
+				return nil
129
+			})
130
+			if err != nil {
131
+				return err
132
+			}
133
+		}
134
+		return nil
135
+	})
136
+	return err
137
+}
138
+
139
+func (c *Context) buildInsertSQLs() error {
140
+	for _, f := range c.fixturesFiles {
141
+		var records interface{}
142
+		if err := yaml.Unmarshal(f.content, &records); err != nil {
143
+			return err
144
+		}
145
+
146
+		switch records := records.(type) {
147
+		case []interface{}:
148
+			for _, record := range records {
149
+				recordMap, ok := record.(map[interface{}]interface{})
150
+				if !ok {
151
+					return ErrWrongCastNotAMap
152
+				}
153
+
154
+				sql, values, err := f.buildInsertSQL(c.helper, recordMap)
155
+				if err != nil {
156
+					return err
157
+				}
158
+
159
+				f.insertSQLs = append(f.insertSQLs, insertSQL{sql, values})
160
+			}
161
+		case map[interface{}]interface{}:
162
+			for _, record := range records {
163
+				recordMap, ok := record.(map[interface{}]interface{})
164
+				if !ok {
165
+					return ErrWrongCastNotAMap
166
+				}
167
+
168
+				sql, values, err := f.buildInsertSQL(c.helper, recordMap)
169
+				if err != nil {
170
+					return err
171
+				}
172
+
173
+				f.insertSQLs = append(f.insertSQLs, insertSQL{sql, values})
174
+			}
175
+		default:
176
+			return ErrFileIsNotSliceOrMap
177
+		}
178
+	}
179
+
180
+	return nil
181
+}
182
+
183
+func (f *fixtureFile) fileNameWithoutExtension() string {
184
+	return strings.Replace(f.fileName, filepath.Ext(f.fileName), "", 1)
185
+}
186
+
187
+func (f *fixtureFile) delete(tx *sql.Tx, h Helper) error {
188
+	_, err := tx.Exec(fmt.Sprintf("DELETE FROM %s", h.quoteKeyword(f.fileNameWithoutExtension())))
189
+	return err
190
+}
191
+
192
+func (f *fixtureFile) buildInsertSQL(h Helper, record map[interface{}]interface{}) (sqlStr string, values []interface{}, err error) {
193
+	var (
194
+		sqlColumns []string
195
+		sqlValues  []string
196
+		i          = 1
197
+	)
198
+	for key, value := range record {
199
+		keyStr, ok := key.(string)
200
+		if !ok {
201
+			err = ErrKeyIsNotString
202
+			return
203
+		}
204
+
205
+		sqlColumns = append(sqlColumns, h.quoteKeyword(keyStr))
206
+
207
+		switch h.paramType() {
208
+		case paramTypeDollar:
209
+			sqlValues = append(sqlValues, fmt.Sprintf("$%d", i))
210
+		case paramTypeQuestion:
211
+			sqlValues = append(sqlValues, "?")
212
+		case paramTypeColon:
213
+			switch {
214
+			case isDateTime(value):
215
+				sqlValues = append(sqlValues, fmt.Sprintf("to_date(:%d, 'YYYY-MM-DD HH24:MI:SS')", i))
216
+			case isDate(value):
217
+				sqlValues = append(sqlValues, fmt.Sprintf("to_date(:%d, 'YYYY-MM-DD')", i))
218
+			case isTime(value):
219
+				sqlValues = append(sqlValues, fmt.Sprintf("to_date(:%d, 'HH24:MI:SS')", i))
220
+			default:
221
+				sqlValues = append(sqlValues, fmt.Sprintf(":%d", i))
222
+			}
223
+		}
224
+		i++
225
+		values = append(values, value)
226
+	}
227
+
228
+	sqlStr = fmt.Sprintf(
229
+		"INSERT INTO %s (%s) VALUES (%s)",
230
+		h.quoteKeyword(f.fileNameWithoutExtension()),
231
+		strings.Join(sqlColumns, ", "),
232
+		strings.Join(sqlValues, ", "),
233
+	)
234
+	return
235
+}
236
+
237
+func fixturesFromFolder(folderName string) ([]*fixtureFile, error) {
238
+	var files []*fixtureFile
239
+	fileinfos, err := ioutil.ReadDir(folderName)
240
+	if err != nil {
241
+		return nil, err
242
+	}
243
+
244
+	for _, fileinfo := range fileinfos {
245
+		if !fileinfo.IsDir() && filepath.Ext(fileinfo.Name()) == ".yml" {
246
+			fixture := &fixtureFile{
247
+				path:     path.Join(folderName, fileinfo.Name()),
248
+				fileName: fileinfo.Name(),
249
+			}
250
+			fixture.content, err = ioutil.ReadFile(fixture.path)
251
+			if err != nil {
252
+				return nil, err
253
+			}
254
+			files = append(files, fixture)
255
+		}
256
+	}
257
+	return files, nil
258
+}
259
+
260
+func fixturesFromFiles(fileNames ...string) ([]*fixtureFile, error) {
261
+	var (
262
+		fixtureFiles []*fixtureFile
263
+		err          error
264
+	)
265
+
266
+	for _, f := range fileNames {
267
+		fixture := &fixtureFile{
268
+			path:     f,
269
+			fileName: filepath.Base(f),
270
+		}
271
+		fixture.content, err = ioutil.ReadFile(fixture.path)
272
+		if err != nil {
273
+			return nil, err
274
+		}
275
+		fixtureFiles = append(fixtureFiles, fixture)
276
+	}
277
+
278
+	return fixtureFiles, nil
279
+}

+ 36 - 0
vendor/gopkg.in/testfixtures.v2/time.go

@@ -0,0 +1,36 @@
1
+package testfixtures
2
+
3
+import "regexp"
4
+
5
+var (
6
+	regexpDate     = regexp.MustCompile("\\d\\d\\d\\d-\\d\\d-\\d\\d")
7
+	regexpDateTime = regexp.MustCompile("\\d\\d\\d\\d-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d")
8
+	regexpTime     = regexp.MustCompile("\\d\\d:\\d\\d:\\d\\d")
9
+)
10
+
11
+func isDate(value interface{}) bool {
12
+	str, isStr := value.(string)
13
+	if !isStr {
14
+		return false
15
+	}
16
+
17
+	return regexpDate.MatchString(str)
18
+}
19
+
20
+func isDateTime(value interface{}) bool {
21
+	str, isStr := value.(string)
22
+	if !isStr {
23
+		return false
24
+	}
25
+
26
+	return regexpDateTime.MatchString(str)
27
+}
28
+
29
+func isTime(value interface{}) bool {
30
+	str, isStr := value.(string)
31
+	if !isStr {
32
+		return false
33
+	}
34
+
35
+	return regexpTime.MatchString(str)
36
+}

+ 13 - 0
vendor/gopkg.in/yaml.v2/LICENSE

@@ -0,0 +1,13 @@
1
+Copyright 2011-2016 Canonical Ltd.
2
+
3
+Licensed under the Apache License, Version 2.0 (the "License");
4
+you may not use this file except in compliance with the License.
5
+You may obtain a copy of the License at
6
+
7
+    http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+Unless required by applicable law or agreed to in writing, software
10
+distributed under the License is distributed on an "AS IS" BASIS,
11
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+See the License for the specific language governing permissions and
13
+limitations under the License.

+ 31 - 0
vendor/gopkg.in/yaml.v2/LICENSE.libyaml

@@ -0,0 +1,31 @@
1
+The following files were ported to Go from C files of libyaml, and thus
2
+are still covered by their original copyright and license:
3
+
4
+    apic.go
5
+    emitterc.go
6
+    parserc.go
7
+    readerc.go
8
+    scannerc.go
9
+    writerc.go
10
+    yamlh.go
11
+    yamlprivateh.go
12
+
13
+Copyright (c) 2006 Kirill Simonov
14
+
15
+Permission is hereby granted, free of charge, to any person obtaining a copy of
16
+this software and associated documentation files (the "Software"), to deal in
17
+the Software without restriction, including without limitation the rights to
18
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
19
+of the Software, and to permit persons to whom the Software is furnished to do
20
+so, subject to the following conditions:
21
+
22
+The above copyright notice and this permission notice shall be included in all
23
+copies or substantial portions of the Software.
24
+
25
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+SOFTWARE.

+ 131 - 0
vendor/gopkg.in/yaml.v2/README.md

@@ -0,0 +1,131 @@
1
+# YAML support for the Go language
2
+
3
+Introduction
4
+------------
5
+
6
+The yaml package enables Go programs to comfortably encode and decode YAML
7
+values. It was developed within [Canonical](https://www.canonical.com) as
8
+part of the [juju](https://juju.ubuntu.com) project, and is based on a
9
+pure Go port of the well-known [libyaml](http://pyyaml.org/wiki/LibYAML)
10
+C library to parse and generate YAML data quickly and reliably.
11
+
12
+Compatibility
13
+-------------
14
+
15
+The yaml package supports most of YAML 1.1 and 1.2, including support for
16
+anchors, tags, map merging, etc. Multi-document unmarshalling is not yet
17
+implemented, and base-60 floats from YAML 1.1 are purposefully not
18
+supported since they're a poor design and are gone in YAML 1.2.
19
+
20
+Installation and usage
21
+----------------------
22
+
23
+The import path for the package is *gopkg.in/yaml.v2*.
24
+
25
+To install it, run:
26
+
27
+    go get gopkg.in/yaml.v2
28
+
29
+API documentation
30
+-----------------
31
+
32
+If opened in a browser, the import path itself leads to the API documentation:
33
+
34
+  * [https://gopkg.in/yaml.v2](https://gopkg.in/yaml.v2)
35
+
36
+API stability
37
+-------------
38
+
39
+The package API for yaml v2 will remain stable as described in [gopkg.in](https://gopkg.in).
40
+
41
+
42
+License
43
+-------
44
+
45
+The yaml package is licensed under the Apache License 2.0. Please see the LICENSE file for details.
46
+
47
+
48
+Example
49
+-------
50
+
51
+```Go
52
+package main
53
+
54
+import (
55
+        "fmt"
56
+        "log"
57
+
58
+        "gopkg.in/yaml.v2"
59
+)
60
+
61
+var data = `
62
+a: Easy!
63
+b:
64
+  c: 2
65
+  d: [3, 4]
66
+`
67
+
68
+type T struct {
69
+        A string
70
+        B struct {
71
+                RenamedC int   `yaml:"c"`
72
+                D        []int `yaml:",flow"`
73
+        }
74
+}
75
+
76
+func main() {
77
+        t := T{}
78
+    
79
+        err := yaml.Unmarshal([]byte(data), &t)
80
+        if err != nil {
81
+                log.Fatalf("error: %v", err)
82
+        }
83
+        fmt.Printf("--- t:\n%v\n\n", t)
84
+    
85
+        d, err := yaml.Marshal(&t)
86
+        if err != nil {
87
+                log.Fatalf("error: %v", err)
88
+        }
89
+        fmt.Printf("--- t dump:\n%s\n\n", string(d))
90
+    
91
+        m := make(map[interface{}]interface{})
92
+    
93
+        err = yaml.Unmarshal([]byte(data), &m)
94
+        if err != nil {
95
+                log.Fatalf("error: %v", err)
96
+        }
97
+        fmt.Printf("--- m:\n%v\n\n", m)
98
+    
99
+        d, err = yaml.Marshal(&m)
100
+        if err != nil {
101
+                log.Fatalf("error: %v", err)
102
+        }
103
+        fmt.Printf("--- m dump:\n%s\n\n", string(d))
104
+}
105
+```
106
+
107
+This example will generate the following output:
108
+
109
+```
110
+--- t:
111
+{Easy! {2 [3 4]}}
112
+
113
+--- t dump:
114
+a: Easy!
115
+b:
116
+  c: 2
117
+  d: [3, 4]
118
+
119
+
120
+--- m:
121
+map[a:Easy! b:map[c:2 d:[3 4]]]
122
+
123
+--- m dump:
124
+a: Easy!
125
+b:
126
+  c: 2
127
+  d:
128
+  - 3
129
+  - 4
130
+```
131
+

+ 742 - 0
vendor/gopkg.in/yaml.v2/apic.go

@@ -0,0 +1,742 @@
1
+package yaml
2
+
3
+import (
4
+	"io"
5
+	"os"
6
+)
7
+
8
+func yaml_insert_token(parser *yaml_parser_t, pos int, token *yaml_token_t) {
9
+	//fmt.Println("yaml_insert_token", "pos:", pos, "typ:", token.typ, "head:", parser.tokens_head, "len:", len(parser.tokens))
10
+
11
+	// Check if we can move the queue at the beginning of the buffer.
12
+	if parser.tokens_head > 0 && len(parser.tokens) == cap(parser.tokens) {
13
+		if parser.tokens_head != len(parser.tokens) {
14
+			copy(parser.tokens, parser.tokens[parser.tokens_head:])
15
+		}
16
+		parser.tokens = parser.tokens[:len(parser.tokens)-parser.tokens_head]
17
+		parser.tokens_head = 0
18
+	}
19
+	parser.tokens = append(parser.tokens, *token)
20
+	if pos < 0 {
21
+		return
22
+	}