error-pages/internal/pick/strings_slice_test.go

50 lines
1.2 KiB
Go
Raw Normal View History

2021-10-06 17:38:00 +00:00
package pick_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/tarampampam/error-pages/internal/pick"
)
func TestStringsSlice_Pick(t *testing.T) {
t.Run("first", func(t *testing.T) {
for i := uint8(0); i < 100; i++ {
assert.Equal(t, "", pick.NewStringsSlice([]string{}, pick.First).Pick())
}
2021-10-06 17:38:00 +00:00
p := pick.NewStringsSlice([]string{"foo", "bar", "baz"}, pick.First)
2021-10-06 17:38:00 +00:00
for i := uint8(0); i < 100; i++ {
assert.Equal(t, "foo", p.Pick())
}
})
2021-10-06 17:38:00 +00:00
t.Run("random once", func(t *testing.T) {
for i := uint8(0); i < 100; i++ {
assert.Equal(t, "", pick.NewStringsSlice([]string{}, pick.RandomOnce).Pick())
}
2021-10-06 17:38:00 +00:00
var (
p = pick.NewStringsSlice([]string{"foo", "bar", "baz"}, pick.RandomOnce)
picked = p.Pick()
)
2021-10-06 17:38:00 +00:00
for i := uint8(0); i < 100; i++ {
assert.Equal(t, picked, p.Pick())
}
})
2021-10-06 17:38:00 +00:00
t.Run("random every time", func(t *testing.T) {
for i := uint8(0); i < 100; i++ {
assert.Equal(t, "", pick.NewStringsSlice([]string{}, pick.RandomEveryTime).Pick())
2021-10-06 17:38:00 +00:00
}
for i := uint8(0); i < 100; i++ {
p := pick.NewStringsSlice([]string{"foo", "bar", "baz"}, pick.RandomEveryTime)
2021-10-06 17:38:00 +00:00
assert.NotEqual(t, p.Pick(), p.Pick())
}
})
2021-10-06 17:38:00 +00:00
}