Skip to content

Commit

Permalink
tests & example
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhuda committed Sep 19, 2021
1 parent b681d61 commit d7a5fe8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 92 deletions.
16 changes: 16 additions & 0 deletions diskv_wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package diskv_wrapper

import (
"github.com/peterbourgon/diskv/v3"
)

func Init(basePath string) *diskv.Diskv {
disk := diskv.New(diskv.Options{
BasePath: basePath,
AdvancedTransform: AdvanceTransform,
InverseTransform: InverseTransform,
CacheSizeMax: 1024 * 1024,
})

return disk
}
3 changes: 2 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (

func main() {
var version, key, value string
var basePath = "example_data"

fmt.Println("::Using Diskv")

currentDisk := diskv_utils.Init()
currentDisk := diskv_utils.Init(basePath)

fmt.Println("::::Existing")
existingVersionUse := diskv_utils.VersionUse(currentDisk)
Expand Down
1 change: 1 addition & 0 deletions tests/disk_test/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1
24 changes: 24 additions & 0 deletions tests/diskv_wrapper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package diskv_wrapper

import (
"testing"

"github.com/mkhuda/diskv_wrapper"
"github.com/peterbourgon/diskv/v3"
)

var (
disk *diskv.Diskv = diskv_wrapper.Init("disk_test")
)

func write_disk_version() {
diskv_wrapper.WriteVersion(disk, "v1")
}

func TestVersionUse(t *testing.T) {
write_disk_version()
existingVersionUse := diskv_wrapper.VersionUse(disk)
if len(existingVersionUse) == 0 {
t.Errorf("Expected has version to use")
}
}
80 changes: 0 additions & 80 deletions wrapper_test.go

This file was deleted.

11 changes: 0 additions & 11 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ import (
"github.com/peterbourgon/diskv/v3"
)

func Init() *diskv.Diskv {
disk := diskv.New(diskv.Options{
BasePath: "localdisk",
AdvancedTransform: AdvanceTransform,
InverseTransform: InverseTransform,
CacheSizeMax: 1024 * 1024,
})

return disk
}

func WriteVersion(d *diskv.Diskv, version string) {
d.WriteString("version", version)
}
Expand Down

0 comments on commit d7a5fe8

Please sign in to comment.