You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.1 KiB
70 lines
1.1 KiB
6 years ago
|
package group
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestGroupGet(t *testing.T) {
|
||
|
count := 0
|
||
|
g := NewGroup(func() interface{} {
|
||
|
count++
|
||
|
return count
|
||
|
})
|
||
|
v := g.Get("/x/internal/dummy/user")
|
||
|
assert.Equal(t, 1, v.(int))
|
||
|
|
||
|
v = g.Get("/x/internal/dummy/avatar")
|
||
|
assert.Equal(t, 2, v.(int))
|
||
|
|
||
|
v = g.Get("/x/internal/dummy/user")
|
||
|
assert.Equal(t, 1, v.(int))
|
||
|
assert.Equal(t, 2, count)
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestGroupReset(t *testing.T) {
|
||
|
g := NewGroup(func() interface{} {
|
||
|
return 1
|
||
|
})
|
||
|
g.Get("/x/internal/dummy/user")
|
||
|
call := false
|
||
|
g.Reset(func() interface{} {
|
||
|
call = true
|
||
|
return 1
|
||
|
})
|
||
|
|
||
|
length := 0
|
||
|
g.objs.Range(func(_, _ interface{}) bool {
|
||
|
length++
|
||
|
return true
|
||
|
})
|
||
|
assert.Equal(t, 0, length)
|
||
|
|
||
|
g.Get("/x/internal/dummy/user")
|
||
|
assert.Equal(t, true, call)
|
||
|
}
|
||
|
|
||
|
func TestGroupClear(t *testing.T) {
|
||
|
g := NewGroup(func() interface{} {
|
||
|
return 1
|
||
|
})
|
||
|
g.Get("/x/internal/dummy/user")
|
||
|
length := 0
|
||
|
g.objs.Range(func(_, _ interface{}) bool {
|
||
|
length++
|
||
|
return true
|
||
|
})
|
||
|
assert.Equal(t, 1, length)
|
||
|
|
||
|
g.Clear()
|
||
|
length = 0
|
||
|
g.objs.Range(func(_, _ interface{}) bool {
|
||
|
length++
|
||
|
return true
|
||
|
})
|
||
|
assert.Equal(t, 0, length)
|
||
|
|
||
|
}
|