test(kv): add unit tests for the helpers functions kv.AssertKeyAtLeas… (#19965)
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Marko <marko@baricevic.me>
This commit is contained in:
parent
4be248eef6
commit
c56152dfac
89
types/kv/helpers_test.go
Normal file
89
types/kv/helpers_test.go
Normal file
@ -0,0 +1,89 @@
|
||||
package kv_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||
)
|
||||
|
||||
func TestAssertKeyAtLeastLength(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
key []byte
|
||||
length int
|
||||
expectPanic bool
|
||||
}{
|
||||
{
|
||||
name: "Store key length is less than the given length",
|
||||
key: []byte("hello"),
|
||||
length: 10,
|
||||
expectPanic: true,
|
||||
},
|
||||
{
|
||||
name: "Store key length is equal to the given length",
|
||||
key: []byte("store-key"),
|
||||
length: 9,
|
||||
expectPanic: false,
|
||||
},
|
||||
{
|
||||
name: "Store key length is greater than the given length",
|
||||
key: []byte("unique"),
|
||||
length: 3,
|
||||
expectPanic: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if tc.expectPanic {
|
||||
assert.Panics(t, func() {
|
||||
kv.AssertKeyAtLeastLength(tc.key, tc.length)
|
||||
})
|
||||
return
|
||||
}
|
||||
kv.AssertKeyAtLeastLength(tc.key, tc.length)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssertKeyLength(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
key []byte
|
||||
length int
|
||||
expectPanic bool
|
||||
}{
|
||||
{
|
||||
name: "Store key length is less than the given length",
|
||||
key: []byte("hello"),
|
||||
length: 10,
|
||||
expectPanic: true,
|
||||
},
|
||||
{
|
||||
name: "Store key length is equal to the given length",
|
||||
key: []byte("store-key"),
|
||||
length: 9,
|
||||
expectPanic: false,
|
||||
},
|
||||
{
|
||||
name: "Store key length is greater than the given length",
|
||||
key: []byte("unique"),
|
||||
length: 3,
|
||||
expectPanic: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if tc.expectPanic {
|
||||
assert.Panics(t, func() {
|
||||
kv.AssertKeyLength(tc.key, tc.length)
|
||||
})
|
||||
return
|
||||
}
|
||||
kv.AssertKeyLength(tc.key, tc.length)
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user