mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
updated chan_test
This commit is contained in:
@@ -2,75 +2,77 @@ package utils
|
||||
|
||||
import (
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewChanMap(t *testing.T) {
|
||||
mapTest := make(map[string]chan string)
|
||||
mapTest := sync.Map{}
|
||||
chanTest := make(chan string)
|
||||
test := "test"
|
||||
|
||||
Convey("Call NewChanMap to generate ChanMap", t, func() {
|
||||
mapTest[test] = chanTest
|
||||
mapTest.Store("test", chanTest)
|
||||
chanMapTest := ChanMap{mapTest}
|
||||
chanMap := NewChanMap()
|
||||
chanMap.m[test] = chanTest
|
||||
chanMap.m.Store("test", chanTest)
|
||||
|
||||
Convey(test, func() {
|
||||
So(chanMap, ShouldResemble, &chanMapTest)
|
||||
v1, ok := chanMap.m.Load("test")
|
||||
So(ok, ShouldBeTrue)
|
||||
v2, ok := chanMapTest.m.Load("test")
|
||||
So(ok, ShouldBeTrue)
|
||||
So(v1, ShouldResemble, v2)
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestChan(t *testing.T) {
|
||||
mapTest := make(map[string]chan string)
|
||||
mapTest := sync.Map{}
|
||||
chanTest := make(chan string)
|
||||
mapTest["test"] = chanTest
|
||||
mapTest.Store("test", chanTest)
|
||||
chanMapTest := ChanMap{mapTest}
|
||||
|
||||
Convey("Test Chan use exist key", t, func() {
|
||||
ch1 := chanMapTest.Chan(
|
||||
"test")
|
||||
ch1 := chanMapTest.Chan("test")
|
||||
Convey("ch1 should equal chanTest", func() {
|
||||
So(ch1, ShouldEqual, chanTest)
|
||||
})
|
||||
|
||||
})
|
||||
Convey("Test Chan use no-exist key", t, func() {
|
||||
ch2 := chanMapTest.Chan("test2")
|
||||
Convey("ch2 should equal chanMapTest.m[test2]", func() {
|
||||
|
||||
So(chanMapTest.m["test2"], ShouldEqual, ch2)
|
||||
v, ok := chanMapTest.m.Load("test2")
|
||||
So(ok, ShouldBeTrue)
|
||||
So(v, ShouldEqual, ch2)
|
||||
})
|
||||
Convey("Cap of chanMapTest.m[test2] should equal 10", func() {
|
||||
So(10, ShouldEqual, cap(chanMapTest.m["test2"]))
|
||||
So(10, ShouldEqual, cap(ch2))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestChanBlocked(t *testing.T) {
|
||||
mapTest := make(map[string]chan string)
|
||||
mapTest := sync.Map{}
|
||||
chanTest := make(chan string)
|
||||
mapTest["test"] = chanTest
|
||||
mapTest.Store("test", chanTest)
|
||||
chanMapTest := ChanMap{mapTest}
|
||||
|
||||
Convey("Test Chan use exist key", t, func() {
|
||||
ch1 := chanMapTest.ChanBlocked(
|
||||
"test")
|
||||
ch1 := chanMapTest.ChanBlocked("test")
|
||||
Convey("ch1 should equal chanTest", func() {
|
||||
So(ch1, ShouldEqual, chanTest)
|
||||
})
|
||||
|
||||
})
|
||||
Convey("Test Chan use no-exist key", t, func() {
|
||||
ch2 := chanMapTest.ChanBlocked("test2")
|
||||
Convey("ch2 should equal chanMapTest.m[test2]", func() {
|
||||
|
||||
So(chanMapTest.m["test2"], ShouldEqual, ch2)
|
||||
v, ok := chanMapTest.m.Load("test2")
|
||||
So(ok, ShouldBeTrue)
|
||||
So(v, ShouldEqual, ch2)
|
||||
})
|
||||
Convey("Cap of chanMapTest.m[test2] should equal 10", func() {
|
||||
So(0, ShouldEqual, cap(chanMapTest.m["test2"]))
|
||||
So(0, ShouldEqual, cap(ch2))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user