externalize bolt options
This commit is contained in:
+2
-1
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/hashicorp/logutils"
|
||||
"github.com/jessevdk/go-flags"
|
||||
@@ -150,7 +151,7 @@ func makeBoltStore(siteNames []string) store.Interface {
|
||||
for _, site := range siteNames {
|
||||
sites = append(sites, store.BoltSite{SiteID: site, FileName: fmt.Sprintf("%s/%s.db", opts.BoltPath, site)})
|
||||
}
|
||||
result, err := store.NewBoltDB(sites...)
|
||||
result, err := store.NewBoltDB(bolt.Options{Timeout: 30 * time.Second}, sites...)
|
||||
if err != nil {
|
||||
log.Fatalf("[ERROR] can't initialize data store, %+v", err)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -14,7 +15,7 @@ import (
|
||||
|
||||
func TestDisqus_Import(t *testing.T) {
|
||||
defer os.Remove("/tmp/remark-test.db")
|
||||
dataStore, err := store.NewBoltDB(store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "test"})
|
||||
dataStore, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "test"})
|
||||
require.Nil(t, err, "create store")
|
||||
d := Disqus{CommentCreator: dataStore}
|
||||
err = d.Import(strings.NewReader(xmlTest), "test")
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -20,7 +21,7 @@ func TestMigrator_ImportDisqus(t *testing.T) {
|
||||
err := ioutil.WriteFile("/tmp/disqus-test.xml", []byte(xmlTest), 0600)
|
||||
require.Nil(t, err)
|
||||
|
||||
dataStore, err := store.NewBoltDB(store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "test"})
|
||||
dataStore, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "test"})
|
||||
require.Nil(t, err, "create store")
|
||||
|
||||
err = ImportComments(ImportParams{
|
||||
@@ -48,7 +49,7 @@ func TestMigrator_ImportRemark(t *testing.T) {
|
||||
err := ioutil.WriteFile("/tmp/disqus-test.r42", []byte(data), 0600)
|
||||
require.Nil(t, err)
|
||||
|
||||
dataStore, err := store.NewBoltDB(store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "radio-t"})
|
||||
dataStore, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{FileName: "/tmp/remark-test.db", SiteID: "radio-t"})
|
||||
require.Nil(t, err, "create store")
|
||||
|
||||
err = ImportComments(ImportParams{
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/umputun/remark/app/store"
|
||||
@@ -39,7 +40,7 @@ func TestRemark_Import(t *testing.T) {
|
||||
buf.WriteString(r2)
|
||||
|
||||
os.Remove(testDb)
|
||||
b, err := store.NewBoltDB(store.BoltSite{SiteID: "radio-t", FileName: testDb})
|
||||
b, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{SiteID: "radio-t", FileName: testDb})
|
||||
assert.Nil(t, err)
|
||||
r := Remark{CommentCreator: b}
|
||||
err = r.Import(buf, "radio-t")
|
||||
@@ -57,7 +58,7 @@ func TestRemark_Import(t *testing.T) {
|
||||
func prep(t *testing.T) *store.Service {
|
||||
os.Remove(testDb)
|
||||
|
||||
boltStore, err := store.NewBoltDB(store.BoltSite{SiteID: "radio-t", FileName: testDb})
|
||||
boltStore, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{SiteID: "radio-t", FileName: testDb})
|
||||
assert.Nil(t, err)
|
||||
|
||||
b := &store.Service{Interface: boltStore}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -409,7 +410,7 @@ func TestServer_FileServer(t *testing.T) {
|
||||
}
|
||||
|
||||
func prep(t *testing.T) (srv *Rest, port int) {
|
||||
dataStore, err := store.NewBoltDB(store.BoltSite{FileName: testDb, SiteID: "radio-t"})
|
||||
dataStore, err := store.NewBoltDB(bolt.Options{}, store.BoltSite{FileName: testDb, SiteID: "radio-t"})
|
||||
require.Nil(t, err)
|
||||
srv = &Rest{
|
||||
DataService: store.Service{Interface: dataStore, EditDuration: 5 * time.Minute},
|
||||
|
||||
+2
-2
@@ -47,12 +47,12 @@ type BoltSite struct {
|
||||
}
|
||||
|
||||
// NewBoltDB makes persistent boltdb-based store
|
||||
func NewBoltDB(sites ...BoltSite) (*BoltDB, error) {
|
||||
func NewBoltDB(options bolt.Options, sites ...BoltSite) (*BoltDB, error) {
|
||||
log.Printf("[INFO] bolt store for sites %+v", sites)
|
||||
result := BoltDB{dbs: make(map[string]*bolt.DB)}
|
||||
for _, site := range sites {
|
||||
|
||||
db, err := bolt.Open(site.FileName, 0600, &bolt.Options{Timeout: 30 * time.Second})
|
||||
db, err := bolt.Open(site.FileName, 0600, &options) // bolt.Options{Timeout: 30 * time.Second}
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to make boltdb for %s", site.FileName)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -193,7 +194,7 @@ func TestBoltDB_GetForUser(t *testing.T) {
|
||||
func prep(t *testing.T) *Service {
|
||||
os.Remove(testDb)
|
||||
|
||||
boltStore, err := NewBoltDB(BoltSite{FileName: "/tmp/test-remark.db", SiteID: "radio-t"})
|
||||
boltStore, err := NewBoltDB(bolt.Options{}, BoltSite{FileName: "/tmp/test-remark.db", SiteID: "radio-t"})
|
||||
assert.Nil(t, err)
|
||||
b := &Service{Interface: boltStore}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -92,7 +93,7 @@ func TestService_EditComment(t *testing.T) {
|
||||
func TestService_EditCommentDurationFailed(t *testing.T) {
|
||||
defer os.Remove(testDb)
|
||||
|
||||
blt, err := NewBoltDB(BoltSite{FileName: "/tmp/test-remark.db", SiteID: "radio-t"})
|
||||
blt, err := NewBoltDB(bolt.Options{}, BoltSite{FileName: "/tmp/test-remark.db", SiteID: "radio-t"})
|
||||
assert.Nil(t, err)
|
||||
|
||||
comment := Comment{
|
||||
|
||||
Reference in New Issue
Block a user