@@ -13,16 +13,21 @@ func TestAttests(t *testing.T) {
13
13
attests := Attests {
14
14
{Type : "provenance" , Attrs : map [string ]string {"mode" : "max" }},
15
15
{Type : "sbom" , Disabled : true },
16
+ {Type : "sbom" , Attrs : map [string ]string {
17
+ "generator" : "scanner" ,
18
+ "ENV1" : `"foo,bar"` ,
19
+ "Env2" : "hello" ,
20
+ }},
16
21
}
17
22
18
- expected := `[{"type":"provenance","mode":"max"},{"type":"sbom","disabled":true}]`
23
+ expected := `[{"type":"provenance","mode":"max"},{"type":"sbom","disabled":true},{"ENV1":"\"foo,bar\"","Env2":"hello","generator":"scanner","type":"sbom"} ]`
19
24
actual , err := json .Marshal (attests )
20
25
require .NoError (t , err )
21
26
require .JSONEq (t , expected , string (actual ))
22
27
})
23
28
24
29
t .Run ("UnmarshalJSON" , func (t * testing.T ) {
25
- in := `[{"type":"provenance","mode":"max"},{"type":"sbom","disabled":true}]`
30
+ in := `[{"type":"provenance","mode":"max"},{"type":"sbom","disabled":true},{"ENV1":"\"foo,bar\"","Env2":"hello","generator":"scanner","type":"sbom"} ]`
26
31
27
32
var actual Attests
28
33
err := json .Unmarshal ([]byte (in ), & actual )
@@ -31,6 +36,11 @@ func TestAttests(t *testing.T) {
31
36
expected := Attests {
32
37
{Type : "provenance" , Attrs : map [string ]string {"mode" : "max" }},
33
38
{Type : "sbom" , Disabled : true , Attrs : map [string ]string {}},
39
+ {Type : "sbom" , Disabled : false , Attrs : map [string ]string {
40
+ "generator" : "scanner" ,
41
+ "ENV1" : `"foo,bar"` ,
42
+ "Env2" : "hello" ,
43
+ }},
34
44
}
35
45
require .Equal (t , expected , actual )
36
46
})
@@ -41,7 +51,14 @@ func TestAttests(t *testing.T) {
41
51
"type" : cty .StringVal ("provenance" ),
42
52
"mode" : cty .StringVal ("max" ),
43
53
}),
54
+ cty .ObjectVal (map [string ]cty.Value {
55
+ "type" : cty .StringVal ("sbom" ),
56
+ "generator" : cty .StringVal ("scan" ),
57
+ "ENV1" : cty .StringVal (`foo,bar` ),
58
+ "Env2" : cty .StringVal (`hello` ),
59
+ }),
44
60
cty .StringVal ("type=sbom,disabled=true" ),
61
+ cty .StringVal (`type=sbom,generator=scan,"FOO=bar,baz",Hello=World` ),
45
62
})
46
63
47
64
var actual Attests
@@ -50,7 +67,17 @@ func TestAttests(t *testing.T) {
50
67
51
68
expected := Attests {
52
69
{Type : "provenance" , Attrs : map [string ]string {"mode" : "max" }},
70
+ {Type : "sbom" , Attrs : map [string ]string {
71
+ "generator" : "scan" ,
72
+ "ENV1" : "foo,bar" ,
73
+ "Env2" : "hello" ,
74
+ }},
53
75
{Type : "sbom" , Disabled : true , Attrs : map [string ]string {}},
76
+ {Type : "sbom" , Attrs : map [string ]string {
77
+ "generator" : "scan" ,
78
+ "FOO" : "bar,baz" ,
79
+ "Hello" : "World" ,
80
+ }},
54
81
}
55
82
require .Equal (t , expected , actual )
56
83
})
@@ -59,6 +86,11 @@ func TestAttests(t *testing.T) {
59
86
attests := Attests {
60
87
{Type : "provenance" , Attrs : map [string ]string {"mode" : "max" }},
61
88
{Type : "sbom" , Disabled : true },
89
+ {Type : "sbom" , Attrs : map [string ]string {
90
+ "generator" : "scan" ,
91
+ "ENV1" : `"foo,bar"` ,
92
+ "Env2" : "hello" ,
93
+ }},
62
94
}
63
95
64
96
actual := attests .ToCtyValue ()
@@ -71,6 +103,12 @@ func TestAttests(t *testing.T) {
71
103
"type" : cty .StringVal ("sbom" ),
72
104
"disabled" : cty .StringVal ("true" ),
73
105
}),
106
+ cty .MapVal (map [string ]cty.Value {
107
+ "type" : cty .StringVal ("sbom" ),
108
+ "generator" : cty .StringVal ("scan" ),
109
+ "ENV1" : cty .StringVal (`"foo,bar"` ),
110
+ "Env2" : cty .StringVal ("hello" ),
111
+ }),
74
112
})
75
113
76
114
result := actual .Equals (expected )
0 commit comments