Skip to content

Commit

Permalink
Respond to breaking interface changes (#justprev1thingzzz)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunginnanet committed Jun 22, 2024
1 parent c9da7d1 commit 0ee8b60
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bitcask/bitcask.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (db *DB) Destroy(storeName string) error {
}

// With calls the given underlying bitcask instance.
func (db *DB) With(storeName string) database.Store {
func (db *DB) With(storeName string) database.Filer {
if err := db.init(); err != nil {
panic(err)
}
Expand Down
13 changes: 7 additions & 6 deletions bitcask/bitcask_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
c "git.tcp.direct/kayos/common/entropy"
"github.com/davecgh/go-spew/spew"

"git.tcp.direct/tcp.direct/database"
"git.tcp.direct/tcp.direct/database/kv"
)

Expand Down Expand Up @@ -111,7 +112,7 @@ func Test_Search(t *testing.T) {
db.store["yeet"] = &Store{Bitcask: nil}
t.Run("BasicSearch", func(t *testing.T) {
t.Logf("executing search for %s", needle)
resChan, errChan := db.With(storename).Search(needle)
resChan, errChan := db.With(storename).(database.Store).Search(needle)
var keys = []int{one, two, three, four, five}
var needed = len(keys)

Expand Down Expand Up @@ -146,7 +147,7 @@ func Test_Search(t *testing.T) {
bogus := c.RandStr(55)
t.Logf("executing search for %s", bogus)
var results []kv.KeyValue
resChan, errChan := db.With(storename).Search(bogus)
resChan, errChan := db.With(storename).(database.Store).Search(bogus)
select {
case err := <-errChan:
t.Errorf("failed to search: %s", err.Error())
Expand All @@ -170,7 +171,7 @@ func Test_ValueExists(t *testing.T) {
needles := addJunk(db, storename, c.RNG(100), c.RNG(100), c.RNG(100), c.RNG(100), c.RNG(100), t, true)

for _, ndl := range needles {
k, exists := db.With(storename).ValueExists(ndl)
k, exists := db.With(storename).(database.Store).ValueExists(ndl)
if !exists {
t.Fatalf("[FAIL] store should have contained a value %s somewhere, it did not.", string(ndl))
}
Expand All @@ -189,7 +190,7 @@ func Test_ValueExists(t *testing.T) {
t.Run("ValueShouldNotExist", func(t *testing.T) {
for n := 0; n != 5; n++ {
garbage := c.RandStr(55)
if _, exists := db.With(storename).ValueExists([]byte(garbage)); exists {
if _, exists := db.With(storename).(database.Store).ValueExists([]byte(garbage)); exists {
t.Errorf("[FAIL] store should have not contained value %v, but it did", []byte(garbage))
} else {
t.Logf("[SUCCESS] store succeeded in not having random value %s", garbage)
Expand All @@ -200,7 +201,7 @@ func Test_ValueExists(t *testing.T) {
t.Run("ValueExistNilBitcask", func(t *testing.T) {
db.store["asdb"] = &Store{Bitcask: nil}
garbage := "yeet"
if _, exists := db.With(storename).ValueExists([]byte(garbage)); exists {
if _, exists := db.With(storename).(database.Store).ValueExists([]byte(garbage)); exists {
t.Errorf("[FAIL] store should have not contained value %v, should have been nil", []byte(garbage))
} else {
t.Log("[SUCCESS] store succeeded in being nil")
Expand All @@ -227,7 +228,7 @@ func Test_PrefixScan(t *testing.T) {
t.Logf("added needle with key(value): %s(%s)", combo.Key.String(), combo.Value.String())
}
}
resChan, errChan := db.With(storename).PrefixScan("user:")
resChan, errChan := db.With(storename).(database.Store).PrefixScan("user:")
var results []kv.KeyValue
for keyValue := range resChan {
results = append(results, keyValue)
Expand Down
2 changes: 1 addition & 1 deletion pogreb/pogreb.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (db *DB) Init(storeName string, opts ...any) error {
}

// With calls the given underlying pogreb instance.
func (db *DB) With(storeName string) database.Store {
func (db *DB) With(storeName string) database.Filer {
if err := db.init(); err != nil {
panic(err)
}
Expand Down
13 changes: 7 additions & 6 deletions pogreb/pogreb_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
c "git.tcp.direct/kayos/common/entropy"
"github.com/davecgh/go-spew/spew"

"git.tcp.direct/tcp.direct/database"
"git.tcp.direct/tcp.direct/database/kv"
)

Expand Down Expand Up @@ -111,7 +112,7 @@ func Test_Search(t *testing.T) {
db.store["yeet"] = &Store{DB: nil}
t.Run("BasicSearch", func(t *testing.T) {
t.Logf("executing search for %s", needle)
resChan, errChan := db.With(storename).Search(needle)
resChan, errChan := db.With(storename).(database.Store).Search(needle)
var keys = []int{one, two, three, four, five}
var needed = len(keys)

Expand Down Expand Up @@ -146,7 +147,7 @@ func Test_Search(t *testing.T) {
bogus := c.RandStr(55)
t.Logf("executing search for %s", bogus)
var results []kv.KeyValue
resChan, errChan := db.With(storename).Search(bogus)
resChan, errChan := db.With(storename).(database.Store).Search(bogus)
select {
case err := <-errChan:
t.Errorf("failed to search: %s", err.Error())
Expand All @@ -170,7 +171,7 @@ func Test_ValueExists(t *testing.T) {
needles := addJunk(db, storename, c.RNG(100), c.RNG(100), c.RNG(100), c.RNG(100), c.RNG(100), t, true)

for _, ndl := range needles {
k, exists := db.With(storename).ValueExists(ndl)
k, exists := db.With(storename).(database.Store).ValueExists(ndl)
if !exists {
t.Fatalf("[FAIL] store should have contained a value %s somewhere, it did not.", string(ndl))
}
Expand All @@ -189,7 +190,7 @@ func Test_ValueExists(t *testing.T) {
t.Run("ValueShouldNotExist", func(t *testing.T) {
for n := 0; n != 5; n++ {
garbage := c.RandStr(55)
if _, exists := db.With(storename).ValueExists([]byte(garbage)); exists {
if _, exists := db.With(storename).(database.Store).ValueExists([]byte(garbage)); exists {
t.Errorf("[FAIL] store should have not contained value %v, but it did", []byte(garbage))
} else {
t.Logf("[SUCCESS] store succeeded in not having random value %s", garbage)
Expand All @@ -200,7 +201,7 @@ func Test_ValueExists(t *testing.T) {
t.Run("ValueExistNilBitcask", func(t *testing.T) {
db.store["asdb"] = &Store{DB: nil}
garbage := "yeet"
if _, exists := db.With(storename).ValueExists([]byte(garbage)); exists {
if _, exists := db.With(storename).(database.Store).ValueExists([]byte(garbage)); exists {
t.Errorf("[FAIL] store should have not contained value %v, should have been nil", []byte(garbage))
} else {
t.Log("[SUCCESS] store succeeded in being nil")
Expand All @@ -227,7 +228,7 @@ func Test_PrefixScan(t *testing.T) {
t.Logf("added needle with key(value): %s(%s)", combo.Key.String(), combo.Value.String())
}
}
resChan, errChan := db.With(storename).PrefixScan("user:")
resChan, errChan := db.With(storename).(database.Store).PrefixScan("user:")
var results []kv.KeyValue
for keyValue := range resChan {
results = append(results, keyValue)
Expand Down

0 comments on commit 0ee8b60

Please sign in to comment.