-
Notifications
You must be signed in to change notification settings - Fork 0
/
iswcomponent_test.go
96 lines (84 loc) · 2.3 KB
/
iswcomponent_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
// Copyright 2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package psatoken
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
type testSwComponent struct {
MeasurementType error
MeasurementValue error
Version error
SignerID error
MeasurementDesc error
}
func (o *testSwComponent) GetMeasurementType() (string, error) {
return "", o.MeasurementType
}
func (o *testSwComponent) GetMeasurementValue() ([]byte, error) {
return nil, o.MeasurementValue
}
func (o *testSwComponent) GetVersion() (string, error) {
return "", o.Version
}
func (o *testSwComponent) GetSignerID() ([]byte, error) {
return nil, o.SignerID
}
func (o *testSwComponent) GetMeasurementDesc() (string, error) {
return "", o.MeasurementDesc
}
func (o *testSwComponent) SetMeasurementType(v string) error { return nil }
func (o *testSwComponent) SetMeasurementValue(v []byte) error { return nil }
func (o *testSwComponent) SetVersion(v string) error { return nil }
func (o *testSwComponent) SetSignerID(v []byte) error { return nil }
func (o *testSwComponent) SetMeasurementDesc(v string) error { return nil }
func (o *testSwComponent) Validate() error { return nil }
func Test_ValidateSwComoponent(t *testing.T) {
tvs := []struct {
Name string
Value *testSwComponent
Err string
}{
{
Name: "ok",
Value: &testSwComponent{},
Err: "",
},
{
Name: "nok measurement type",
Value: &testSwComponent{MeasurementType: errors.New("bad")},
Err: "measurement type: bad",
},
{
Name: "nok measurement value",
Value: &testSwComponent{MeasurementValue: errors.New("bad")},
Err: "measurement value: bad",
},
{
Name: "nok version",
Value: &testSwComponent{Version: errors.New("bad")},
Err: "version: bad",
},
{
Name: "nok signer ID",
Value: &testSwComponent{SignerID: errors.New("bad")},
Err: "signer ID: bad",
},
{
Name: "nok measurement desc",
Value: &testSwComponent{MeasurementDesc: errors.New("bad")},
Err: "measurement description: bad",
},
}
for _, tv := range tvs {
t.Run(tv.Name, func(t *testing.T) {
err := ValidateSwComponent(tv.Value)
if tv.Err != "" {
assert.EqualError(t, err, tv.Err)
} else {
assert.NoError(t, err)
}
})
}
}