Skip to content

Commit c56152d

Browse files
EmilGeorgievfacundomedicacoderabbitai[bot]tac0turtle
authored
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>
1 parent 4be248e commit c56152d

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

types/kv/helpers_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package kv_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
8+
"github.com/cosmos/cosmos-sdk/types/kv"
9+
)
10+
11+
func TestAssertKeyAtLeastLength(t *testing.T) {
12+
cases := []struct {
13+
name string
14+
key []byte
15+
length int
16+
expectPanic bool
17+
}{
18+
{
19+
name: "Store key length is less than the given length",
20+
key: []byte("hello"),
21+
length: 10,
22+
expectPanic: true,
23+
},
24+
{
25+
name: "Store key length is equal to the given length",
26+
key: []byte("store-key"),
27+
length: 9,
28+
expectPanic: false,
29+
},
30+
{
31+
name: "Store key length is greater than the given length",
32+
key: []byte("unique"),
33+
length: 3,
34+
expectPanic: false,
35+
},
36+
}
37+
38+
for _, tc := range cases {
39+
t.Run(tc.name, func(t *testing.T) {
40+
if tc.expectPanic {
41+
assert.Panics(t, func() {
42+
kv.AssertKeyAtLeastLength(tc.key, tc.length)
43+
})
44+
return
45+
}
46+
kv.AssertKeyAtLeastLength(tc.key, tc.length)
47+
})
48+
}
49+
}
50+
51+
func TestAssertKeyLength(t *testing.T) {
52+
cases := []struct {
53+
name string
54+
key []byte
55+
length int
56+
expectPanic bool
57+
}{
58+
{
59+
name: "Store key length is less than the given length",
60+
key: []byte("hello"),
61+
length: 10,
62+
expectPanic: true,
63+
},
64+
{
65+
name: "Store key length is equal to the given length",
66+
key: []byte("store-key"),
67+
length: 9,
68+
expectPanic: false,
69+
},
70+
{
71+
name: "Store key length is greater than the given length",
72+
key: []byte("unique"),
73+
length: 3,
74+
expectPanic: true,
75+
},
76+
}
77+
78+
for _, tc := range cases {
79+
t.Run(tc.name, func(t *testing.T) {
80+
if tc.expectPanic {
81+
assert.Panics(t, func() {
82+
kv.AssertKeyLength(tc.key, tc.length)
83+
})
84+
return
85+
}
86+
kv.AssertKeyLength(tc.key, tc.length)
87+
})
88+
}
89+
}

0 commit comments

Comments
 (0)