-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter_compact_test.go
78 lines (75 loc) · 1.87 KB
/
formatter_compact_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
package sharedsecret
import (
"reflect"
"testing"
)
func TestShamirSecretCompactFormatterFormat(t *testing.T) {
type args struct {
secCtx SecretContext
secretID string
data string
}
secCtx := SecretContext{
Bits: 8,
Radix: 16,
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{"should error for empty secretID", args{secCtx, "", ""}, "", true},
{"should error for data", args{secCtx, "23", ""}, "", true},
{"should format shared secret", args{secCtx, "23", "abcd"}, "abcd", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sf := &shamirSecretCompactFormatter{}
got, err := sf.Format(tt.args.secCtx, tt.args.secretID, tt.args.data)
if (err != nil) != tt.wantErr {
t.Errorf("shamirSecretCompactFormatter.Format() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("shamirSecretCompactFormatter.Format() = %v, want %v", got, tt.want)
}
})
}
}
func TestShamirSecretCompactFormatterParse(t *testing.T) {
type args struct {
secCtx SecretContext
data string
}
secCtx := SecretContext{
Bits: 8,
Radix: 16,
}
tests := []struct {
name string
args args
want interface{}
wantErr bool
}{
{"should error for empty", args{secCtx, ""}, nil, true},
{"should extract", args{secCtx, "abcd"}, shamirSharedSecretData{
id: 1,
bits: 8,
data: "abcd",
}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sf := shamirSecretCompactFormatter{}
got, err := sf.Parse(tt.args.secCtx, tt.args.data)
if (err != nil) != tt.wantErr {
t.Errorf("shamirSecretCompactFormatter.Parse() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("shamirSecretCompactFormatter.Parse() = %v, want %v", got, tt.want)
}
})
}
}