Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
9ebd95a3
Commit
9ebd95a3
authored
Feb 28, 2015
by
Victor Marmol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating github.com/stretchr/testify godep.
parent
6c5b3901
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
598 additions
and
12 deletions
+598
-12
Godeps.json
Godeps/Godeps.json
+2
-2
assertions.go
...pace/src/github.com/stretchr/testify/assert/assertions.go
+0
-0
assertions_test.go
...src/github.com/stretchr/testify/assert/assertions_test.go
+0
-0
doc.go
.../_workspace/src/github.com/stretchr/testify/assert/doc.go
+79
-3
errors.go
...orkspace/src/github.com/stretchr/testify/assert/errors.go
+1
-1
forward_assertions.go
.../github.com/stretchr/testify/assert/forward_assertions.go
+262
-0
forward_assertions_test.go
...ub.com/stretchr/testify/assert/forward_assertions_test.go
+0
-0
http_assertions.go
...src/github.com/stretchr/testify/assert/http_assertions.go
+157
-0
http_assertions_test.go
...ithub.com/stretchr/testify/assert/http_assertions_test.go
+86
-0
doc.go
...ps/_workspace/src/github.com/stretchr/testify/mock/doc.go
+1
-1
mock.go
...s/_workspace/src/github.com/stretchr/testify/mock/mock.go
+10
-5
mock_test.go
...rkspace/src/github.com/stretchr/testify/mock/mock_test.go
+0
-0
No files found.
Godeps/Godeps.json
View file @
9ebd95a3
...
@@ -266,11 +266,11 @@
...
@@ -266,11 +266,11 @@
},
},
{
{
"ImportPath"
:
"github.com/stretchr/testify/assert"
,
"ImportPath"
:
"github.com/stretchr/testify/assert"
,
"Rev"
:
"
37614ac27794505bf7867ca93aac883cadb6a5f7
"
"Rev"
:
"
e4ec8152c15fc46bd5056ce65997a07c7d415325
"
},
},
{
{
"ImportPath"
:
"github.com/stretchr/testify/mock"
,
"ImportPath"
:
"github.com/stretchr/testify/mock"
,
"Rev"
:
"
37614ac27794505bf7867ca93aac883cadb6a5f7
"
"Rev"
:
"
e4ec8152c15fc46bd5056ce65997a07c7d415325
"
},
},
{
{
"ImportPath"
:
"github.com/vaughan0/go-ini"
,
"ImportPath"
:
"github.com/vaughan0/go-ini"
,
...
...
Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions.go
View file @
9ebd95a3
This diff is collapsed.
Click to expand it.
Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions_test.go
View file @
9ebd95a3
This diff is collapsed.
Click to expand it.
Godeps/_workspace/src/github.com/stretchr/testify/assert/doc.go
View file @
9ebd95a3
...
@@ -17,6 +17,22 @@
...
@@ -17,6 +17,22 @@
//
//
// }
// }
//
//
// if you assert many times, use the below:
//
// import (
// "testing"
// "github.com/stretchr/testify/assert"
// )
//
// func TestSomething(t *testing.T) {
// assert := assert.New(t)
//
// var a string = "Hello"
// var b string = "Hello"
//
// assert.Equal(a, b, "The two words should be the same.")
// }
//
// Assertions
// Assertions
//
//
// Assertions allow you to easily write test code, and are global funcs in the `assert` package.
// Assertions allow you to easily write test code, and are global funcs in the `assert` package.
...
@@ -45,17 +61,21 @@
...
@@ -45,17 +61,21 @@
//
//
// assert.NotEmpty(t, actualObject [, message [, format-args]])
// assert.NotEmpty(t, actualObject [, message [, format-args]])
//
//
// assert.Len(t, actualObject, expectedLength, [, message [, format-args]])
//
// assert.Error(t, errorObject [, message [, format-args]])
// assert.Error(t, errorObject [, message [, format-args]])
//
//
// assert.NoError(t, errorObject [, message [, format-args]])
// assert.NoError(t, errorObject [, message [, format-args]])
//
//
// assert.EqualError(t, theError, errString [, message [, format-args]])
//
// assert.Implements(t, (*MyInterface)(nil), new(MyObject) [,message [, format-args]])
// assert.Implements(t, (*MyInterface)(nil), new(MyObject) [,message [, format-args]])
//
//
// assert.IsType(t, expectedObject, actualObject [, message [, format-args]])
// assert.IsType(t, expectedObject, actualObject [, message [, format-args]])
//
//
// assert.Contains(t, string
, substring
[, message [, format-args]])
// assert.Contains(t, string
OrSlice, substringOrElement
[, message [, format-args]])
//
//
// assert.NotContains(t, string
, substring
[, message [, format-args]])
// assert.NotContains(t, string
OrSlice, substringOrElement
[, message [, format-args]])
//
//
// assert.Panics(t, func(){
// assert.Panics(t, func(){
//
//
...
@@ -70,5 +90,61 @@
...
@@ -70,5 +90,61 @@
// } [, message [, format-args]])
// } [, message [, format-args]])
//
//
// assert.WithinDuration(t, timeA, timeB, deltaTime, [, message [, format-args]])
// assert.WithinDuration(t, timeA, timeB, deltaTime, [, message [, format-args]])
//
// assert.InDelta(t, numA, numB, delta, [, message [, format-args]])
//
// assert.InEpsilon(t, numA, numB, epsilon, [, message [, format-args]])
//
// assert package contains Assertions object. it has assertion methods.
//
// Here is an overview of the assert functions:
// assert.Equal(expected, actual [, message [, format-args])
//
// assert.NotEqual(notExpected, actual [, message [, format-args]])
//
// assert.True(actualBool [, message [, format-args]])
//
// assert.False(actualBool [, message [, format-args]])
//
// assert.Nil(actualObject [, message [, format-args]])
//
// assert.NotNil(actualObject [, message [, format-args]])
//
// assert.Empty(actualObject [, message [, format-args]])
//
// assert.NotEmpty(actualObject [, message [, format-args]])
//
// assert.Len(actualObject, expectedLength, [, message [, format-args]])
//
// assert.Error(errorObject [, message [, format-args]])
//
// assert.NoError(errorObject [, message [, format-args]])
//
// assert.EqualError(theError, errString [, message [, format-args]])
//
// assert.Implements((*MyInterface)(nil), new(MyObject) [,message [, format-args]])
//
// assert.IsType(expectedObject, actualObject [, message [, format-args]])
//
// assert.Contains(stringOrSlice, substringOrElement [, message [, format-args]])
//
// assert.NotContains(stringOrSlice, substringOrElement [, message [, format-args]])
//
// assert.Panics(func(){
//
// // call code that should panic
//
// } [, message [, format-args]])
//
// assert.NotPanics(func(){
//
// // call code that should not panic
//
// } [, message [, format-args]])
//
// assert.WithinDuration(timeA, timeB, deltaTime, [, message [, format-args]])
//
// assert.InDelta(numA, numB, delta, [, message [, format-args]])
//
// assert.InEpsilon(numA, numB, epsilon, [, message [, format-args]])
package
assert
package
assert
Godeps/_workspace/src/github.com/stretchr/testify/assert/errors.go
View file @
9ebd95a3
...
@@ -7,4 +7,4 @@ import (
...
@@ -7,4 +7,4 @@ import (
// AnError is an error instance useful for testing. If the code does not care
// AnError is an error instance useful for testing. If the code does not care
// about error specifics, and only needs to return the error for example, this
// about error specifics, and only needs to return the error for example, this
// error should be used to make the test code more readable.
// error should be used to make the test code more readable.
var
AnError
error
=
errors
.
New
(
"assert.AnError general error for testing.
"
)
var
AnError
=
errors
.
New
(
"assert.AnError general error for testing
"
)
Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions.go
0 → 100644
View file @
9ebd95a3
package
assert
import
"time"
type
Assertions
struct
{
t
TestingT
}
func
New
(
t
TestingT
)
*
Assertions
{
return
&
Assertions
{
t
:
t
,
}
}
// Fail reports a failure through
func
(
a
*
Assertions
)
Fail
(
failureMessage
string
,
msgAndArgs
...
interface
{})
bool
{
return
Fail
(
a
.
t
,
failureMessage
,
msgAndArgs
...
)
}
// Implements asserts that an object is implemented by the specified interface.
//
// assert.Implements((*MyInterface)(nil), new(MyObject), "MyObject")
func
(
a
*
Assertions
)
Implements
(
interfaceObject
interface
{},
object
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
Implements
(
a
.
t
,
interfaceObject
,
object
,
msgAndArgs
...
)
}
// IsType asserts that the specified objects are of the same type.
func
(
a
*
Assertions
)
IsType
(
expectedType
interface
{},
object
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
IsType
(
a
.
t
,
expectedType
,
object
,
msgAndArgs
...
)
}
// Equal asserts that two objects are equal.
//
// assert.Equal(123, 123, "123 and 123 should be equal")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
Equal
(
expected
,
actual
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
Equal
(
a
.
t
,
expected
,
actual
,
msgAndArgs
...
)
}
// EqualValues asserts that two objects are equal or convertable to the same types
// and equal.
//
// assert.EqualValues(uint32(123), int32(123), "123 and 123 should be equal")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
EqualValues
(
expected
,
actual
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
EqualValues
(
a
.
t
,
expected
,
actual
,
msgAndArgs
...
)
}
// Exactly asserts that two objects are equal is value and type.
//
// assert.Exactly(int32(123), int64(123), "123 and 123 should NOT be equal")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
Exactly
(
expected
,
actual
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
Exactly
(
a
.
t
,
expected
,
actual
,
msgAndArgs
...
)
}
// NotNil asserts that the specified object is not nil.
//
// assert.NotNil(err, "err should be something")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
NotNil
(
object
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
NotNil
(
a
.
t
,
object
,
msgAndArgs
...
)
}
// Nil asserts that the specified object is nil.
//
// assert.Nil(err, "err should be nothing")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
Nil
(
object
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
Nil
(
a
.
t
,
object
,
msgAndArgs
...
)
}
// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or a
// slice with len == 0.
//
// assert.Empty(obj)
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
Empty
(
object
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
Empty
(
a
.
t
,
object
,
msgAndArgs
...
)
}
// Empty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or a
// slice with len == 0.
//
// if assert.NotEmpty(obj) {
// assert.Equal("two", obj[1])
// }
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
NotEmpty
(
object
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
NotEmpty
(
a
.
t
,
object
,
msgAndArgs
...
)
}
// Len asserts that the specified object has specific length.
// Len also fails if the object has a type that len() not accept.
//
// assert.Len(mySlice, 3, "The size of slice is not 3")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
Len
(
object
interface
{},
length
int
,
msgAndArgs
...
interface
{})
bool
{
return
Len
(
a
.
t
,
object
,
length
,
msgAndArgs
...
)
}
// True asserts that the specified value is true.
//
// assert.True(myBool, "myBool should be true")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
True
(
value
bool
,
msgAndArgs
...
interface
{})
bool
{
return
True
(
a
.
t
,
value
,
msgAndArgs
...
)
}
// False asserts that the specified value is true.
//
// assert.False(myBool, "myBool should be false")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
False
(
value
bool
,
msgAndArgs
...
interface
{})
bool
{
return
False
(
a
.
t
,
value
,
msgAndArgs
...
)
}
// NotEqual asserts that the specified values are NOT equal.
//
// assert.NotEqual(obj1, obj2, "two objects shouldn't be equal")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
NotEqual
(
expected
,
actual
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
NotEqual
(
a
.
t
,
expected
,
actual
,
msgAndArgs
...
)
}
// Contains asserts that the specified string contains the specified substring.
//
// assert.Contains("Hello World", "World", "But 'Hello World' does contain 'World'")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
Contains
(
s
,
contains
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
Contains
(
a
.
t
,
s
,
contains
,
msgAndArgs
...
)
}
// NotContains asserts that the specified string does NOT contain the specified substring.
//
// assert.NotContains("Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
NotContains
(
s
,
contains
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
NotContains
(
a
.
t
,
s
,
contains
,
msgAndArgs
...
)
}
// Uses a Comparison to assert a complex condition.
func
(
a
*
Assertions
)
Condition
(
comp
Comparison
,
msgAndArgs
...
interface
{})
bool
{
return
Condition
(
a
.
t
,
comp
,
msgAndArgs
...
)
}
// Panics asserts that the code inside the specified PanicTestFunc panics.
//
// assert.Panics(func(){
// GoCrazy()
// }, "Calling GoCrazy() should panic")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
Panics
(
f
PanicTestFunc
,
msgAndArgs
...
interface
{})
bool
{
return
Panics
(
a
.
t
,
f
,
msgAndArgs
...
)
}
// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
//
// assert.NotPanics(func(){
// RemainCalm()
// }, "Calling RemainCalm() should NOT panic")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
NotPanics
(
f
PanicTestFunc
,
msgAndArgs
...
interface
{})
bool
{
return
NotPanics
(
a
.
t
,
f
,
msgAndArgs
...
)
}
// WithinDuration asserts that the two times are within duration delta of each other.
//
// assert.WithinDuration(time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
WithinDuration
(
expected
,
actual
time
.
Time
,
delta
time
.
Duration
,
msgAndArgs
...
interface
{})
bool
{
return
WithinDuration
(
a
.
t
,
expected
,
actual
,
delta
,
msgAndArgs
...
)
}
// InDelta asserts that the two numerals are within delta of each other.
//
// assert.InDelta(t, math.Pi, (22 / 7.0), 0.01)
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
InDelta
(
expected
,
actual
interface
{},
delta
float64
,
msgAndArgs
...
interface
{})
bool
{
return
InDelta
(
a
.
t
,
expected
,
actual
,
delta
,
msgAndArgs
...
)
}
// InEpsilon asserts that expected and actual have a relative error less than epsilon
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
InEpsilon
(
expected
,
actual
interface
{},
epsilon
float64
,
msgAndArgs
...
interface
{})
bool
{
return
InEpsilon
(
a
.
t
,
expected
,
actual
,
epsilon
,
msgAndArgs
...
)
}
// NoError asserts that a function returned no error (i.e. `nil`).
//
// actualObj, err := SomeFunction()
// if assert.NoError(err) {
// assert.Equal(actualObj, expectedObj)
// }
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
NoError
(
theError
error
,
msgAndArgs
...
interface
{})
bool
{
return
NoError
(
a
.
t
,
theError
,
msgAndArgs
...
)
}
// Error asserts that a function returned an error (i.e. not `nil`).
//
// actualObj, err := SomeFunction()
// if assert.Error(err, "An error was expected") {
// assert.Equal(err, expectedError)
// }
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
Error
(
theError
error
,
msgAndArgs
...
interface
{})
bool
{
return
Error
(
a
.
t
,
theError
,
msgAndArgs
...
)
}
// EqualError asserts that a function returned an error (i.e. not `nil`)
// and that it is equal to the provided error.
//
// actualObj, err := SomeFunction()
// if assert.Error(err, "An error was expected") {
// assert.Equal(err, expectedError)
// }
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
EqualError
(
theError
error
,
errString
string
,
msgAndArgs
...
interface
{})
bool
{
return
EqualError
(
a
.
t
,
theError
,
errString
,
msgAndArgs
...
)
}
// Regexp asserts that a specified regexp matches a string.
//
// assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
// assert.Regexp(t, "start...$", "it's not starting")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
Regexp
(
rx
interface
{},
str
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
Regexp
(
a
.
t
,
rx
,
str
,
msgAndArgs
...
)
}
// NotRegexp asserts that a specified regexp does not match a string.
//
// assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
// assert.NotRegexp(t, "^start", "it's not starting")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
NotRegexp
(
rx
interface
{},
str
interface
{},
msgAndArgs
...
interface
{})
bool
{
return
NotRegexp
(
a
.
t
,
rx
,
str
,
msgAndArgs
...
)
}
Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions_test.go
0 → 100644
View file @
9ebd95a3
This diff is collapsed.
Click to expand it.
Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions.go
0 → 100644
View file @
9ebd95a3
package
assert
import
(
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"strings"
)
// httpCode is a helper that returns HTTP code of the response. It returns -1
// if building a new request fails.
func
httpCode
(
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
)
int
{
w
:=
httptest
.
NewRecorder
()
req
,
err
:=
http
.
NewRequest
(
mode
,
url
+
"?"
+
values
.
Encode
(),
nil
)
if
err
!=
nil
{
return
-
1
}
handler
(
w
,
req
)
return
w
.
Code
}
// HTTPSuccess asserts that a specified handler returns a success status code.
//
// assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil)
//
// Returns whether the assertion was successful (true) or not (false).
func
HTTPSuccess
(
t
TestingT
,
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
)
bool
{
code
:=
httpCode
(
handler
,
mode
,
url
,
values
)
if
code
==
-
1
{
return
false
}
return
code
>=
http
.
StatusOK
&&
code
<=
http
.
StatusPartialContent
}
// HTTPRedirect asserts that a specified handler returns a redirect status code.
//
// assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
//
// Returns whether the assertion was successful (true) or not (false).
func
HTTPRedirect
(
t
TestingT
,
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
)
bool
{
code
:=
httpCode
(
handler
,
mode
,
url
,
values
)
if
code
==
-
1
{
return
false
}
return
code
>=
http
.
StatusMultipleChoices
&&
code
<=
http
.
StatusTemporaryRedirect
}
// HTTPError asserts that a specified handler returns an error status code.
//
// assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
//
// Returns whether the assertion was successful (true) or not (false).
func
HTTPError
(
t
TestingT
,
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
)
bool
{
code
:=
httpCode
(
handler
,
mode
,
url
,
values
)
if
code
==
-
1
{
return
false
}
return
code
>=
http
.
StatusBadRequest
}
// HttpBody is a helper that returns HTTP body of the response. It returns
// empty string if building a new request fails.
func
HttpBody
(
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
)
string
{
w
:=
httptest
.
NewRecorder
()
req
,
err
:=
http
.
NewRequest
(
mode
,
url
+
"?"
+
values
.
Encode
(),
nil
)
if
err
!=
nil
{
return
""
}
handler
(
w
,
req
)
return
w
.
Body
.
String
()
}
// HTTPBodyContains asserts that a specified handler returns a
// body that contains a string.
//
// assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
//
// Returns whether the assertion was successful (true) or not (false).
func
HTTPBodyContains
(
t
TestingT
,
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
,
str
interface
{})
bool
{
body
:=
HttpBody
(
handler
,
mode
,
url
,
values
)
contains
:=
strings
.
Contains
(
body
,
fmt
.
Sprint
(
str
))
if
!
contains
{
Fail
(
t
,
fmt
.
Sprintf
(
"Expected response body for
\"
%s
\"
to contain
\"
%s
\"
but found
\"
%s
\"
"
,
url
+
"?"
+
values
.
Encode
(),
str
,
body
))
}
return
contains
}
// HTTPBodyNotContains asserts that a specified handler returns a
// body that does not contain a string.
//
// assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
//
// Returns whether the assertion was successful (true) or not (false).
func
HTTPBodyNotContains
(
t
TestingT
,
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
,
str
interface
{})
bool
{
body
:=
HttpBody
(
handler
,
mode
,
url
,
values
)
contains
:=
strings
.
Contains
(
body
,
fmt
.
Sprint
(
str
))
if
contains
{
Fail
(
t
,
"Expected response body for %s to NOT contain
\"
%s
\"
but found
\"
%s
\"
"
,
url
+
"?"
+
values
.
Encode
(),
str
,
body
)
}
return
!
contains
}
//
// Assertions Wrappers
//
// HTTPSuccess asserts that a specified handler returns a success status code.
//
// assert.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
HTTPSuccess
(
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
)
bool
{
return
HTTPSuccess
(
a
.
t
,
handler
,
mode
,
url
,
values
)
}
// HTTPRedirect asserts that a specified handler returns a redirect status code.
//
// assert.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
HTTPRedirect
(
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
)
bool
{
return
HTTPRedirect
(
a
.
t
,
handler
,
mode
,
url
,
values
)
}
// HTTPError asserts that a specified handler returns an error status code.
//
// assert.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
HTTPError
(
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
)
bool
{
return
HTTPError
(
a
.
t
,
handler
,
mode
,
url
,
values
)
}
// HTTPBodyContains asserts that a specified handler returns a
// body that contains a string.
//
// assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
HTTPBodyContains
(
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
,
str
interface
{})
bool
{
return
HTTPBodyContains
(
a
.
t
,
handler
,
mode
,
url
,
values
,
str
)
}
// HTTPBodyNotContains asserts that a specified handler returns a
// body that does not contain a string.
//
// assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
//
// Returns whether the assertion was successful (true) or not (false).
func
(
a
*
Assertions
)
HTTPBodyNotContains
(
handler
http
.
HandlerFunc
,
mode
,
url
string
,
values
url
.
Values
,
str
interface
{})
bool
{
return
HTTPBodyNotContains
(
a
.
t
,
handler
,
mode
,
url
,
values
,
str
)
}
Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions_test.go
0 → 100644
View file @
9ebd95a3
package
assert
import
(
"fmt"
"net/http"
"net/url"
"testing"
)
func
httpOK
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusOK
)
}
func
httpRedirect
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusTemporaryRedirect
)
}
func
httpError
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
}
func
TestHTTPStatuses
(
t
*
testing
.
T
)
{
assert
:=
New
(
t
)
mockT
:=
new
(
testing
.
T
)
assert
.
Equal
(
HTTPSuccess
(
mockT
,
httpOK
,
"GET"
,
"/"
,
nil
),
true
)
assert
.
Equal
(
HTTPSuccess
(
mockT
,
httpRedirect
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
HTTPSuccess
(
mockT
,
httpError
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
HTTPRedirect
(
mockT
,
httpOK
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
HTTPRedirect
(
mockT
,
httpRedirect
,
"GET"
,
"/"
,
nil
),
true
)
assert
.
Equal
(
HTTPRedirect
(
mockT
,
httpError
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
HTTPError
(
mockT
,
httpOK
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
HTTPError
(
mockT
,
httpRedirect
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
HTTPError
(
mockT
,
httpError
,
"GET"
,
"/"
,
nil
),
true
)
}
func
TestHTTPStatusesWrapper
(
t
*
testing
.
T
)
{
assert
:=
New
(
t
)
mockAssert
:=
New
(
new
(
testing
.
T
))
assert
.
Equal
(
mockAssert
.
HTTPSuccess
(
httpOK
,
"GET"
,
"/"
,
nil
),
true
)
assert
.
Equal
(
mockAssert
.
HTTPSuccess
(
httpRedirect
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
mockAssert
.
HTTPSuccess
(
httpError
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
mockAssert
.
HTTPRedirect
(
httpOK
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
mockAssert
.
HTTPRedirect
(
httpRedirect
,
"GET"
,
"/"
,
nil
),
true
)
assert
.
Equal
(
mockAssert
.
HTTPRedirect
(
httpError
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
mockAssert
.
HTTPError
(
httpOK
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
mockAssert
.
HTTPError
(
httpRedirect
,
"GET"
,
"/"
,
nil
),
false
)
assert
.
Equal
(
mockAssert
.
HTTPError
(
httpError
,
"GET"
,
"/"
,
nil
),
true
)
}
func
httpHelloName
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
name
:=
r
.
FormValue
(
"name"
)
w
.
Write
([]
byte
(
fmt
.
Sprintf
(
"Hello, %s!"
,
name
)))
}
func
TestHttpBody
(
t
*
testing
.
T
)
{
assert
:=
New
(
t
)
mockT
:=
new
(
testing
.
T
)
assert
.
True
(
HTTPBodyContains
(
mockT
,
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"Hello, World!"
))
assert
.
True
(
HTTPBodyContains
(
mockT
,
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"World"
))
assert
.
False
(
HTTPBodyContains
(
mockT
,
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"world"
))
assert
.
False
(
HTTPBodyNotContains
(
mockT
,
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"Hello, World!"
))
assert
.
False
(
HTTPBodyNotContains
(
mockT
,
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"World"
))
assert
.
True
(
HTTPBodyNotContains
(
mockT
,
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"world"
))
}
func
TestHttpBodyWrappers
(
t
*
testing
.
T
)
{
assert
:=
New
(
t
)
mockAssert
:=
New
(
new
(
testing
.
T
))
assert
.
True
(
mockAssert
.
HTTPBodyContains
(
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"Hello, World!"
))
assert
.
True
(
mockAssert
.
HTTPBodyContains
(
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"World"
))
assert
.
False
(
mockAssert
.
HTTPBodyContains
(
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"world"
))
assert
.
False
(
mockAssert
.
HTTPBodyNotContains
(
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"Hello, World!"
))
assert
.
False
(
mockAssert
.
HTTPBodyNotContains
(
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"World"
))
assert
.
True
(
mockAssert
.
HTTPBodyNotContains
(
httpHelloName
,
"GET"
,
"/"
,
url
.
Values
{
"name"
:
[]
string
{
"World"
}},
"world"
))
}
Godeps/_workspace/src/github.com/stretchr/testify/mock/doc.go
View file @
9ebd95a3
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
// the year of their birth or an error, you might write this:
// the year of their birth or an error, you might write this:
//
//
// func (o *MyTestObject) SavePersonDetails(firstname, lastname string, age int) (int, error) {
// func (o *MyTestObject) SavePersonDetails(firstname, lastname string, age int) (int, error) {
// args := o.
Mock.
Called(firstname, lastname, age)
// args := o.Called(firstname, lastname, age)
// return args.Int(0), args.Error(1)
// return args.Int(0), args.Error(1)
// }
// }
//
//
...
...
Godeps/_workspace/src/github.com/stretchr/testify/mock/mock.go
View file @
9ebd95a3
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"reflect"
"reflect"
"runtime"
"runtime"
"strings"
"strings"
"sync"
)
)
// TestingT is an interface wrapper around *testing.T
// TestingT is an interface wrapper around *testing.T
...
@@ -60,6 +61,8 @@ type Mock struct {
...
@@ -60,6 +61,8 @@ type Mock struct {
// TestData holds any data that might be useful for testing. Testify ignores
// TestData holds any data that might be useful for testing. Testify ignores
// this data completely allowing you to do whatever you like with it.
// this data completely allowing you to do whatever you like with it.
testData
objx
.
Map
testData
objx
.
Map
mutex
sync
.
Mutex
}
}
// TestData holds any data that might be useful for testing. Testify ignores
// TestData holds any data that might be useful for testing. Testify ignores
...
@@ -178,6 +181,8 @@ func callString(method string, arguments Arguments, includeArgumentValues bool)
...
@@ -178,6 +181,8 @@ func callString(method string, arguments Arguments, includeArgumentValues bool)
// of arguments to return. Panics if the call is unexpected (i.e. not preceeded by
// of arguments to return. Panics if the call is unexpected (i.e. not preceeded by
// appropriate .On .Return() calls)
// appropriate .On .Return() calls)
func
(
m
*
Mock
)
Called
(
arguments
...
interface
{})
Arguments
{
func
(
m
*
Mock
)
Called
(
arguments
...
interface
{})
Arguments
{
defer
m
.
mutex
.
Unlock
()
m
.
mutex
.
Lock
()
// get the calling function's name
// get the calling function's name
pc
,
_
,
_
,
ok
:=
runtime
.
Caller
(
1
)
pc
,
_
,
_
,
ok
:=
runtime
.
Caller
(
1
)
...
@@ -296,11 +301,11 @@ func (m *Mock) AssertNotCalled(t TestingT, methodName string, arguments ...inter
...
@@ -296,11 +301,11 @@ func (m *Mock) AssertNotCalled(t TestingT, methodName string, arguments ...inter
return
true
return
true
}
}
func
(
m
*
Mock
)
methodWasCalled
(
methodName
string
,
arguments
[]
interface
{})
bool
{
func
(
m
*
Mock
)
methodWasCalled
(
methodName
string
,
expected
[]
interface
{})
bool
{
for
_
,
call
:=
range
m
.
Calls
{
for
_
,
call
:=
range
m
.
Calls
{
if
call
.
Method
==
methodName
{
if
call
.
Method
==
methodName
{
_
,
differences
:=
call
.
Arguments
.
Diff
(
a
rguments
)
_
,
differences
:=
Arguments
(
expected
)
.
Diff
(
call
.
A
rguments
)
if
differences
==
0
{
if
differences
==
0
{
// found the expected call
// found the expected call
...
@@ -473,7 +478,7 @@ func (args Arguments) Int(index int) int {
...
@@ -473,7 +478,7 @@ func (args Arguments) Int(index int) int {
var
s
int
var
s
int
var
ok
bool
var
ok
bool
if
s
,
ok
=
args
.
Get
(
index
)
.
(
int
);
!
ok
{
if
s
,
ok
=
args
.
Get
(
index
)
.
(
int
);
!
ok
{
panic
(
fmt
.
Sprintf
(
"assert: arguments: Int(%d) failed because object wasn't correct type: %
s
"
,
index
,
args
.
Get
(
index
)))
panic
(
fmt
.
Sprintf
(
"assert: arguments: Int(%d) failed because object wasn't correct type: %
v
"
,
index
,
args
.
Get
(
index
)))
}
}
return
s
return
s
}
}
...
@@ -488,7 +493,7 @@ func (args Arguments) Error(index int) error {
...
@@ -488,7 +493,7 @@ func (args Arguments) Error(index int) error {
return
nil
return
nil
}
}
if
s
,
ok
=
obj
.
(
error
);
!
ok
{
if
s
,
ok
=
obj
.
(
error
);
!
ok
{
panic
(
fmt
.
Sprintf
(
"assert: arguments: Error(%d) failed because object wasn't correct type: %
s
"
,
index
,
args
.
Get
(
index
)))
panic
(
fmt
.
Sprintf
(
"assert: arguments: Error(%d) failed because object wasn't correct type: %
v
"
,
index
,
args
.
Get
(
index
)))
}
}
return
s
return
s
}
}
...
@@ -499,7 +504,7 @@ func (args Arguments) Bool(index int) bool {
...
@@ -499,7 +504,7 @@ func (args Arguments) Bool(index int) bool {
var
s
bool
var
s
bool
var
ok
bool
var
ok
bool
if
s
,
ok
=
args
.
Get
(
index
)
.
(
bool
);
!
ok
{
if
s
,
ok
=
args
.
Get
(
index
)
.
(
bool
);
!
ok
{
panic
(
fmt
.
Sprintf
(
"assert: arguments: Bool(%d) failed because object wasn't correct type: %
s
"
,
index
,
args
.
Get
(
index
)))
panic
(
fmt
.
Sprintf
(
"assert: arguments: Bool(%d) failed because object wasn't correct type: %
v
"
,
index
,
args
.
Get
(
index
)))
}
}
return
s
return
s
}
}
Godeps/_workspace/src/github.com/stretchr/testify/mock/mock_test.go
View file @
9ebd95a3
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment