mirror of https://github.com/stretchr/testify.git
Clean up golint warnings
parent
37ec10ac14
commit
5cc789b89e
|
@ -188,7 +188,7 @@ func Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}
|
|||
// Returns whether the assertion was successful (true) or not (false).
|
||||
func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
||||
|
||||
var success bool = true
|
||||
success := true
|
||||
|
||||
if object == nil {
|
||||
success = false
|
||||
|
@ -211,13 +211,14 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
|||
func isNil(object interface{}) bool {
|
||||
if object == nil {
|
||||
return true
|
||||
} else {
|
||||
value := reflect.ValueOf(object)
|
||||
kind := value.Kind()
|
||||
if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
value := reflect.ValueOf(object)
|
||||
kind := value.Kind()
|
||||
if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -257,11 +258,11 @@ func isEmpty(object interface{}) bool {
|
|||
return true
|
||||
} else if object == false {
|
||||
return true
|
||||
} else {
|
||||
for _, v := range zeros {
|
||||
if object == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range zeros {
|
||||
if object == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,7 +305,7 @@ func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
|||
|
||||
}
|
||||
|
||||
// Empty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
||||
// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
||||
// a slice or a channel with len == 0.
|
||||
//
|
||||
// if assert.NotEmpty(t, obj) {
|
||||
|
@ -398,7 +399,7 @@ func NotContains(t TestingT, s, contains string, msgAndArgs ...interface{}) bool
|
|||
|
||||
}
|
||||
|
||||
// Uses a Comparison to assert a complex condition.
|
||||
// Condition uses a Comparison to assert a complex condition.
|
||||
func Condition(t TestingT, comp Comparison, msgAndArgs ...interface{}) bool {
|
||||
result := comp()
|
||||
if !result {
|
||||
|
@ -414,7 +415,7 @@ type PanicTestFunc func()
|
|||
// didPanic returns true if the function passed to it panics. Otherwise, it returns false.
|
||||
func didPanic(f PanicTestFunc) (bool, interface{}) {
|
||||
|
||||
var didPanic bool = false
|
||||
didPanic := false
|
||||
var message interface{}
|
||||
func() {
|
||||
|
||||
|
@ -515,7 +516,8 @@ func Error(t TestingT, err error, msgAndArgs ...interface{}) bool {
|
|||
|
||||
}
|
||||
|
||||
// Error asserts that a function returned an error (i.e. not `nil`).
|
||||
// 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(t, err, "An error was expected") {
|
||||
|
|
|
@ -275,12 +275,12 @@ func TestNotPanics(t *testing.T) {
|
|||
func TestEqual_Funcs(t *testing.T) {
|
||||
|
||||
type f func() int
|
||||
var f1 f = func() int { return 1 }
|
||||
var f2 f = func() int { return 2 }
|
||||
f1 := func() int { return 1 }
|
||||
f2 := func() int { return 2 }
|
||||
|
||||
var f1_copy f = f1
|
||||
f1Copy := f1
|
||||
|
||||
Equal(t, f1_copy, f1, "Funcs are the same and should be considered equal")
|
||||
Equal(t, f1Copy, f1, "Funcs are the same and should be considered equal")
|
||||
NotEqual(t, f1, f2, "f1 and f2 are different")
|
||||
|
||||
}
|
||||
|
@ -290,12 +290,12 @@ func TestNoError(t *testing.T) {
|
|||
mockT := new(testing.T)
|
||||
|
||||
// start with a nil error
|
||||
var err error = nil
|
||||
var err error
|
||||
|
||||
True(t, NoError(mockT, err), "NoError should return True for nil arg")
|
||||
|
||||
// now set an error
|
||||
err = errors.New("Some error")
|
||||
err = errors.New("some error")
|
||||
|
||||
False(t, NoError(mockT, err), "NoError with error should return False")
|
||||
|
||||
|
@ -306,12 +306,12 @@ func TestError(t *testing.T) {
|
|||
mockT := new(testing.T)
|
||||
|
||||
// start with a nil error
|
||||
var err error = nil
|
||||
var err error
|
||||
|
||||
False(t, Error(mockT, err), "Error should return False for nil arg")
|
||||
|
||||
// now set an error
|
||||
err = errors.New("Some error")
|
||||
err = errors.New("some error")
|
||||
|
||||
True(t, Error(mockT, err), "Error with error should return True")
|
||||
|
||||
|
@ -321,22 +321,22 @@ func TestEqualError(t *testing.T) {
|
|||
mockT := new(testing.T)
|
||||
|
||||
// start with a nil error
|
||||
var err error = nil
|
||||
var err error
|
||||
False(t, EqualError(mockT, err, ""),
|
||||
"EqualError should return false for nil arg")
|
||||
|
||||
// now set an error
|
||||
err = errors.New("Some error")
|
||||
err = errors.New("some error")
|
||||
False(t, EqualError(mockT, err, "Not some error"),
|
||||
"EqualError should return false for different error string")
|
||||
True(t, EqualError(mockT, err, "Some error"),
|
||||
True(t, EqualError(mockT, err, "some error"),
|
||||
"EqualError should return true")
|
||||
}
|
||||
|
||||
func Test_isEmpty(t *testing.T) {
|
||||
|
||||
ch_with_value := make(chan struct{}, 1)
|
||||
ch_with_value <- struct{}{}
|
||||
chWithValue := make(chan struct{}, 1)
|
||||
chWithValue <- struct{}{}
|
||||
|
||||
True(t, isEmpty(""))
|
||||
True(t, isEmpty(nil))
|
||||
|
@ -354,15 +354,15 @@ func Test_isEmpty(t *testing.T) {
|
|||
False(t, isEmpty(1))
|
||||
False(t, isEmpty(true))
|
||||
False(t, isEmpty(map[string]string{"Hello": "World"}))
|
||||
False(t, isEmpty(ch_with_value))
|
||||
False(t, isEmpty(chWithValue))
|
||||
|
||||
}
|
||||
|
||||
func TestEmpty(t *testing.T) {
|
||||
|
||||
mockT := new(testing.T)
|
||||
ch_with_value := make(chan struct{}, 1)
|
||||
ch_with_value <- struct{}{}
|
||||
chWithValue := make(chan struct{}, 1)
|
||||
chWithValue <- struct{}{}
|
||||
|
||||
True(t, Empty(mockT, ""), "Empty string is empty")
|
||||
True(t, Empty(mockT, nil), "Nil is empty")
|
||||
|
@ -376,14 +376,14 @@ func TestEmpty(t *testing.T) {
|
|||
False(t, Empty(mockT, []string{"something"}), "Non empty string array is not empty")
|
||||
False(t, Empty(mockT, 1), "Non-zero int value is not empty")
|
||||
False(t, Empty(mockT, true), "True value is not empty")
|
||||
False(t, Empty(mockT, ch_with_value), "Channel with values is not empty")
|
||||
False(t, Empty(mockT, chWithValue), "Channel with values is not empty")
|
||||
}
|
||||
|
||||
func TestNotEmpty(t *testing.T) {
|
||||
|
||||
mockT := new(testing.T)
|
||||
ch_with_value := make(chan struct{}, 1)
|
||||
ch_with_value <- struct{}{}
|
||||
chWithValue := make(chan struct{}, 1)
|
||||
chWithValue <- struct{}{}
|
||||
|
||||
False(t, NotEmpty(mockT, ""), "Empty string is empty")
|
||||
False(t, NotEmpty(mockT, nil), "Nil is empty")
|
||||
|
@ -397,7 +397,7 @@ func TestNotEmpty(t *testing.T) {
|
|||
True(t, NotEmpty(mockT, []string{"something"}), "Non empty string array is not empty")
|
||||
True(t, NotEmpty(mockT, 1), "Non-zero int value is not empty")
|
||||
True(t, NotEmpty(mockT, true), "True value is not empty")
|
||||
True(t, NotEmpty(mockT, ch_with_value), "Channel with values is not empty")
|
||||
True(t, NotEmpty(mockT, chWithValue), "Channel with values is not empty")
|
||||
}
|
||||
|
||||
func TestWithinDuration(t *testing.T) {
|
||||
|
|
|
@ -7,4 +7,4 @@ import (
|
|||
// 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
|
||||
// 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")
|
||||
|
|
Loading…
Reference in New Issue