Skip to content

Commit

Permalink
pkg/overlay: fix tests for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
egonelbre committed Aug 22, 2018
1 parent 89abea1 commit a971e41
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
26 changes: 19 additions & 7 deletions pkg/overlay/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ var (
// TODO(bryanchriswhite): compare actual errors
expectedErrors: errors{
mock: nil,
bolt: &storage.ErrKeyNotFound,
bolt: &storage.ErrKeyNotFound,
_redis: &storage.ErrKeyNotFound,
},
data: test.KvStore{"foo": func() storage.Value {
Expand Down Expand Up @@ -248,8 +248,8 @@ func boltTestClient(t *testing.T, data test.KvStore) (_ storage.KeyValueStore, _
assert.NoError(t, err)

cleanup := func() {
err := os.Remove(boltPath)
assert.NoError(t, err)
assert.NoError(t, client.Close())
assert.NoError(t, os.Remove(boltPath))
}

if !(data.Empty()) {
Expand Down Expand Up @@ -296,19 +296,22 @@ func TestRedisPut(t *testing.T) {

for _, c := range putCases {
t.Run(c.testID, func(t *testing.T) {
db, cleanup := boltTestClient(t, c.data)
defer cleanup()

db := redisTestClient(t, c.data)
oc := Cache{DB: db}

err := oc.Put(c.key, c.value)
assertErrClass(t, c.expectedErrors[_redis], err)

v, err := db.Get([]byte(c.key))
assert.NoError(t, err)
na := &overlay.Node{}

na := &overlay.Node{}
assert.NoError(t, proto.Unmarshal(v, na))

{ // see https://github.com/vitessio/vitess/issues/3566
na.XXX_sizecache = c.value.XXX_sizecache
na.Address.XXX_sizecache = c.value.Address.XXX_sizecache
}
assert.Equal(t, na, &c.value)
})
}
Expand Down Expand Up @@ -345,6 +348,11 @@ func TestBoltPut(t *testing.T) {
na := &overlay.Node{}

assert.NoError(t, proto.Unmarshal(v, na))

{ // see https://github.com/vitessio/vitess/issues/3566
na.XXX_sizecache = c.value.XXX_sizecache
na.Address.XXX_sizecache = c.value.Address.XXX_sizecache
}
assert.Equal(t, na, &c.value)
})
}
Expand Down Expand Up @@ -384,6 +392,10 @@ func TestMockPut(t *testing.T) {
na := &overlay.Node{}

assert.NoError(t, proto.Unmarshal(v, na))
{ // see https://github.com/vitessio/vitess/issues/3566
na.XXX_sizecache = c.value.XXX_sizecache
na.Address.XXX_sizecache = c.value.Address.XXX_sizecache
}
assert.Equal(t, na, &c.value)
})
}
Expand Down
20 changes: 11 additions & 9 deletions pkg/overlay/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package overlay
import (
"context"
"net/url"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/zeebo/errs"
"storj.io/storj/pkg/kademlia"
)

Expand All @@ -19,11 +21,11 @@ func TestRun(t *testing.T) {

cases := []struct {
testName string
testFunc func()
testFunc func(t *testing.T)
}{
{
testName: "Run with nil",
testFunc: func() {
testFunc: func(t *testing.T) {
err := config.Run(bctx, nil)

assert.Error(t, err)
Expand All @@ -32,7 +34,7 @@ func TestRun(t *testing.T) {
},
{
testName: "Run with nil, pass pointer to Kademlia in context",
testFunc: func() {
testFunc: func(t *testing.T) {
ctx := context.WithValue(bctx, key, kad)
err := config.Run(ctx, nil)

Expand All @@ -42,7 +44,7 @@ func TestRun(t *testing.T) {
},
{
testName: "db scheme redis conn fail",
testFunc: func() {
testFunc: func(t *testing.T) {
ctx := context.WithValue(bctx, key, kad)
var config = Config{DatabaseURL: "redis://somedir/overlay.db/?db=1"}
err := config.Run(ctx, nil)
Expand All @@ -53,21 +55,21 @@ func TestRun(t *testing.T) {
},
{
testName: "db scheme bolt conn fail",
testFunc: func() {
testFunc: func(t *testing.T) {
ctx := context.WithValue(bctx, key, kad)
var config = Config{DatabaseURL: "bolt://somedir/overlay.db"}
err := config.Run(ctx, nil)

assert.Error(t, err)
assert.Equal(t, err.Error(), "open somedir/overlay.db: no such file or directory")
if !os.IsNotExist(errs.Unwrap(err)) {
t.Fatal(err.Error())
}
},
},
}

for _, c := range cases {
t.Run(c.testName, func(t *testing.T) {
c.testFunc()
})
t.Run(c.testName, c.testFunc)
}
}

Expand Down
15 changes: 9 additions & 6 deletions pkg/provider/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -107,13 +108,15 @@ func TestIdentityConfig_SaveIdentity(t *testing.T) {
err = ic.Save(fi)
assert.NoError(t, err)

certInfo, err := os.Stat(ic.CertPath)
assert.NoError(t, err)
assert.Equal(t, os.FileMode(0644), certInfo.Mode())
if runtime.GOOS != "windows" {
certInfo, err := os.Stat(ic.CertPath)
assert.NoError(t, err)
assert.Equal(t, os.FileMode(0644), certInfo.Mode())

keyInfo, err := os.Stat(ic.KeyPath)
assert.NoError(t, err)
assert.Equal(t, os.FileMode(0600), keyInfo.Mode())
keyInfo, err := os.Stat(ic.KeyPath)
assert.NoError(t, err)
assert.Equal(t, os.FileMode(0600), keyInfo.Mode())
}

savedChainPEM, err := ioutil.ReadFile(ic.CertPath)
assert.NoError(t, err)
Expand Down

0 comments on commit a971e41

Please sign in to comment.