2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-12 09:14:16 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package satellitedb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-05-19 16:10:46 +01:00
|
|
|
"github.com/lib/pq"
|
2018-11-12 09:14:16 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-05-19 16:10:46 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/storj"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testrand"
|
2018-11-12 09:14:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBytesToUUID(t *testing.T) {
|
|
|
|
t.Run("Invalid input", func(t *testing.T) {
|
|
|
|
str := "not UUID string"
|
|
|
|
bytes := []byte(str)
|
|
|
|
|
|
|
|
_, err := bytesToUUID(bytes)
|
|
|
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Valid input", func(t *testing.T) {
|
2019-06-26 11:38:51 +01:00
|
|
|
id := testrand.UUID()
|
2018-11-12 09:14:16 +00:00
|
|
|
result, err := bytesToUUID(id[:])
|
|
|
|
assert.NoError(t, err)
|
2019-06-26 11:38:51 +01:00
|
|
|
assert.Equal(t, result, id)
|
2018-11-12 09:14:16 +00:00
|
|
|
})
|
|
|
|
}
|
2019-05-19 16:10:46 +01:00
|
|
|
|
|
|
|
func TestPostgresNodeIDsArray(t *testing.T) {
|
|
|
|
ids := make(storj.NodeIDList, 10)
|
|
|
|
for i := range ids {
|
2019-06-26 11:38:51 +01:00
|
|
|
ids[i] = testrand.NodeID()
|
2019-05-19 16:10:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
got, err := postgresNodeIDList(ids).Value() // returns a []byte
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
expected, err := pq.ByteaArray(ids.Bytes()).Value() // returns a string
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, expected.(string), string(got.([]byte)))
|
|
|
|
}
|