本文整理汇总了Golang中github.com/tideland/golib/audit.NewTestingAssertion函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTestingAssertion函数的具体用法?Golang NewTestingAssertion怎么用?Golang NewTestingAssertion使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewTestingAssertion函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestPutGOB
// TestPutGOB tests the PUT command with a GOB payload and result.
func TestPutGOB(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
// Setup the test server.
mux, ts, err := web.StartTestServer()
assert.Nil(err)
defer ts.Close()
err = mux.Register("test", "gob", NewTestHandler("putgob", assert))
assert.Nil(err)
// Perform test requests.
reqData := TestCounterData{"test", 4711}
reqBuf := new(bytes.Buffer)
err = gob.NewEncoder(reqBuf).Encode(reqData)
assert.Nil(err, "GOB encode.")
t.Logf("%q", reqBuf.String())
resp, err := web.DoTestRequest(ts, &web.TestRequest{
Method: "POST",
Path: "/test/gob",
Header: web.TestSettings{"Content-Type": "application/vnd.tideland.gob"},
Body: reqBuf.Bytes(),
})
var respData TestCounterData
err = gob.NewDecoder(bytes.NewBuffer(resp.Body)).Decode(&respData)
assert.Nil(err, "GOB decode.")
assert.Equal(respData.ID, "test", "GOB decoded 'id'.")
assert.Equal(respData.Count, int64(4711), "GOB decoded 'count'.")
}
示例2: TestCleanupNoError
// TestCleanupNoError tests the cleanup of props with
// no errors.
func TestCleanupNoError(t *testing.T) {
assert := audit.NewTestingAssertion(t, false)
cleanups := make(map[string]interface{})
cleanup := func(key string, prop interface{}) error {
cleanups[key] = prop
return nil
}
scn := scene.Start()
err := scn.StoreClean("foo", 4711, cleanup)
assert.Nil(err)
err = scn.StoreClean("bar", "yadda", cleanup)
assert.Nil(err)
foo, err := scn.Dispose("foo")
assert.Nil(err)
assert.Equal(foo, 4711)
err = scn.Stop()
assert.Nil(err)
assert.Length(cleanups, 2)
assert.Equal(cleanups["foo"], 4711)
assert.Equal(cleanups["bar"], "yadda")
}
示例3: TestEnvironmentSubscribersDo
// TestEnvironmentSubscribersDo tests the iteration over
// the subscribers.
func TestEnvironmentSubscribersDo(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
env := cells.NewEnvironment("subscribers-do")
defer env.Stop()
err := env.StartCell("foo", newCollectBehavior())
assert.Nil(err)
err = env.StartCell("bar", newCollectBehavior())
assert.Nil(err)
err = env.StartCell("baz", newCollectBehavior())
assert.Nil(err)
err = env.Subscribe("foo", "bar", "baz")
assert.Nil(err)
err = env.EmitNew("foo", iterateTopic, nil, nil)
assert.Nil(err)
time.Sleep(200 * time.Millisecond)
collected, err := env.Request("bar", cells.ProcessedTopic, nil, nil, cells.DefaultTimeout)
assert.Nil(err)
assert.Length(collected, 1)
assert.Contents(`<topic: "love" / payload: <"default": foo loves bar>>`, collected)
collected, err = env.Request("baz", cells.ProcessedTopic, nil, nil, cells.DefaultTimeout)
assert.Nil(err)
assert.Length(collected, 1)
assert.Contents(`<topic: "love" / payload: <"default": foo loves baz>>`, collected)
}
示例4: TestSimpleInactivityTimeout
// TestSimpleInactivityTimeout tests a simple scene usage
// with inactivity timeout.
func TestSimpleInactivityTimeout(t *testing.T) {
assert := audit.NewTestingAssertion(t, false)
scn := scene.StartLimited(100*time.Millisecond, 0)
err := scn.Store("foo", 4711)
assert.Nil(err)
for i := 0; i < 5; i++ {
foo, err := scn.Fetch("foo")
assert.Nil(err)
assert.Equal(foo, 4711)
time.Sleep(50)
}
time.Sleep(100 * time.Millisecond)
foo, err := scn.Fetch("foo")
assert.True(scene.IsTimeoutError(err))
assert.Nil(foo)
status, err := scn.Status()
assert.True(scene.IsTimeoutError(err))
assert.Equal(status, scene.Over)
err = scn.Stop()
assert.True(scene.IsTimeoutError(err))
}
示例5: TestEarlyFlag
// TestEarlyFlag tests the signaling before a waiting.
func TestEarlyFlag(t *testing.T) {
assert := audit.NewTestingAssertion(t, false)
scn := scene.Start()
err := scn.Flag("foo")
assert.Nil(err)
go func() {
err := scn.WaitFlag("foo")
assert.Nil(err)
err = scn.Store("foo-a", true)
assert.Nil(err)
}()
go func() {
err := scn.WaitFlag("foo")
assert.Nil(err)
err = scn.Store("foo-b", true)
assert.Nil(err)
}()
time.Sleep(100 * time.Millisecond)
fooA, err := scn.Fetch("foo-a")
assert.Nil(err)
assert.Equal(fooA, true)
fooB, err := scn.Fetch("foo-b")
assert.Nil(err)
assert.Equal(fooB, true)
err = scn.Stop()
assert.Nil(err)
}
示例6: TestTimeContainments
// Test time containments.
func TestTimeContainments(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
// Create some test data.
ts := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
years := []int{2008, 2009, 2010}
months := []time.Month{10, 11, 12}
days := []int{10, 11, 12, 13, 14}
hours := []int{20, 21, 22, 23}
minutes := []int{0, 5, 10, 15, 20, 25}
seconds := []int{0, 15, 30, 45}
weekdays := []time.Weekday{time.Monday, time.Tuesday, time.Wednesday}
assert.True(timex.YearInList(ts, years), "Go time in year list.")
assert.True(timex.YearInRange(ts, 2005, 2015), "Go time in year range.")
assert.True(timex.MonthInList(ts, months), "Go time in month list.")
assert.True(timex.MonthInRange(ts, 7, 12), "Go time in month range.")
assert.True(timex.DayInList(ts, days), "Go time in day list.")
assert.True(timex.DayInRange(ts, 5, 15), "Go time in day range .")
assert.True(timex.HourInList(ts, hours), "Go time in hour list.")
assert.True(timex.HourInRange(ts, 20, 31), "Go time in hour range .")
assert.True(timex.MinuteInList(ts, minutes), "Go time in minute list.")
assert.True(timex.MinuteInRange(ts, 0, 5), "Go time in minute range .")
assert.True(timex.SecondInList(ts, seconds), "Go time in second list.")
assert.True(timex.SecondInRange(ts, 0, 5), "Go time in second range .")
assert.True(timex.WeekdayInList(ts, weekdays), "Go time in weekday list.")
assert.True(timex.WeekdayInRange(ts, time.Monday, time.Friday), "Go time in weekday range .")
}
示例7: TestRingBufferPop
// TestRingBufferPop tests the popping of values.
func TestRingBufferPop(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
rb := collections.NewRingBuffer(10)
assert.Equal(rb.Cap(), 10)
assert.Length(rb, 0)
rb.Push(1, "alpha", nil, true)
assert.Length(rb, 4)
assert.Equal(rb.String(), "[1]->[alpha]->[<nil>]->[true]")
tests := []struct {
value interface{}
ok bool
length int
}{
{1, true, 3},
{"alpha", true, 2},
{nil, true, 1},
{true, true, 0},
{nil, false, 0},
}
for _, test := range tests {
v, ok := rb.Pop()
assert.Equal(v, test.value)
assert.Equal(ok, test.ok)
assert.Length(rb, test.length)
}
rb.Push(2, "beta")
assert.Equal(rb.Cap(), 10)
assert.Length(rb, 2)
}
示例8: TestSScan
func TestSScan(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
conn, restore := connectDatabase(assert)
defer restore()
for i := 97; i < 123; i++ {
for j := 97; j < 123; j++ {
value := string([]byte{byte(i), byte(j)})
conn.Do("sadd", "scan-set", value)
}
}
cursor, result, err := conn.DoScan("sscan", "scan-set", 0, "match", "*", "count", 5)
assert.Nil(err)
assert.True(cursor != 0)
assert.True(result.Len() > 0)
loopCursor := 0
loopCount := 0
valueCount := 0
for {
cursor, result, err := conn.DoScan("sscan", "scan-set", loopCursor, "match", "*", "count", 5)
assert.Nil(err)
loopCount += 1
valueCount += result.Len()
if cursor == 0 {
break
}
loopCursor = cursor
}
assert.True(loopCount > 1)
assert.Equal(valueCount, 26*26)
}
示例9: TestTreeDo
// TestTreeDo tests the iteration over the tree nodes.
func TestTreeDo(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
tree := collections.NewTree("root", true)
err := tree.At("root").Add("alpha")
assert.Nil(err)
err = tree.At("root").Add("bravo")
assert.Nil(err)
err = tree.At("root", "bravo").Add("foo")
assert.Nil(err)
err = tree.At("root", "bravo").Add("bar")
assert.Nil(err)
err = tree.At("root").Add("bravo")
assert.Nil(err)
err = tree.At("root").Add("charlie")
assert.Nil(err)
err = tree.Create("root", "delta", 1).Add(true)
assert.Nil(err)
err = tree.Create("root", "delta", 2).Add(false)
assert.Nil(err)
// Test iteration.
var values []interface{}
err = tree.DoAll(func(v interface{}) error {
values = append(values, v)
return nil
})
assert.Nil(err)
assert.Length(values, 12)
err = tree.DoAll(func(v interface{}) error {
return errors.New("ouch")
})
assert.ErrorMatch(err, ".* cannot perform function on all nodes: ouch")
}
示例10: TestAsFloat64
// TestAsFloat64 checks the access of float64 values.
func TestAsFloat64(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
maxFloat64S := strconv.FormatFloat(math.MaxFloat64, 'e', -1, 64)
minFloat64S := strconv.FormatFloat(-1*math.MaxFloat64, 'e', -1, 64)
d := stringex.NewDefaulter("AsFloat4", true)
tests := []struct {
v valuer
dv float64
expected float64
}{
{valuer{"0.0", false}, 0.0, 0.0},
{valuer{"1.0", false}, 0.0, 1.0},
{valuer{"-1.0", false}, 0.0, -1.0},
{valuer{maxFloat64S, false}, 0.0, math.MaxFloat64},
{valuer{minFloat64S, false}, 0.0, math.MaxFloat64 * -1.0},
{valuer{"9e+999", false}, 1.0, 1.0},
{valuer{"-9e+999", false}, 1.0, 1.0},
{valuer{"one.two", false}, 1.0, 1.0},
{valuer{"1.0", true}, 2.0, 2.0},
{valuer{"-1.0", true}, -2.0, -2.0},
}
for i, test := range tests {
assert.Logf("test %v %d: %v and default %v", d, i, test.v, test.dv)
bv := d.AsFloat64(test.v, test.dv)
assert.Equal(bv, test.expected)
}
}
示例11: TestAsStringMap
// TestAsStringMap checks the access of string map values.
func TestAsStringMap(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
d := stringex.NewDefaulter("AsStringMap", true)
tests := []struct {
v valuer
rsep string
kvsep string
dv map[string]string
expected map[string]string
}{
{valuer{"a:1/b:2", false}, "/", ":", map[string]string{"a": "1"}, map[string]string{"a": "1", "b": "2"}},
{valuer{"a:1/b:2", true}, "/", ":", map[string]string{"a": "1"}, map[string]string{"a": "1"}},
{valuer{"a:1/b:2", false}, "/", ":", nil, map[string]string{"a": "1", "b": "2"}},
{valuer{"a:1/b:2", true}, "/", ":", nil, nil},
{valuer{"", false}, "/", ":", nil, map[string]string{"": ""}},
{valuer{"", true}, "/", ":", map[string]string{"a": "1"}, map[string]string{"a": "1"}},
{valuer{"a:1/b:2", false}, "|", "=", nil, map[string]string{"a:1/b:2": "a:1/b:2"}},
}
for i, test := range tests {
assert.Logf("test %v %d: %v and default %v", d, i, test.v, test.dv)
sv := d.AsStringMap(test.v, test.rsep, test.kvsep, test.dv)
assert.Equal(sv, test.expected)
}
}
示例12: TestAsInt64
// TestAsInt64 checks the access of int64 values.
func TestAsInt64(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
maxInt64S := strconv.FormatInt(math.MaxInt64, 10)
minInt64S := strconv.FormatInt(math.MinInt64, 10)
d := stringex.NewDefaulter("AsInt64", true)
tests := []struct {
v valuer
dv int64
expected int64
}{
{valuer{"0", false}, 0, 0},
{valuer{"1", false}, 0, 1},
{valuer{"-1", false}, 0, -1},
{valuer{maxInt64S, false}, 0, math.MaxInt64},
{valuer{minInt64S, false}, 0, math.MinInt64},
{valuer{"999999999999999999999", false}, 1, 1},
{valuer{"-999999999999999999999", false}, 1, 1},
{valuer{"one two three", false}, 1, 1},
{valuer{"1", true}, 2, 2},
{valuer{"-1", true}, -2, -2},
}
for i, test := range tests {
assert.Logf("test %v %d: %v and default %v", d, i, test.v, test.dv)
bv := d.AsInt64(test.v, test.dv)
assert.Equal(bv, test.expected)
}
}
示例13: TestAsBool
// TestAsBool checks the access of bool values.
func TestAsBool(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
d := stringex.NewDefaulter("AsBool", true)
tests := []struct {
v valuer
dv bool
expected bool
}{
{valuer{"1", false}, false, true},
{valuer{"t", false}, false, true},
{valuer{"T", false}, false, true},
{valuer{"TRUE", false}, false, true},
{valuer{"true", false}, false, true},
{valuer{"True", false}, false, true},
{valuer{"wahr", false}, true, true},
{valuer{"", true}, true, true},
{valuer{"0", false}, true, false},
{valuer{"f", false}, true, false},
{valuer{"F", false}, true, false},
{valuer{"FALSE", false}, true, false},
{valuer{"false", false}, true, false},
{valuer{"False", false}, true, false},
{valuer{"falsch", false}, false, false},
{valuer{"", true}, false, false},
}
for i, test := range tests {
assert.Logf("test %v %d: %v and default %v", d, i, test.v, test.dv)
bv := d.AsBool(test.v, test.dv)
assert.Equal(bv, test.expected)
}
}
示例14: TestRouterBehavior
// TestRouterBehavior tests the router behavior.
func TestRouterBehavior(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
env := cells.NewEnvironment("router-behavior")
defer env.Stop()
rf := func(emitterID, subscriberID string, event cells.Event) (bool, error) {
ok := strings.Contains(event.Topic(), subscriberID)
return ok, nil
}
env.StartCell("router", behaviors.NewRouterBehavior(rf))
env.StartCell("test-1", behaviors.NewCollectorBehavior(10))
env.StartCell("test-2", behaviors.NewCollectorBehavior(10))
env.StartCell("test-3", behaviors.NewCollectorBehavior(10))
env.StartCell("test-4", behaviors.NewCollectorBehavior(10))
env.StartCell("test-5", behaviors.NewCollectorBehavior(10))
env.Subscribe("router", "test-1", "test-2", "test-3", "test-4", "test-5")
env.EmitNew("router", "test-1:test-2", "a")
env.EmitNew("router", "test-1:test-2:test-3", "b")
env.EmitNew("router", "test-3:test-4:test-5", "c")
time.Sleep(100 * time.Millisecond)
test := func(id string, length int) {
collected, err := env.Request(id, cells.CollectedTopic, nil, cells.DefaultTimeout)
assert.Nil(err)
assert.Length(collected, length)
}
test("test-1", 2)
test("test-2", 2)
test("test-3", 2)
test("test-4", 1)
test("test-5", 1)
}
示例15: TestText
// TestText tests the generation of text.
func TestText(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
gen := audit.NewGenerator(audit.SimpleRand())
for i := 0; i < 10000; i++ {
s := gen.Sentence()
ws := strings.Split(s, " ")
lws := len(ws)
assert.True(2 <= lws && lws <= 15, info("SL: %d", lws))
assert.True('A' <= s[0] && s[0] <= 'Z', info("SUC: %v", s[0]))
}
for i := 0; i < 10000; i++ {
p := gen.Paragraph()
ss := strings.Split(p, ". ")
lss := len(ss)
assert.True(2 <= lss && lss <= 10, info("PL: %d", lss))
for _, s := range ss {
ws := strings.Split(s, " ")
lws := len(ws)
assert.True(2 <= lws && lws <= 15, info("PSL: %d", lws))
assert.True('A' <= s[0] && s[0] <= 'Z', info("PSUC: %v", s[0]))
}
}
}