-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathdetector_test.go
More file actions
56 lines (52 loc) · 1.19 KB
/
detector_test.go
File metadata and controls
56 lines (52 loc) · 1.19 KB
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
package claircore
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestDetectorMarshalText(t *testing.T) {
tests := []struct {
name string
detector Detector
want string
}{
{
name: "valid",
detector: Detector{Name: "test", Version: "1.0.0", Kind: "package"},
want: "urn:claircore:detector:test:1.0.0:package"},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got, err := tc.detector.MarshalText()
if err != nil {
t.Fatalf("MarshalText: %v", err)
}
if !cmp.Equal(tc.want, string(got)) {
t.Errorf("MarshalText: want %s, got %s", tc.want, string(got))
}
})
}
}
func TestDetectorUnmarshalText(t *testing.T) {
tests := []struct {
name string
uri string
want Detector
}{
{
name: "valid",
uri: "urn:claircore:detector:test:1.0.0:package",
want: Detector{Name: "test", Version: "1.0.0", Kind: "package"},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var got Detector
if err := got.UnmarshalText([]byte(tc.uri)); err != nil {
t.Fatalf("UnmarshalText: %v", err)
}
if !cmp.Equal(tc.want, got) {
t.Errorf("UnmarshalText: want %v, got %v", tc.want, got)
}
})
}
}