3
0
corteza/pkg/slice/ints_test.go
Denis Arh af077b0edd Add slice.UInt64s, helper type
Type properly encodes slice of uint64s as JSON array of strings
2022-07-14 11:07:10 +02:00

77 lines
1.1 KiB
Go

package slice
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
func TestHasUint64(t *testing.T) {
cases := []struct {
name string
ss []uint64
s uint64
o bool
}{
{
"empty",
[]uint64{},
42,
false,
},
{
"has not",
[]uint64{42},
12345,
false,
},
{
"has",
[]uint64{42},
42,
true,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
assert.EqualValues(t, HasUint64(c.ss, c.s), c.o)
})
}
}
func TestUInt64s_MarshalJSON(t *testing.T) {
cases := []struct {
name string
ii UInt64s
json string
}{
{
"empty",
UInt64s{},
`[]`,
},
{
"one",
UInt64s{285372959844073660},
`["285372959844073660"]`,
},
{
"two",
UInt64s{285372959844073660, 285372959844073661},
`["285372959844073660","285372959844073661"]`,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
var (
req = require.New(t)
result, err = json.Marshal(c.ii)
)
req.NoError(err)
req.Equal(string(result), c.json)
})
}
}