forked from dweymouth/hashstructure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptional_test.go
More file actions
49 lines (42 loc) · 865 Bytes
/
optional_test.go
File metadata and controls
49 lines (42 loc) · 865 Bytes
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
45
46
47
48
49
package hashstructure
import (
"bytes"
"testing"
"github.com/markphelps/optional"
)
type optionalStruct struct {
Int optional.Int
String optional.String
Bool optional.Bool
}
type outerStruct struct {
Int int
InnerStruct *optionalStruct
}
func TestOptional(t *testing.T) {
s1 := &outerStruct{
Int: 42,
InnerStruct: &optionalStruct{
Int: optional.NewInt(3),
String: optional.NewString("hello"),
},
}
s2 := &outerStruct{
Int: 42,
InnerStruct: &optionalStruct{
Int: optional.NewInt(2),
Bool: optional.NewBool(false),
},
}
h1, err := Hash(s1, FormatMD5, nil)
if err != nil {
t.Errorf("error hashing s1: %v", err)
}
h2, err := Hash(s2, FormatMD5, nil)
if err != nil {
t.Errorf("error hashing s2: %v", err)
}
if bytes.Equal(h1, h2) {
t.Error("hashes were equal and should have been different")
}
}