-
Notifications
You must be signed in to change notification settings - Fork 87
/
tpm_test.go
61 lines (56 loc) · 1.23 KB
/
tpm_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
package sbctl
import (
"errors"
"testing"
"github.com/spf13/afero"
)
var (
tests = []struct {
Result error
File string
Checksums int
}{
{
Result: nil,
File: "tests/tpm_eventlogs/t480s_eventlog",
Checksums: 0,
},
{
Result: ErrOprom,
File: "tests/tpm_eventlogs/t14s_eventlog",
Checksums: 11,
},
{
Result: ErrOprom,
File: "tests/tpm_eventlogs/t14_eventlog",
Checksums: 7,
},
{
Result: ErrNoEventlog,
File: "tests/tpm_eventlogs/this_file_does_not_exist",
Checksums: 0,
},
}
)
func TestParseEventlog(t *testing.T) {
for _, test := range tests {
err := CheckEventlogOprom(afero.NewOsFs(), test.File)
if !errors.Is(err, test.Result) {
t.Fatalf("Test case file '%s' not correct. Expected '%s', got '%s'", test.File, test.Result, err.Error())
}
}
}
func TestEventlogChecksums(t *testing.T) {
for _, test := range tests {
digests, err := GetEventlogChecksums(afero.NewOsFs(), test.File)
if err != nil {
continue
}
if len((*digests)) == 0 {
continue
}
if len((*digests)[0].Signatures) != test.Checksums {
t.Fatalf("Test case file '%s' not correct. Expected '%d', got '%d'", test.File, test.Checksums, len((*digests)))
}
}
}