2020-09-01 13:11:38 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"crypto/sha256"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIDV2(t *testing.T) {
|
2020-09-10 09:57:29 +00:00
|
|
|
id := NewID()
|
2020-09-01 13:11:38 +00:00
|
|
|
|
|
|
|
checksum := [sha256.Size]byte{}
|
|
|
|
|
|
|
|
_, err := rand.Read(checksum[:])
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
id.SetSHA256(checksum)
|
|
|
|
|
|
|
|
idV2 := id.ToV2()
|
|
|
|
|
2020-09-10 09:57:29 +00:00
|
|
|
require.Equal(t, checksum[:], idV2.GetValue())
|
2020-09-01 13:11:38 +00:00
|
|
|
}
|
2020-09-11 15:18:29 +00:00
|
|
|
|
|
|
|
func TestID_Equal(t *testing.T) {
|
|
|
|
cs := randSHA256Checksum(t)
|
|
|
|
|
|
|
|
id1 := NewID()
|
|
|
|
id1.SetSHA256(cs)
|
|
|
|
|
|
|
|
id2 := NewID()
|
|
|
|
id2.SetSHA256(cs)
|
|
|
|
|
|
|
|
id3 := NewID()
|
|
|
|
id3.SetSHA256(randSHA256Checksum(t))
|
|
|
|
|
|
|
|
require.True(t, id1.Equal(id2))
|
|
|
|
require.False(t, id1.Equal(id3))
|
|
|
|
}
|