Commit 0d8327f1 authored by Aaron Raddon's avatar Aaron Raddon

Replace assert lib, remove un-needed Assert local

parent 0ab1e8f9
package gou
import (
. "github.com/araddon/gou/goutest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCoerce(t *testing.T) {
......@@ -13,13 +14,13 @@ func TestCoerce(t *testing.T) {
"string": "22",
"stringf": "22.2",
}
Assert(CoerceStringShort(data["int"]) == "4", t, "get int as string")
Assert(CoerceStringShort(data["float"]) == "45.3", t, "get float as string: %v", data["float"])
Assert(CoerceStringShort(data["string"]) == "22", t, "get string as string: %v", data["string"])
Assert(CoerceStringShort(data["stringf"]) == "22.2", t, "get stringf as string: %v", data["stringf"])
assert.True(t, CoerceStringShort(data["int"]) == "4", "get int as string")
assert.True(t, CoerceStringShort(data["float"]) == "45.3", "get float as string: %v", data["float"])
assert.True(t, CoerceStringShort(data["string"]) == "22", "get string as string: %v", data["string"])
assert.True(t, CoerceStringShort(data["stringf"]) == "22.2", "get stringf as string: %v", data["stringf"])
Assert(CoerceIntShort(data["int"]) == 4, t, "get int as int: %v", data["int"])
Assert(CoerceIntShort(data["float"]) == 45, t, "get float as int: %v", data["float"])
Assert(CoerceIntShort(data["string"]) == 22, t, "get string as int: %v", data["string"])
Assert(CoerceIntShort(data["stringf"]) == 22, t, "get stringf as int: %v", data["stringf"])
assert.True(t, CoerceIntShort(data["int"]) == 4, "get int as int: %v", data["int"])
assert.True(t, CoerceIntShort(data["float"]) == 45, "get float as int: %v", data["float"])
assert.True(t, CoerceIntShort(data["string"]) == 22, "get string as int: %v", data["string"])
assert.True(t, CoerceIntShort(data["stringf"]) == 22, "get stringf as int: %v", data["stringf"])
}
package goutest
import (
"fmt"
"testing"
)
// dumb simple assert for testing, printing
// Assert(len(items) == 9, t, "Should be 9 but was %d", len(items))
func Assert(is bool, t *testing.T, args ...interface{}) {
if is == false {
msg := ""
if len(args) > 1 {
switch val := args[0].(type) {
case string:
msg = fmt.Sprintf(val, args[1:len(args)-1])
default:
msg = fmt.Sprint(args)
}
} else if len(args) == 1 {
switch val := args[0].(type) {
case string:
msg = val
default:
msg = fmt.Sprint(val)
}
}
//gou.DoLog(3, gou.ERROR, msg)
t.Fatal(msg)
}
}
This diff is collapsed.
......@@ -4,15 +4,15 @@ import (
"testing"
"time"
"github.com/bmizerany/assert"
"github.com/stretchr/testify/assert"
)
func TestThrottleer(t *testing.T) {
th := NewThrottler(10, 10*time.Second)
for i := 0; i < 10; i++ {
thb, tc := th.Throttle()
assert.Tf(t, thb == false, "Should not throttle %v", i)
assert.Tf(t, tc < 10, "Throttle count should remain below 10 %v", tc)
assert.True(t, thb == false, "Should not throttle %v", i)
assert.True(t, tc < 10, "Throttle count should remain below 10 %v", tc)
time.Sleep(time.Millisecond * 10)
}
......@@ -25,16 +25,16 @@ func TestThrottleer(t *testing.T) {
if thb {
throttled += 1
assert.Tf(t, int(tc) == i-9, "Throttle count should rise %v, i: %d", tc, i)
assert.True(t, int(tc) == i-9, "Throttle count should rise %v, i: %d", tc, i)
}
}
assert.Tf(t, throttled == 10, "Should throttle 10 of 20 requests: %v", throttled)
assert.True(t, throttled == 10, "Should throttle 10 of 20 requests: %v", throttled)
// Now sleep for 1 second so that we should
// no longer be throttled
time.Sleep(time.Second * 2)
thb, _ := th.Throttle()
assert.Tf(t, thb == false, "We should not have been throttled")
assert.True(t, thb == false, "We should not have been throttled")
}
func TestThrottler2(t *testing.T) {
......@@ -61,7 +61,7 @@ func TestThrottler2(t *testing.T) {
throttleMu.Lock()
th = logThrottles[tkey]
tcount := th.ThrottleCount()
assert.Tf(t, tcount == 10, "Should throttle 10 of 20 requests: %v", tcount)
assert.True(t, tcount == 10, "Should throttle 10 of 20 requests: %v", tcount)
throttleMu.Unlock()
// Now sleep for 1 second so that we should
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment