From dae01a7afd435f0c374feb493e20cf423a8fc9e5 Mon Sep 17 00:00:00 2001 From: JamesClonk Date: Sat, 27 Jun 2015 10:54:49 +0200 Subject: [PATCH] update Godeps --- Godeps/Godeps.json | 10 +- .../ChimeraCoder/tokenbucket/.gitignore | 4 + .../ChimeraCoder/tokenbucket/LICENSE | 1 + .../ChimeraCoder/tokenbucket/README.md | 1 + .../stretchr/testify/assert/assertions.go | 93 +++++++++++++++++-- .../testify/assert/assertions_test.go | 79 ++++++++++++---- .../github.com/stretchr/testify/assert/doc.go | 10 +- .../testify/assert/forward_assertions.go | 25 +++-- .../testify/assert/forward_assertions_test.go | 27 ++---- .../testify/assert/http_assertions.go | 12 +-- 10 files changed, 196 insertions(+), 66 deletions(-) create mode 100644 Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/.gitignore create mode 120000 Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/LICENSE create mode 120000 Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/README.md diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index e7a0cb3..b36580b 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -5,17 +5,17 @@ "./..." ], "Deps": [ + { + "ImportPath": "github.com/ChimeraCoder/tokenbucket", + "Rev": "c5a927568de7aad8a58127d80bcd36ca4e71e454" + }, { "ImportPath": "github.com/jawher/mow.cli", "Rev": "33e2f99c7beda006afee6bb2e39e31e4ba4e9946" }, { "ImportPath": "github.com/stretchr/testify/assert", - "Rev": "e897f97d666c44ddbc131f4121c2961034b4c1b4" - }, - { - "ImportPath": "github.com/ChimeraCoder/tokenbucket", - "Rev": "c5a927568de7aad8a58127d80bcd36ca4e71e454" + "Rev": "dab07ac62d4905d3e48d17dc549c684ac3b7c15a" } ] } diff --git a/Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/.gitignore b/Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/.gitignore new file mode 100644 index 0000000..5947b74 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/.gitignore @@ -0,0 +1,4 @@ +*.swp +*.swo +*.swn +conf.sh diff --git a/Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/LICENSE b/Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/LICENSE new file mode 120000 index 0000000..d24842f --- /dev/null +++ b/Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/LICENSE @@ -0,0 +1 @@ +COPYING \ No newline at end of file diff --git a/Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/README.md b/Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/README.md new file mode 120000 index 0000000..100b938 --- /dev/null +++ b/Godeps/_workspace/src/github.com/ChimeraCoder/tokenbucket/README.md @@ -0,0 +1 @@ +README \ No newline at end of file diff --git a/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions.go b/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions.go index e7dd9dd..818cd7b 100644 --- a/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions.go +++ b/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "fmt" + "math" "reflect" "regexp" "runtime" @@ -36,6 +37,17 @@ func ObjectsAreEqual(expected, actual interface{}) bool { return true } + return false + +} + +// ObjectsAreEqualValues gets whether two objects are equal, or if their +// values are equal. +func ObjectsAreEqualValues(expected, actual interface{}) bool { + if ObjectsAreEqual(expected, actual) { + return true + } + actualType := reflect.TypeOf(actual) expectedValue := reflect.ValueOf(expected) if expectedValue.Type().ConvertibleTo(actualType) { @@ -45,13 +57,7 @@ func ObjectsAreEqual(expected, actual interface{}) bool { } } - // Last ditch effort - if fmt.Sprintf("%#v", expected) == fmt.Sprintf("%#v", actual) { - return true - } - return false - } /* CallerInfo is necessary because the assert functions use the testing object @@ -198,6 +204,23 @@ func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) } +// EqualValues asserts that two objects are equal or convertable to the same types +// and equal. +// +// assert.EqualValues(t, uint32(123), int32(123), "123 and 123 should be equal") +// +// Returns whether the assertion was successful (true) or not (false). +func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { + + if !ObjectsAreEqualValues(expected, actual) { + return Fail(t, fmt.Sprintf("Not equal: %#v (expected)\n"+ + " != %#v (actual)", expected, actual), msgAndArgs...) + } + + return true + +} + // Exactly asserts that two objects are equal is value and type. // // assert.Exactly(t, int32(123), int64(123), "123 and 123 should NOT be equal") @@ -634,6 +657,14 @@ func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs return Fail(t, fmt.Sprintf("Parameters must be numerical"), msgAndArgs...) } + if math.IsNaN(af) { + return Fail(t, fmt.Sprintf("Actual must not be NaN"), msgAndArgs...) + } + + if math.IsNaN(bf) { + return Fail(t, fmt.Sprintf("Expected %v with delta %v, but was NaN", expected, delta), msgAndArgs...) + } + dt := af - bf if dt < -delta || dt > delta { return Fail(t, fmt.Sprintf("Max difference between %v and %v allowed is %v, but difference was %v", expected, actual, delta, dt), msgAndArgs...) @@ -642,6 +673,27 @@ func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs return true } +// InDeltaSlice is the same as InDelta, except it compares two slices. +func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { + if expected == nil || actual == nil || + reflect.TypeOf(actual).Kind() != reflect.Slice || + reflect.TypeOf(expected).Kind() != reflect.Slice { + return Fail(t, fmt.Sprintf("Parameters must be slice"), msgAndArgs...) + } + + actualSlice := reflect.ValueOf(actual) + expectedSlice := reflect.ValueOf(expected) + + for i := 0; i < actualSlice.Len(); i++ { + result := InDelta(t, actualSlice.Index(i).Interface(), expectedSlice.Index(i).Interface(), delta) + if !result { + return result + } + } + + return true +} + // min(|expected|, |actual|) * epsilon func calcEpsilonDelta(expected, actual interface{}, epsilon float64) float64 { af, aok := toFloat(expected) @@ -676,6 +728,27 @@ func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAnd return InDelta(t, expected, actual, delta, msgAndArgs...) } +// InEpsilonSlice is the same as InEpsilon, except it compares two slices. +func InEpsilonSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { + if expected == nil || actual == nil || + reflect.TypeOf(actual).Kind() != reflect.Slice || + reflect.TypeOf(expected).Kind() != reflect.Slice { + return Fail(t, fmt.Sprintf("Parameters must be slice"), msgAndArgs...) + } + + actualSlice := reflect.ValueOf(actual) + expectedSlice := reflect.ValueOf(expected) + + for i := 0; i < actualSlice.Len(); i++ { + result := InEpsilon(t, actualSlice.Index(i).Interface(), expectedSlice.Index(i).Interface(), delta) + if !result { + return result + } + } + + return true +} + /* Errors */ @@ -751,12 +824,12 @@ func matchRegexp(rx interface{}, str interface{}) bool { // assert.Regexp(t, "start...$", "it's not starting") // // Returns whether the assertion was successful (true) or not (false). -func Regexp(t TestingT, rx interface{}, str interface{}) bool { +func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { match := matchRegexp(rx, str) if !match { - Fail(t, "Expect \"%v\" to match \"%v\"", str, rx) + Fail(t, fmt.Sprintf("Expect \"%v\" to match \"%v\"", str, rx), msgAndArgs...) } return match @@ -768,11 +841,11 @@ func Regexp(t TestingT, rx interface{}, str interface{}) bool { // assert.NotRegexp(t, "^start", "it's not starting") // // Returns whether the assertion was successful (true) or not (false). -func NotRegexp(t TestingT, rx interface{}, str interface{}) bool { +func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { match := matchRegexp(rx, str) if match { - Fail(t, "Expect \"%v\" to NOT match \"%v\"", str, rx) + Fail(t, fmt.Sprintf("Expect \"%v\" to NOT match \"%v\"", str, rx), msgAndArgs...) } return !match diff --git a/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions_test.go b/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions_test.go index db447d3..d859c77 100644 --- a/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/testify/assert/assertions_test.go @@ -2,6 +2,7 @@ package assert import ( "errors" + "math" "regexp" "testing" "time" @@ -43,6 +44,24 @@ func TestObjectsAreEqual(t *testing.T) { if ObjectsAreEqual(map[int]int{5: 10}, map[int]int{10: 20}) { t.Error("objectsAreEqual should return false") } + if ObjectsAreEqual('x', "x") { + t.Error("objectsAreEqual should return false") + } + if ObjectsAreEqual("x", 'x') { + t.Error("objectsAreEqual should return false") + } + if ObjectsAreEqual(0, 0.1) { + t.Error("objectsAreEqual should return false") + } + if ObjectsAreEqual(0.1, 0) { + t.Error("objectsAreEqual should return false") + } + if ObjectsAreEqual(uint32(10), int32(10)) { + t.Error("objectsAreEqual should return false") + } + if !ObjectsAreEqualValues(uint32(10), int32(10)) { + t.Error("ObjectsAreEqualValues should return true") + } } @@ -91,14 +110,10 @@ func TestEqual(t *testing.T) { if !Equal(mockT, nil, nil) { t.Error("Equal should return true") } - if !Equal(mockT, int32(123), int64(123)) { - t.Error("Equal should return true") - } - if !Equal(mockT, int64(123), uint64(123)) { + if !Equal(mockT, int32(123), int32(123)) { t.Error("Equal should return true") } - funcA := func() int { return 42 } - if !Equal(mockT, funcA, funcA) { + if !Equal(mockT, uint64(123), uint64(123)) { t.Error("Equal should return true") } @@ -388,19 +403,6 @@ func TestNotPanics(t *testing.T) { } -func TestEqual_Funcs(t *testing.T) { - - type f func() int - f1 := func() int { return 1 } - f2 := func() int { return 2 } - - f1Copy := f1 - - Equal(t, f1Copy, f1, "Funcs are the same and should be considered equal") - NotEqual(t, f1, f2, "f1 and f2 are different") - -} - func TestNoError(t *testing.T) { mockT := new(testing.T) @@ -651,6 +653,8 @@ func TestInDelta(t *testing.T) { False(t, InDelta(mockT, 1, 2, 0.5), "Expected |1 - 2| <= 0.5 to fail") False(t, InDelta(mockT, 2, 1, 0.5), "Expected |2 - 1| <= 0.5 to fail") False(t, InDelta(mockT, "", nil, 1), "Expected non numerals to fail") + False(t, InDelta(mockT, 42, math.NaN(), 0.01), "Expected NaN for actual to fail") + False(t, InDelta(mockT, math.NaN(), 42, 0.01), "Expected NaN for expected to fail") cases := []struct { a, b interface{} @@ -676,6 +680,27 @@ func TestInDelta(t *testing.T) { } } +func TestInDeltaSlice(t *testing.T) { + mockT := new(testing.T) + + True(t, InDeltaSlice(mockT, + []float64{1.001, 0.999}, + []float64{1, 1}, + 0.1), "{1.001, 0.009} is element-wise close to {1, 1} in delta=0.1") + + True(t, InDeltaSlice(mockT, + []float64{1, 2}, + []float64{0, 3}, + 1), "{1, 2} is element-wise close to {0, 3} in delta=1") + + False(t, InDeltaSlice(mockT, + []float64{1, 2}, + []float64{0, 3}, + 0.1), "{1, 2} is not element-wise close to {0, 3} in delta=0.1") + + False(t, InDeltaSlice(mockT, "", nil, 1), "Expected non numeral slices to fail") +} + func TestInEpsilon(t *testing.T) { mockT := new(testing.T) @@ -715,6 +740,22 @@ func TestInEpsilon(t *testing.T) { } +func TestInEpsilonSlice(t *testing.T) { + mockT := new(testing.T) + + True(t, InEpsilonSlice(mockT, + []float64{2.2, 2.0}, + []float64{2.1, 2.1}, + 0.06), "{2.2, 2.0} is element-wise close to {2.1, 2.1} in espilon=0.06") + + False(t, InEpsilonSlice(mockT, + []float64{2.2, 2.0}, + []float64{2.1, 2.1}, + 0.04), "{2.2, 2.0} is not element-wise close to {2.1, 2.1} in espilon=0.04") + + False(t, InEpsilonSlice(mockT, "", nil, 1), "Expected non numeral slices to fail") +} + func TestRegexp(t *testing.T) { mockT := new(testing.T) diff --git a/Godeps/_workspace/src/github.com/stretchr/testify/assert/doc.go b/Godeps/_workspace/src/github.com/stretchr/testify/assert/doc.go index 1c6de28..f678106 100644 --- a/Godeps/_workspace/src/github.com/stretchr/testify/assert/doc.go +++ b/Godeps/_workspace/src/github.com/stretchr/testify/assert/doc.go @@ -1,4 +1,4 @@ -// A set of comprehensive testing tools for use with the normal Go testing system. +// Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. // // Example Usage // @@ -45,7 +45,9 @@ // // Here is an overview of the assert functions: // -// assert.Equal(t, expected, actual [, message [, format-args]) +// assert.Equal(t, expected, actual [, message [, format-args]]) +// +// assert.EqualValues(t, expected, actual [, message [, format-args]]) // // assert.NotEqual(t, notExpected, actual [, message [, format-args]]) // @@ -98,7 +100,9 @@ // 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.Equal(expected, actual [, message [, format-args]]) +// +// assert.EqualValues(expected, actual [, message [, format-args]]) // // assert.NotEqual(notExpected, actual [, message [, format-args]]) // diff --git a/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions.go b/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions.go index e2866f8..d8d3f53 100644 --- a/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions.go +++ b/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions.go @@ -2,10 +2,13 @@ package assert import "time" +// Assertions provides assertion methods around the +// TestingT interface. type Assertions struct { t TestingT } +// New makes a new Assertions object for the specified TestingT. func New(t TestingT) *Assertions { return &Assertions{ t: t, @@ -38,6 +41,16 @@ func (a *Assertions) Equal(expected, actual interface{}, msgAndArgs ...interface 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") @@ -75,7 +88,7 @@ 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 +// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or a // slice with len == 0. // // if assert.NotEmpty(obj) { @@ -142,7 +155,7 @@ func (a *Assertions) NotContains(s, contains interface{}, msgAndArgs ...interfac return NotContains(a.t, s, contains, msgAndArgs...) } -// Uses a Comparison to assert a complex condition. +// Condition uses a Comparison to assert a complex condition. func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool { return Condition(a.t, comp, msgAndArgs...) } @@ -237,8 +250,8 @@ func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ... // 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{}) bool { - return Regexp(a.t, rx, str) +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. @@ -247,6 +260,6 @@ func (a *Assertions) Regexp(rx interface{}, str interface{}) bool { // 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{}) bool { - return NotRegexp(a.t, rx, str) +func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { + return NotRegexp(a.t, rx, str, msgAndArgs...) } diff --git a/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions_test.go b/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions_test.go index 20cca6e..3df3f39 100644 --- a/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions_test.go +++ b/Godeps/_workspace/src/github.com/stretchr/testify/assert/forward_assertions_test.go @@ -50,6 +50,14 @@ func TestEqualWrapper(t *testing.T) { } } +func TestEqualValuesWrapper(t *testing.T) { + assert := New(new(testing.T)) + + if !assert.EqualValues(uint32(10), int32(10)) { + t.Error("EqualValues should return true") + } +} + func TestNotNilWrapper(t *testing.T) { assert := New(new(testing.T)) @@ -251,27 +259,12 @@ func TestNotPanicsWrapper(t *testing.T) { } -func TestEqualWrapper_Funcs(t *testing.T) { - - assert := New(t) - - type f func() int - var f1 f = func() int { return 1 } - var f2 f = func() int { return 2 } - - var f1_copy f = f1 - - assert.Equal(f1_copy, f1, "Funcs are the same and should be considered equal") - assert.NotEqual(f1, f2, "f1 and f2 are different") - -} - func TestNoErrorWrapper(t *testing.T) { assert := New(t) mockAssert := New(new(testing.T)) // start with a nil error - var err error = nil + var err error assert.True(mockAssert.NoError(err), "NoError should return True for nil arg") @@ -287,7 +280,7 @@ func TestErrorWrapper(t *testing.T) { mockAssert := New(new(testing.T)) // start with a nil error - var err error = nil + var err error assert.False(mockAssert.Error(err), "Error should return False for nil arg") diff --git a/Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions.go b/Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions.go index 0bcb6db..1246e58 100644 --- a/Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions.go +++ b/Godeps/_workspace/src/github.com/stretchr/testify/assert/http_assertions.go @@ -22,7 +22,7 @@ func httpCode(handler http.HandlerFunc, mode, url string, values url.Values) int // HTTPSuccess asserts that a specified handler returns a success status code. // -// assert.HTTPSuccess(t, myHandler, "POST", http://www.google.com", nil) +// 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 { @@ -59,9 +59,9 @@ func HTTPError(t TestingT, handler http.HandlerFunc, mode, url string, values ur return code >= http.StatusBadRequest } -// HttpBody is a helper that returns HTTP body of the response. It returns +// 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 { +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 { @@ -78,7 +78,7 @@ func HttpBody(handler http.HandlerFunc, mode, url string, values url.Values) str // // 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) + body := HTTPBody(handler, mode, url, values) contains := strings.Contains(body, fmt.Sprint(str)) if !contains { @@ -95,7 +95,7 @@ func HTTPBodyContains(t TestingT, handler http.HandlerFunc, mode, url string, va // // 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) + body := HTTPBody(handler, mode, url, values) contains := strings.Contains(body, fmt.Sprint(str)) if contains { @@ -111,7 +111,7 @@ func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, mode, url string, // HTTPSuccess asserts that a specified handler returns a success status code. // -// assert.HTTPSuccess(myHandler, "POST", http://www.google.com", nil) +// 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 {