forked from theupdateframework/go-tuf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_test.go
73 lines (61 loc) · 1.48 KB
/
sort_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
package signer_test
import (
"encoding/json"
"sort"
"testing"
"github.com/theupdateframework/go-tuf/data"
"github.com/theupdateframework/go-tuf/internal/signer"
"github.com/theupdateframework/go-tuf/pkg/keys"
)
type mockSigner struct {
value json.RawMessage
}
func (s *mockSigner) MarshalPrivateKey() (*data.PrivateKey, error) {
panic("not implemented")
}
func (s *mockSigner) UnmarshalPrivateKey(key *data.PrivateKey) error {
panic("not implemented")
}
func (s *mockSigner) PublicData() *data.PublicKey {
return &data.PublicKey{
Type: "mock",
Scheme: "mock",
Algorithms: []data.HashAlgorithm{"mock"},
Value: s.value,
}
}
func (s *mockSigner) SignMessage(message []byte) ([]byte, error) {
panic("not implemented")
}
func TestSignerSortByIDs(t *testing.T) {
s1 := &mockSigner{
value: json.RawMessage(`{"mock": 1}`),
}
s2 := &mockSigner{
value: json.RawMessage(`{"mock": 2}`),
}
s3 := &mockSigner{
value: json.RawMessage(`{"mock": 3}`),
}
s4 := &mockSigner{
value: json.RawMessage(`{"mock": 4}`),
}
s5 := &mockSigner{
value: json.RawMessage(`{"mock": 5}`),
}
s := []keys.Signer{
s1, s2, s3, s4, s5,
}
sort.Sort(signer.ByIDs(s))
signerIDs := []string{}
for i, signer := range s {
ids := signer.PublicData().IDs()
if len(ids) != 1 {
t.Errorf("Signer %v IDs %v should have length 1", i, ids)
}
signerIDs = append(signerIDs, ids[0])
}
if !sort.StringsAreSorted(signerIDs) {
t.Errorf("Signers incorrectly sorted: %+v", signerIDs)
}
}