From 105ab5495ece10fccc2b02101026c8482a4059a1 Mon Sep 17 00:00:00 2001 From: Tim Shannon Date: Tue, 13 Oct 2020 12:08:53 -0500 Subject: [PATCH 1/3] Starting on BadgerV2 Current plan is to match what Badger did, and instead of creating a new folder for v2, simply tag the main version v2, and no longer support v1 with updates. --- go.mod | 1 + go.sum | 25 +++++++++++++++++++++++++ store.go | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7088274..40f4ebd 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/timshannon/badgerhold require ( github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect github.com/dgraph-io/badger v1.6.0 + github.com/dgraph-io/badger/v2 v2.2007.2 ) go 1.13 diff --git a/go.sum b/go.sum index cb98f89..2f4aae8 100644 --- a/go.sum +++ b/go.sum @@ -3,7 +3,13 @@ github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOv github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 h1:cTp8I5+VIoKjsnZuH8vjyaysT/ses3EvZeaV/1UkF2M= github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM= +github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= +github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -13,6 +19,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgraph-io/badger v1.6.0 h1:DshxFxZWXUcO0xX476VJC07Xsr6ZCBVRHKZ93Oh7Evo= github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= +github.com/dgraph-io/badger/v2 v2.2007.2 h1:EjjK0KqwaFMlPin1ajhP943VPENHJdEz1KLIegjaI3k= +github.com/dgraph-io/badger/v2 v2.2007.2/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= +github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de h1:t0UHb5vdojIDUqktM6+xJAfScFBsVpXZmqC9dsgJmeA= +github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= @@ -20,8 +30,15 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= @@ -31,6 +48,9 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= @@ -42,6 +62,8 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -54,4 +76,7 @@ golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSF golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/store.go b/store.go index be1e701..a5baa3a 100644 --- a/store.go +++ b/store.go @@ -9,7 +9,7 @@ import ( "strings" "sync" - "github.com/dgraph-io/badger" + "github.com/dgraph-io/badger/v2" ) const ( From 4bc13372df1bf6ecb06ae0a77396c51e0922d35b Mon Sep 17 00:00:00 2001 From: Tim Shannon Date: Tue, 13 Oct 2020 12:20:26 -0500 Subject: [PATCH 2/3] Updated to v2 paths --- aggregate.go | 2 +- aggregate_test.go | 2 +- bench_test.go | 4 ++-- compare_test.go | 2 +- delete.go | 2 +- delete_test.go | 4 ++-- example_test.go | 4 ++-- find_test.go | 2 +- get.go | 2 +- get_test.go | 2 +- go.mod | 2 +- index.go | 2 +- nested_structs_test.go | 2 +- put.go | 2 +- put_test.go | 4 ++-- query.go | 2 +- sort_test.go | 2 +- store_test.go | 2 +- 18 files changed, 22 insertions(+), 22 deletions(-) diff --git a/aggregate.go b/aggregate.go index dae88d1..8919ef9 100644 --- a/aggregate.go +++ b/aggregate.go @@ -9,7 +9,7 @@ import ( "reflect" "sort" - "github.com/dgraph-io/badger" + "github.com/dgraph-io/badger/v2" ) // AggregateResult allows you to access the results of an aggregate query diff --git a/aggregate_test.go b/aggregate_test.go index dd006f7..f438fde 100644 --- a/aggregate_test.go +++ b/aggregate_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/timshannon/badgerhold" + "github.com/timshannon/badgerhold/v2" ) func TestFindAggregateGroup(t *testing.T) { diff --git a/bench_test.go b/bench_test.go index 23f8a06..c9c66af 100644 --- a/bench_test.go +++ b/bench_test.go @@ -11,8 +11,8 @@ import ( "os" "testing" - "github.com/dgraph-io/badger" - "github.com/timshannon/badgerhold" + "github.com/dgraph-io/badger/v2" + "github.com/timshannon/badgerhold/v2" ) type BenchData struct { diff --git a/compare_test.go b/compare_test.go index fc93ed6..d5cbd47 100644 --- a/compare_test.go +++ b/compare_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - "github.com/timshannon/badgerhold" + "github.com/timshannon/badgerhold/v2" ) type CItemTest struct { diff --git a/delete.go b/delete.go index 0c55884..714513e 100644 --- a/delete.go +++ b/delete.go @@ -7,7 +7,7 @@ package badgerhold import ( "reflect" - "github.com/dgraph-io/badger" + "github.com/dgraph-io/badger/v2" ) // Delete deletes a record from the bolthold, datatype just needs to be an example of the type stored so that diff --git a/delete_test.go b/delete_test.go index 177115a..759619d 100644 --- a/delete_test.go +++ b/delete_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - "github.com/dgraph-io/badger" - "github.com/timshannon/badgerhold" + "github.com/dgraph-io/badger/v2" + "github.com/timshannon/badgerhold/v2" ) func TestDelete(t *testing.T) { diff --git a/example_test.go b/example_test.go index a424d86..9301d38 100644 --- a/example_test.go +++ b/example_test.go @@ -10,8 +10,8 @@ import ( "os" "time" - "github.com/dgraph-io/badger" - "github.com/timshannon/badgerhold" + "github.com/dgraph-io/badger/v2" + "github.com/timshannon/badgerhold/v2" ) type Item struct { diff --git a/find_test.go b/find_test.go index e10e4c9..d2ceb56 100644 --- a/find_test.go +++ b/find_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - "github.com/timshannon/badgerhold" + "github.com/timshannon/badgerhold/v2" ) type ItemTest struct { diff --git a/get.go b/get.go index 3da40d2..5f68995 100644 --- a/get.go +++ b/get.go @@ -9,7 +9,7 @@ import ( "reflect" "strings" - "github.com/dgraph-io/badger" + "github.com/dgraph-io/badger/v2" ) // ErrNotFound is returned when no data is found for the given key diff --git a/get_test.go b/get_test.go index be34e7f..f937e62 100644 --- a/get_test.go +++ b/get_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/timshannon/badgerhold" + "github.com/timshannon/badgerhold/v2" ) func TestGet(t *testing.T) { diff --git a/go.mod b/go.mod index 40f4ebd..2fe5c5b 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/timshannon/badgerhold +module github.com/timshannon/badgerhold/v2 require ( github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect diff --git a/index.go b/index.go index 3a44562..5dfdeeb 100644 --- a/index.go +++ b/index.go @@ -9,7 +9,7 @@ import ( "reflect" "sort" - "github.com/dgraph-io/badger" + "github.com/dgraph-io/badger/v2" ) const indexPrefix = "_bhIndex" diff --git a/nested_structs_test.go b/nested_structs_test.go index 32fc8f4..75dbf5d 100644 --- a/nested_structs_test.go +++ b/nested_structs_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - "github.com/timshannon/badgerhold" + "github.com/timshannon/badgerhold/v2" ) type Nested struct { diff --git a/put.go b/put.go index 42631c3..44352f9 100644 --- a/put.go +++ b/put.go @@ -8,7 +8,7 @@ import ( "errors" "reflect" - "github.com/dgraph-io/badger" + "github.com/dgraph-io/badger/v2" ) // ErrKeyExists is the error returned when data is being Inserted for a Key that already exists diff --git a/put_test.go b/put_test.go index b1beed2..d80d0d3 100644 --- a/put_test.go +++ b/put_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/dgraph-io/badger" - "github.com/timshannon/badgerhold" + "github.com/dgraph-io/badger/v2" + "github.com/timshannon/badgerhold/v2" ) func TestInsert(t *testing.T) { diff --git a/query.go b/query.go index 13d02ac..c05d8ff 100644 --- a/query.go +++ b/query.go @@ -12,7 +12,7 @@ import ( "strings" "unicode" - "github.com/dgraph-io/badger" + "github.com/dgraph-io/badger/v2" ) const ( diff --git a/sort_test.go b/sort_test.go index fda027f..49a3ba4 100644 --- a/sort_test.go +++ b/sort_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/timshannon/badgerhold" + "github.com/timshannon/badgerhold/v2" ) var sortTests = []test{ diff --git a/store_test.go b/store_test.go index f6c4aa4..8cef280 100644 --- a/store_test.go +++ b/store_test.go @@ -11,7 +11,7 @@ import ( "os" "testing" - "github.com/timshannon/badgerhold" + "github.com/timshannon/badgerhold/v2" ) var globalStore *badgerhold.Store From d4ec6a313aa416049f2eeb050f915833c90d66b9 Mon Sep 17 00:00:00 2001 From: Tim Shannon Date: Tue, 13 Oct 2020 12:48:32 -0500 Subject: [PATCH 3/3] Updated tests to work with V2 --- go.mod | 6 +----- go.sum | 8 -------- store_test.go | 43 ++++++++++++++----------------------------- 3 files changed, 15 insertions(+), 42 deletions(-) diff --git a/go.mod b/go.mod index 2fe5c5b..ee9c761 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,5 @@ module github.com/timshannon/badgerhold/v2 -require ( - github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect - github.com/dgraph-io/badger v1.6.0 - github.com/dgraph-io/badger/v2 v2.2007.2 -) +require github.com/dgraph-io/badger/v2 v2.2007.2 go 1.13 diff --git a/go.sum b/go.sum index 2f4aae8..a149610 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,3 @@ -github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9 h1:HD8gA2tkByhMAwYaFAX9w2l7vxvBQ5NMoxDrkhqhtn4= -github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= -github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 h1:cTp8I5+VIoKjsnZuH8vjyaysT/ses3EvZeaV/1UkF2M= -github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM= github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= @@ -17,8 +13,6 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgraph-io/badger v1.6.0 h1:DshxFxZWXUcO0xX476VJC07Xsr6ZCBVRHKZ93Oh7Evo= -github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= github.com/dgraph-io/badger/v2 v2.2007.2 h1:EjjK0KqwaFMlPin1ajhP943VPENHJdEz1KLIegjaI3k= github.com/dgraph-io/badger/v2 v2.2007.2/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE= github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de h1:t0UHb5vdojIDUqktM6+xJAfScFBsVpXZmqC9dsgJmeA= @@ -60,8 +54,6 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= diff --git a/store_test.go b/store_test.go index 8cef280..ad3f259 100644 --- a/store_test.go +++ b/store_test.go @@ -6,7 +6,8 @@ package badgerhold_test import ( "encoding/json" - "fmt" + + // "fmt" "io/ioutil" "os" "testing" @@ -14,29 +15,6 @@ import ( "github.com/timshannon/badgerhold/v2" ) -var globalStore *badgerhold.Store - -func TestMain(m *testing.M) { - opt := testOptions() - var err error - globalStore, err = badgerhold.Open(opt) - if err != nil { - panic(fmt.Sprintf("Error opening %s: %s", opt.Dir, err)) - } - - result := m.Run() - - err = globalStore.Close() - if err != nil { - panic(fmt.Sprintf("Error closing store: %s", err)) - } - err = os.RemoveAll(opt.Dir) - if err != nil { - panic(fmt.Sprintf("Error cleaning up store dir %s: %s", opt.Dir, err)) - } - os.Exit(result) -} - func TestOpen(t *testing.T) { opt := testOptions() store, err := badgerhold.Open(opt) @@ -124,14 +102,21 @@ func TestGetUnknownType(t *testing.T) { // utilities -// testWrap creates a temporary database for testing and closes and cleans it up when -// completed. func testWrap(t *testing.T, tests func(store *badgerhold.Store, t *testing.T)) { - tests(globalStore, t) - err := globalStore.Badger().DropAll() + opt := testOptions() + var err error + store, err := badgerhold.Open(opt) if err != nil { - t.Fatalf("Error clearing badger db: %s", err) + t.Fatalf("Error opening %s: %s", opt.Dir, err) + } + + if store == nil { + t.Fatalf("store is null!") } + + tests(store, t) + store.Close() + os.RemoveAll(opt.Dir) } type emptyLogger struct{}