2019-12-16 17:59:01 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package dbutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/testrand"
|
2019-12-16 17:59:01 +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) {
|
|
|
|
id := testrand.UUID()
|
|
|
|
result, err := BytesToUUID(id[:])
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, result, id)
|
|
|
|
})
|
|
|
|
}
|