Skip to content

Commit

Permalink
fix typo and use assert.Panic
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilGeorgiev committed Apr 5, 2024
1 parent b4f4edb commit 22d800c
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions types/kv/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ func TestAssertKeyAtLeastLength(t *testing.T) {
expectPanic bool
}{
{
name: "Store key is less then the given length",
name: "Store key length is less than the given length",
key: []byte("hello"),
length: 10,
expectPanic: true,
},
{
name: "Store key is equal to the given length",
name: "Store key length is equal to the given length",
key: []byte("store-key"),
length: 9,
expectPanic: false,
},
{
name: "Store key is greater then the given length",
name: "Store key length is greater than the given length",
key: []byte("unique"),
length: 3,
expectPanic: false,
Expand All @@ -36,14 +36,12 @@ func TestAssertKeyAtLeastLength(t *testing.T) {

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
defer func() {
r := recover()
if tc.expectPanic {
assert.NotNil(t, r)
return
}
assert.Nil(t, r)
}()
if tc.expectPanic {
assert.Panics(t, func() {
kv.AssertKeyAtLeastLength(tc.key, tc.length)
})
return
}
kv.AssertKeyAtLeastLength(tc.key, tc.length)
})
}
Expand All @@ -57,19 +55,19 @@ func TestAssertKeyLength(t *testing.T) {
expectPanic bool
}{
{
name: "Store key is less then the given length",
name: "Store key length is less than the given length",
key: []byte("hello"),
length: 10,
expectPanic: true,
},
{
name: "Store key is equal to the given length",
name: "Store key length is equal to the given length",
key: []byte("store-key"),
length: 9,
expectPanic: false,
},
{
name: "Store key is greater than the given length",
name: "Store key length is greater than the given length",
key: []byte("unique"),
length: 3,
expectPanic: true,
Expand All @@ -78,14 +76,12 @@ func TestAssertKeyLength(t *testing.T) {

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
defer func() {
r := recover()
if tc.expectPanic {
assert.NotNil(t, r)
return
}
assert.Nil(t, r)
}()
if tc.expectPanic {
assert.Panics(t, func() {
kv.AssertKeyLength(tc.key, tc.length)
})
return
}
kv.AssertKeyLength(tc.key, tc.length)
})
}
Expand Down

0 comments on commit 22d800c

Please sign in to comment.