-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathuuid_test.go
44 lines (37 loc) · 997 Bytes
/
uuid_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gokeepasslib
import (
"errors"
"testing"
)
func TestUUID(t *testing.T) {
one := UUID{}
err := one.UnmarshalText([]byte("rGnBe1gIikK89aZD6n/plA=="))
if err != nil {
t.Fatalf("Error unmarshaling uuid: %s", err.Error())
}
mar, err := one.MarshalText()
if err != nil {
t.Fatalf("Error marshaling uuid")
}
if string(mar) != "rGnBe1gIikK89aZD6n/plA==" {
t.Fatalf("UUID marshaled incorrectly. Expececting %s, got %s", "rGnBe1gIikK89aZD6n/plA==", mar)
}
two := one
if !two.Compare(one) {
t.Fatalf("One and Two UUIDs should be equal, are not")
}
three := UUID{}
err = three.UnmarshalText([]byte("rGnBe1gIikK89aZD6n/plABBBB=="))
if !errors.Is(err, ErrInvalidUUIDLength) {
t.Fatalf("Expected invalid uuid error, got: %s", err)
}
four := UUID{}
err = four.UnmarshalText([]byte(""))
if err != nil {
t.Fatalf("Expected no error but received: %s", err)
}
five := UUID{}
if five.Compare(four) {
t.Fatalf("four and five UUIDs should not be equal but are")
}
}