forked from cosmos/ibc-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add new ErrKeyNotFound and handle it
- Loading branch information
Showing
3 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package store | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/dgraph-io/badger/v3" | ||
) | ||
|
||
func TestGetErrors(t *testing.T) { | ||
dalcKV := NewInMemoryKVStore() | ||
|
||
tc := []struct { | ||
name string | ||
key []byte | ||
err error | ||
}{ | ||
{"empty key", []byte{}, badger.ErrEmptyKey}, | ||
{"not found key", []byte("missing key"), ErrKeyNotFound}, | ||
} | ||
|
||
for _, tt := range tc { | ||
t.Run(tt.name, func(t *testing.T) { | ||
_, err := dalcKV.Get(tt.key) | ||
if !errors.Is(err, tt.err) { | ||
t.Errorf("Invalid err, got: %v expected %v", err, tt.err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSetErrors(t *testing.T) { | ||
dalcKV := NewInMemoryKVStore() | ||
|
||
tc := []struct { | ||
name string | ||
key []byte | ||
value []byte | ||
err error | ||
}{ | ||
{"empty key", []byte{}, []byte{}, badger.ErrEmptyKey}, | ||
{"invalid key", []byte("!badger!key"), []byte("invalid header"), badger.ErrInvalidKey}, | ||
} | ||
|
||
for _, tt := range tc { | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := dalcKV.Set(tt.key, tt.value) | ||
if !errors.Is(tt.err, err) { | ||
t.Errorf("Invalid err, got: %v expected %v", err, tt.err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestDeleteErrors(t *testing.T) { | ||
dalcKV := NewInMemoryKVStore() | ||
|
||
tc := []struct { | ||
name string | ||
key []byte | ||
err error | ||
}{ | ||
{"empty key", []byte{}, badger.ErrEmptyKey}, | ||
{"invalid key", []byte("!badger!key"), badger.ErrInvalidKey}, | ||
} | ||
|
||
for _, tt := range tc { | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := dalcKV.Delete(tt.key) | ||
if !errors.Is(err, tt.err) { | ||
t.Errorf("Invalid err, got: %v expected %v", err, tt.err) | ||
} | ||
}) | ||
} | ||
} |