-
Notifications
You must be signed in to change notification settings - Fork 0
/
idsc_test.go
122 lines (117 loc) · 4.18 KB
/
idsc_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package dshards
import (
"bytes"
"testing"
)
func TestParseIDSC(t *testing.T) {
tests := []struct {
name string
input string
expectSuite Suite
expectHash []byte
expectKey []byte
}{
{
name: "Intro Example",
input: "idsc:0p.X74UbU3NoLTA_Nupi8DhaJ_oQpQ95KFukMAkJJotKgo.eekxqfiZIcEnc8cpR-sD_3X3qLaTzQW-KnovArMkGP0",
expectSuite: PROTO_ZERO_SUITE,
expectHash: []byte{95, 190, 20, 109, 77, 205, 160, 180, 192, 252, 219, 169, 139, 192, 225, 104, 159, 232, 66, 148, 61, 228, 161, 110, 144, 192, 36, 36, 154, 45, 42, 10},
expectKey: []byte{121, 233, 49, 169, 248, 153, 33, 193, 39, 115, 199, 41, 71, 235, 3, 255, 117, 247, 168, 182, 147, 205, 5, 190, 42, 122, 47, 2, 179, 36, 24, 253},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actualIDSC, err := ParseIDSC(test.input)
if err != nil {
t.Errorf("got error: %s", err)
} else if actualIDSC.s != test.expectSuite {
t.Errorf("got %q, want %q", actualIDSC.s, test.expectSuite)
} else if !bytes.Equal(actualIDSC.hash, test.expectHash) {
t.Errorf("got %v, want %v", actualIDSC.hash, test.expectHash)
} else if !bytes.Equal(actualIDSC.symmKey, test.expectKey) {
t.Errorf("got %v, want %v", actualIDSC.symmKey, test.expectKey)
}
})
}
}
func TestNewIDSC(t *testing.T) {
tests := []struct {
name string
s Suite
content []byte
key []byte
expect string
}{
{
name: "Sample",
s: PROTO_ZERO_SUITE,
content: []byte{228, 193, 64, 108, 49, 53, 219, 108, 198, 21, 88, 134, 52, 118, 198, 214, 117, 85, 40, 234, 45, 113, 128, 2, 99, 104, 77, 4, 225, 117, 218, 190, 14, 20, 231, 10, 60},
key: []byte{121, 233, 49, 169, 248, 153, 33, 193, 39, 115, 199, 41, 71, 235, 3, 255, 117, 247, 168, 182, 147, 205, 5, 190, 42, 122, 47, 2, 179, 36, 24, 253},
expect: "idsc:0p.JvaPnGGMmYdJGu8lEPy0JcMpfqQqC12hE42oOLjmx8k.eekxqfiZIcEnc8cpR-sD_3X3qLaTzQW-KnovArMkGP0",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actualIDSC, err := NewIDSC(test.s, test.content, test.key)
actual := actualIDSC.String()
if err != nil {
t.Errorf("got error: %s", err)
} else if actual != test.expect {
t.Errorf("got %v, want %v", actual, test.expect)
}
})
}
}
func TestIDSCToString(t *testing.T) {
tests := []struct {
name string
inputSuite Suite
inputHash []byte
inputSymmKey []byte
expect string
}{
{
name: "Intro Example",
inputSuite: PROTO_ZERO_SUITE,
inputHash: []byte{95, 190, 20, 109, 77, 205, 160, 180, 192, 252, 219, 169, 139, 192, 225, 104, 159, 232, 66, 148, 61, 228, 161, 110, 144, 192, 36, 36, 154, 45, 42, 10},
inputSymmKey: []byte{121, 233, 49, 169, 248, 153, 33, 193, 39, 115, 199, 41, 71, 235, 3, 255, 117, 247, 168, 182, 147, 205, 5, 190, 42, 122, 47, 2, 179, 36, 24, 253},
expect: "idsc:0p.X74UbU3NoLTA_Nupi8DhaJ_oQpQ95KFukMAkJJotKgo.eekxqfiZIcEnc8cpR-sD_3X3qLaTzQW-KnovArMkGP0",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
s := IDSC{test.inputSuite, test.inputHash, test.inputSymmKey}
if actual := s.String(); actual != test.expect {
t.Errorf("got %q, want %q", actual, test.expect)
}
})
}
}
func TestIDSCToURN(t *testing.T) {
tests := []struct {
name string
inputSuite Suite
inputHash []byte
inputSymmKey []byte
expect string
}{
{
name: "Intro Example",
inputSuite: PROTO_ZERO_SUITE,
inputHash: []byte{95, 190, 20, 109, 77, 205, 160, 180, 192, 252, 219, 169, 139, 192, 225, 104, 159, 232, 66, 148, 61, 228, 161, 110, 144, 192, 36, 36, 154, 45, 42, 10},
inputSymmKey: []byte{121, 233, 49, 169, 248, 153, 33, 193, 39, 115, 199, 41, 71, 235, 3, 255, 117, 247, 168, 182, 147, 205, 5, 190, 42, 122, 47, 2, 179, 36, 24, 253},
expect: "urn:sha256d:X74UbU3NoLTA_Nupi8DhaJ_oQpQ95KFukMAkJJotKgo",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
s := IDSC{test.inputSuite, test.inputHash, test.inputSymmKey}
sh, err := s.URN()
if err != nil {
t.Errorf("got error: %s", err)
} else if actual := sh.String(); actual != test.expect {
t.Errorf("got %q, want %q", actual, test.expect)
}
})
}
}