Skip to content

Commit

Permalink
Small things fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
SadikSunbul committed Feb 4, 2025
1 parent a3bf4c9 commit 174e393
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion leveldb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ title: LevelDB

A fast key-value DB using [syndtr/goleveldb](https://github.com/syndtr/goleveldb)

**Note: Requires Go 1.23.1 and above**
**Note: Requires Go 1.21 or later**

### Table of Contents

Expand Down
8 changes: 4 additions & 4 deletions leveldb/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"runtime"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestConfigConfigMaxOpenFiles(t *testing.T) {
cfg := Config{
MaxOpenFiles: 1000,
}
assert.Equal(t, 1000, cfg.MaxOpenFiles)
require.Equal(t, 1000, cfg.MaxOpenFiles)
}

func TestConfigDefaultDarwin(t *testing.T) { // MacOS
cfg := configDefault()
if runtime.GOOS == "darwin" {
assert.Equal(t, 200, cfg.MaxOpenFiles)
require.Equal(t, 200, cfg.MaxOpenFiles)
} else {
assert.Equal(t, 500, cfg.MaxOpenFiles)
require.Equal(t, 500, cfg.MaxOpenFiles)
}
}
2 changes: 1 addition & 1 deletion leveldb/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/gofiber/storage/leveldb

go 1.23.1
go 1.23

require (
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
1 change: 0 additions & 1 deletion leveldb/leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func New(config ...Config) *Storage {

// Get value by key
func (s *Storage) Get(key []byte) ([]byte, error) {

if len(key) <= 0 {
return nil, nil
}
Expand Down
19 changes: 8 additions & 11 deletions leveldb/leveldb_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package leveldb

import (
"fmt"
"os"
"testing"
"time"
Expand Down Expand Up @@ -226,16 +225,15 @@ func Benchmark_Set(b *testing.B) {
_ = removeAllFiles("./fiber.leveldb")
}()

key := []byte("test_key")
value := []byte("test_value")

b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var i int
for pb.Next() {
key := []byte(fmt.Sprintf("key_%d", i))
value := []byte(fmt.Sprintf("value_%d", i))
if err := db.Set(key, value, 0); err != nil {
b.Fatal(err)
}
i++
}
})
}
Expand Down Expand Up @@ -270,18 +268,17 @@ func Benchmark_Delete(b *testing.B) {
_ = removeAllFiles("./fiber.leveldb")
}()

key := "test_key"
if err := db.Set([]byte(key), []byte("test_value"), 0); err != nil {
b.Fatal(err)
}

b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
var i int
for pb.Next() {
key := fmt.Sprintf("key_%d", i)
if err := db.Set([]byte(key), []byte("value"), 0); err != nil {
b.Fatal(err)
}
if err := db.Delete(key); err != nil {
b.Fatal(err)
}
i++
}
})
}

0 comments on commit 174e393

Please sign in to comment.