Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(kv): add unit tests for the helpers functions kv.AssertKeyAtLeas… #19965

Merged
merged 8 commits into from
Apr 10, 2024
89 changes: 89 additions & 0 deletions types/kv/helpers_test.go
Original file line number Diff line number Diff line change
@@ -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