storj/pkg/piecestore/psclient/pieceid_test.go
Bryan White 2a0c4e60d2
preparing for use of customtype gogo extension with NodeID type (#693)
* preparing for use of `customtype` gogo extension with `NodeID` type

* review changes

* preparing for use of `customtype` gogo extension with `NodeID` type

* review changes

* wip

* tests passing

* wip fixing tests

* more wip test fixing

* remove NodeIDList from proto files

* linter fixes

* linter fixes

* linter/review fixes

* more freaking linter fixes

* omg just kill me - linterrrrrrrr

* travis linter, i will muder you and your family in your sleep

* goimports everything - burn in hell travis

* goimports update

* go mod tidy
2018-11-29 19:39:27 +01:00

43 lines
951 B
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package psclient
import (
"testing"
"github.com/mr-tron/base58/base58"
"github.com/stretchr/testify/assert"
"storj.io/storj/internal/identity"
)
func TestNewPieceID(t *testing.T) {
t.Run("should return an id string", func(t *testing.T) {
assert := assert.New(t)
id := NewPieceID()
assert.Equal(id.IsValid(), true)
})
t.Run("should return a different string on each call", func(t *testing.T) {
assert := assert.New(t)
assert.NotEqual(NewPieceID(), NewPieceID())
})
}
func TestDerivePieceID(t *testing.T) {
pid := NewPieceID()
fid, err := testidentity.NewTestIdentity()
assert.NoError(t, err)
did, err := pid.Derive(fid.ID.Bytes())
assert.NoError(t, err)
assert.NotEqual(t, pid, did)
did2, err := pid.Derive(fid.ID.Bytes())
assert.NoError(t, err)
assert.Equal(t, did, did2)
_, err = base58.Decode(did.String())
assert.NoError(t, err)
}