Utils: Add more tests

This commit is contained in:
Noah Hilverling 2019-05-29 14:00:11 +02:00
parent 19f3f65da5
commit 49dc3cb042
3 changed files with 64 additions and 3 deletions

View file

@ -1,7 +1,7 @@
package utils
import (
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/assert"
"testing"
)
@ -30,7 +30,7 @@ func TestChunkKeys(t *testing.T) {
},
}
assert.Equal(t, chunks, want)
assert.Equal(t, want, chunks)
ch = ChunkKeys(make(chan struct{}), keys, 5)
chunks = nil
@ -47,5 +47,5 @@ func TestChunkKeys(t *testing.T) {
},
}
assert.Equal(t, chunks, want)
assert.Equal(t, want, chunks)
}

22
utils/convert_test.go Normal file
View file

@ -0,0 +1,22 @@
package utils
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestChecksum(t *testing.T) {
assert.Equal(t, []byte{
218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9,
}, Checksum("da39a3ee5e6b4b0d3255bfef95601890afd80709"))
assert.Panics(t, func() {
Checksum("x")
})
}
func TestDecodeChecksum(t *testing.T) {
assert.Equal(t, "da39a3ee5e6b4b0d3255bfef95601890afd80709", DecodeChecksum([]byte{
218, 57, 163, 238, 94, 107, 75, 13, 50, 85, 191, 239, 149, 96, 24, 144, 175, 216, 7, 9,
}))
}

39
utils/delta_test.go Normal file
View file

@ -0,0 +1,39 @@
package utils
import (
"github.com/magiconair/properties/assert"
"testing"
)
func TestDelta(t *testing.T) {
old := []string{
"herp",
"merp",
"derp",
"berp",
}
new := []string{
"herp",
"merp",
"cherp",
"lerp",
}
introduced, maintained, dismissed := Delta(new, old)
assert.Equal(t, []string{
"cherp",
"lerp",
}, introduced)
assert.Equal(t, []string{
"herp",
"merp",
}, maintained)
assert.Equal(t, []string{
"derp",
"berp",
}, dismissed)
}