Skip to content

Commit

Permalink
Merge pull request #23 from gfanton/feat/go-1.13
Browse files Browse the repository at this point in the history
feat: Update to go 1.13
  • Loading branch information
gfanton authored Dec 18, 2019
2 parents 4543d20 + 8569e36 commit 280660e
Show file tree
Hide file tree
Showing 17 changed files with 525 additions and 397 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ orbs:
jobs:
build:
docker:
- image: circleci/golang:1.12
- image: circleci/golang:1.13
working_directory: /go/src/berty.tech/go-ipfs-log
environment:
GO111MODULE: "on"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ See [GoDoc](https://godoc.org/github.com/berty/go-orbit-db).

Constraints:

* `go-orbit-db` currently only works with **go1.12**
* `go-orbit-db` currently only works with **go1.13** and later
* You need to use the canonical import: `berty.tech/go-orbit-db` instead of `github.com/berty/go-orbit-db`
* If you have `410 gone` errors, make sure that you use a reliable `$GOPROXY` or disable it completely

Example:

```console
$ go version
go version go1.12.10 linux/amd64
go version go1.13.4 darwin/amd64
$ go get berty.tech/go-orbit-db
[...]
$
Expand Down
4 changes: 4 additions & 0 deletions cache/cacheleveldown/leveldown.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func (w *wrappedCache) Delete(key datastore.Key) error {
return w.wrappedCache.Delete(key)
}

func (w *wrappedCache) Sync(key datastore.Key) error {
return w.wrappedCache.Sync(key)
}

func (w *wrappedCache) Close() error {
if w.closed {
return nil
Expand Down
35 changes: 18 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
module berty.tech/go-orbit-db

go 1.12
go 1.13

require (
berty.tech/go-ipfs-log v0.0.0-20191118100004-2fb04713cace
github.com/ipfs/go-cid v0.0.2
github.com/ipfs/go-datastore v0.0.5
github.com/ipfs/go-ds-leveldb v0.0.2
github.com/ipfs/go-ipfs v0.4.22
github.com/ipfs/go-ipfs-files v0.0.3
github.com/ipfs/go-ipld-cbor v0.0.2
github.com/ipfs/interface-go-ipfs-core v0.0.8
github.com/libp2p/go-libp2p v0.0.28
github.com/libp2p/go-libp2p-core v0.0.6
github.com/libp2p/go-libp2p-peer v0.2.0 // indirect
github.com/libp2p/go-libp2p-peerstore v0.0.6
berty.tech/go-ipfs-log v0.0.0-20191218104035-c2dbcdce66fd
github.com/ipfs/go-cid v0.0.4
github.com/ipfs/go-datastore v0.3.1
github.com/ipfs/go-ds-leveldb v0.4.0
github.com/ipfs/go-ipfs v0.4.22-0.20191217161056-7cc392ba9dac
github.com/ipfs/go-ipfs-files v0.0.4
github.com/ipfs/go-ipld-cbor v0.0.3
github.com/ipfs/interface-go-ipfs-core v0.2.5
github.com/libp2p/go-libp2p v0.5.0
github.com/libp2p/go-libp2p-core v0.3.0
github.com/libp2p/go-libp2p-peerstore v0.1.4
github.com/pkg/errors v0.8.1
github.com/polydawn/refmt v0.0.0-20190221155625-df39d6c2d992
github.com/prometheus/common v0.4.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa
github.com/polydawn/refmt v0.0.0-20190408063855-01bf1e26dd14
github.com/prometheus/common v0.6.0
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a
go.uber.org/zap v1.10.0
)

replace github.com/dgraph-io/badger => github.com/dgraph-io/badger v0.0.0-20190809121831-9d7b751e85c9
replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v1.18.0

replace github.com/go-critic/go-critic v0.0.0-20181204210945-ee9bf5809ead => github.com/go-critic/go-critic v0.3.5-0.20190526074819-1df300866540
619 changes: 348 additions & 271 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions internal/buildconstraints/supported.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build go1.12,!go1.13
// +build go1.13

package buildconstraints

// this file is called for (version>=go1.12 AND version<go.13)
// this file is called for (version >= go1.13)
// see https://golang.org/pkg/go/build/
6 changes: 3 additions & 3 deletions internal/buildconstraints/unsupported.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// +build !go1.12 go1.13
// +build !go1.13

package buildconstraints

func error() {
`Unsupported go version, please use go1.12`
`Unsupported go version, please use go1.13`
}

// this file is called for (version<1.12 OR version>=go1.13)
// this file is called for (version < go1.13)
// See https://golang.org/pkg/go/build/
25 changes: 16 additions & 9 deletions tests/create_open_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package tests

import (
"berty.tech/go-orbit-db/accesscontroller"
"context"
"fmt"
"os"
"path"
"testing"
"time"

"berty.tech/go-orbit-db/accesscontroller"

"berty.tech/go-ipfs-log/identityprovider"
"berty.tech/go-ipfs-log/io"
"berty.tech/go-ipfs-log/keystore"
Expand All @@ -24,16 +25,21 @@ import (

func TestCreateOpen(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
_, ipfs := MakeIPFS(ctx, t)
defer cancel()

Convey("orbit-db - Create & Open", t, FailureHalts, func(c C) {
dbPath := path.Join("./orbitdb/tests/create-open", "1")
mocknet := testingMockNet(ctx)
node, clean := testingIPFSNode(ctx, t, mocknet)
defer clean()

defer os.RemoveAll("./orbitdb/tests/create-open")
ipfs := testingCoreAPI(t, node)

Convey("orbit-db - Create & Open", t, FailureHalts, func(c C) {
dbPath, clean := testingTempDir(t, "db")
defer clean()

orbit, err := orbitdb.NewOrbitDB(ctx, ipfs, &orbitdb.NewOrbitDBOptions{Directory: &dbPath})
c.So(err, ShouldBeNil)

defer orbit.Close()

c.Convey("Create", FailureHalts, func(c C) {
Expand Down Expand Up @@ -139,11 +145,13 @@ func TestCreateOpen(t *testing.T) {
})

c.Convey("can pass local database directory as an option", FailureHalts, func(c C) {
dir := path.Join("./orbitdb/tests/create-open/another-feed")
db, err := orbit.Create(ctx, "third", "eventlog", &orbitdb.CreateDBOptions{Directory: &dir})
dbPath2, clean := testingTempDir(t, "db2")
defer clean()

db, err := orbit.Create(ctx, "third", "eventlog", &orbitdb.CreateDBOptions{Directory: &dbPath2})
c.So(err, ShouldBeNil)

localDataPath = path.Join(dir, db.Address().GetRoot().String(), db.Address().GetPath())
localDataPath = path.Join(dbPath2, db.Address().GetRoot().String(), db.Address().GetPath())

_, err = os.Stat(localDataPath)
c.So(os.IsNotExist(err), ShouldBeFalse)
Expand Down Expand Up @@ -356,6 +364,5 @@ func TestCreateOpen(t *testing.T) {
})
})

TeardownNetwork()
})
}
25 changes: 11 additions & 14 deletions tests/eventlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,34 @@ import (
"bytes"
"context"
"fmt"
"github.com/ipfs/go-cid"
"os"
"path"
"testing"
"time"

"github.com/ipfs/go-cid"

orbitdb "berty.tech/go-orbit-db"
"berty.tech/go-orbit-db/stores/operation"
. "github.com/smartystreets/goconvey/convey"
)

func cidPtr (c cid.Cid) *cid.Cid{
func cidPtr(c cid.Cid) *cid.Cid {
return &c
}

func TestLogDatabase(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

const dbPath = "./orbitdb/tests/eventlog"
defer os.RemoveAll(dbPath)
db1Path, clean := testingTempDir(t, "db1")
defer clean()

//.createInstance(ipfs, { directory: path.join(dbPath, '1') })
Convey("creates and opens a database", t, FailureHalts, func(c C) {
err := os.RemoveAll(dbPath)
c.So(err, ShouldBeNil)
mocknet := testingMockNet(ctx)
node, clean := testingIPFSNode(ctx, t, mocknet)
defer clean()

db1IPFS := testingCoreAPI(t, node)

db1Path := path.Join(dbPath, "1")
_, db1IPFS := MakeIPFS(ctx, t)
infinity := -1

orbitdb1, err := orbitdb.NewOrbitDB(ctx, db1IPFS, &orbitdb.NewOrbitDBOptions{
Expand Down Expand Up @@ -428,7 +427,5 @@ func TestLogDatabase(t *testing.T) {
})
})
})

TeardownNetwork()
})
}
20 changes: 9 additions & 11 deletions tests/keyvalue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package tests

import (
"context"
"os"
"path"
"testing"
"time"

Expand All @@ -15,20 +13,21 @@ func TestKeyValueStore(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()

dbPath := "./orbitdb/tests/keystore"
dbname := "orbit-db-tests"
dbPath, clean := testingTempDir(t, "db-keystore")
defer clean()

defer os.RemoveAll(dbPath)
dbname := "orbit-db-tests"

Convey("orbit-db - Key-Value Database", t, FailureHalts, func(c C) {
err := os.RemoveAll(dbPath)
c.So(err, ShouldBeNil)
mocknet := testingMockNet(ctx)

node, clean := testingIPFSNode(ctx, t, mocknet)
defer clean()

db1Path := path.Join(dbPath, "1")
_, db1IPFS := MakeIPFS(ctx, t)
db1IPFS := testingCoreAPI(t, node)

orbitdb1, err := orbitdb2.NewOrbitDB(ctx, db1IPFS, &orbitdb2.NewOrbitDBOptions{
Directory: &db1Path,
Directory: &dbPath,
})
defer orbitdb1.Close()

Expand Down Expand Up @@ -133,6 +132,5 @@ func TestKeyValueStore(t *testing.T) {
c.So(value, ShouldEqual, nil)
})

TeardownNetwork()
})
}
2 changes: 0 additions & 2 deletions tests/orbit_db_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,5 @@ func TestOrbitDbAddress(t *testing.T) {
c.So(err, ShouldNotBeNil)
})
})

TeardownNetwork()
})
}
19 changes: 8 additions & 11 deletions tests/persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package tests
import (
"context"
"fmt"
"os"
"path"
"sync"
"testing"
"time"
Expand All @@ -20,24 +18,25 @@ func TestPersistence(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

dbPath := "./orbitdb/tests/persistence"
entryCount := 65
infinity := -1

_, db1IPFS := MakeIPFS(ctx, t)
mocknet := testingMockNet(ctx)
node, clean := testingIPFSNode(ctx, t, mocknet)
defer clean()

defer os.RemoveAll(dbPath)
db1IPFS := testingCoreAPI(t, node)

Convey("orbit-db - Create & Open", t, FailureHalts, func(c C) {
err := os.RemoveAll(dbPath)
c.So(err, ShouldBeNil)

db1Path := path.Join(dbPath, "1")
db1Path, clean := testingTempDir(t, "db1")
defer clean()

orbitdb1, err := orbitdb.NewOrbitDB(ctx, db1IPFS, &orbitdb.NewOrbitDBOptions{
Directory: &db1Path,
})

c.So(err, ShouldBeNil)

c.Convey("load", FailureHalts, func(c C) {
dbName := fmt.Sprintf("%d", time.Now().UnixNano())

Expand Down Expand Up @@ -295,7 +294,5 @@ func TestPersistence(t *testing.T) {
}
})
})

TeardownNetwork()
})
}
34 changes: 21 additions & 13 deletions tests/replicate_automatically_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package tests

import (
"berty.tech/go-orbit-db/accesscontroller"
"context"
"fmt"
"os"

"berty.tech/go-orbit-db/accesscontroller"

orbitdb "berty.tech/go-orbit-db"
"berty.tech/go-orbit-db/events"
Expand All @@ -28,25 +28,34 @@ func TestReplicateAutomatically(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*180)
defer cancel()

dbPath1 := "./orbitdb/tests/replicate-automatically/1"
dbPath2 := "./orbitdb/tests/replicate-automatically/2"
dbPath1, clean := testingTempDir(t, "db1")
defer clean()

dbPath2, clean := testingTempDir(t, "db2")
defer clean()

mocknet := testingMockNet(ctx)

node1, clean := testingIPFSNode(ctx, t, mocknet)
defer clean()

defer os.RemoveAll("./orbitdb/tests/replicate-automatically/")
node2, clean := testingIPFSNode(ctx, t, mocknet)
defer clean()

ipfsd1, ipfs1 := MakeIPFS(ctx, t)
ipfsd2, ipfs2 := MakeIPFS(ctx, t)
ipfs1 := testingCoreAPI(t, node1)
ipfs2 := testingCoreAPI(t, node2)

zap.L().Named("orbitdb.tests").Debug(fmt.Sprintf("node1 is %s", ipfsd1.Identity.String()))
zap.L().Named("orbitdb.tests").Debug(fmt.Sprintf("node2 is %s", ipfsd2.Identity.String()))
zap.L().Named("orbitdb.tests").Debug(fmt.Sprintf("node1 is %s", node1.Identity.String()))
zap.L().Named("orbitdb.tests").Debug(fmt.Sprintf("node2 is %s", node2.Identity.String()))

_, err := TestNetwork.LinkPeers(ipfsd1.Identity, ipfsd2.Identity)
_, err := mocknet.LinkPeers(node1.Identity, node2.Identity)
c.So(err, ShouldBeNil)

peerInfo2 := peerstore.PeerInfo{ID: ipfsd2.Identity, Addrs: ipfsd2.PeerHost.Addrs()}
peerInfo2 := peerstore.PeerInfo{ID: node2.Identity, Addrs: node2.PeerHost.Addrs()}
err = ipfs1.Swarm().Connect(ctx, peerInfo2)
c.So(err, ShouldBeNil)

peerInfo1 := peerstore.PeerInfo{ID: ipfsd1.Identity, Addrs: ipfsd1.PeerHost.Addrs()}
peerInfo1 := peerstore.PeerInfo{ID: node1.Identity, Addrs: node1.PeerHost.Addrs()}
err = ipfs2.Swarm().Connect(ctx, peerInfo1)
c.So(err, ShouldBeNil)

Expand Down Expand Up @@ -226,6 +235,5 @@ func TestReplicateAutomatically(t *testing.T) {
c.So(err, ShouldBeNil)
}

TeardownNetwork()
})
}
Loading

0 comments on commit 280660e

Please sign in to comment.