@@ -13,16 +13,21 @@ func TestAttests(t *testing.T) {
1313 attests := Attests {
1414 {Type : "provenance" , Attrs : map [string ]string {"mode" : "max" }},
1515 {Type : "sbom" , Disabled : true },
16+ {Type : "sbom" , Attrs : map [string ]string {
17+ "generator" : "scanner" ,
18+ "ENV1" : `"foo,bar"` ,
19+ "Env2" : "hello" ,
20+ }},
1621 }
1722
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"} ]`
1924 actual , err := json .Marshal (attests )
2025 require .NoError (t , err )
2126 require .JSONEq (t , expected , string (actual ))
2227 })
2328
2429 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"} ]`
2631
2732 var actual Attests
2833 err := json .Unmarshal ([]byte (in ), & actual )
@@ -31,6 +36,11 @@ func TestAttests(t *testing.T) {
3136 expected := Attests {
3237 {Type : "provenance" , Attrs : map [string ]string {"mode" : "max" }},
3338 {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+ }},
3444 }
3545 require .Equal (t , expected , actual )
3646 })
@@ -41,7 +51,14 @@ func TestAttests(t *testing.T) {
4151 "type" : cty .StringVal ("provenance" ),
4252 "mode" : cty .StringVal ("max" ),
4353 }),
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+ }),
4460 cty .StringVal ("type=sbom,disabled=true" ),
61+ cty .StringVal (`type=sbom,generator=scan,"FOO=bar,baz",Hello=World` ),
4562 })
4663
4764 var actual Attests
@@ -50,7 +67,17 @@ func TestAttests(t *testing.T) {
5067
5168 expected := Attests {
5269 {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+ }},
5375 {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+ }},
5481 }
5582 require .Equal (t , expected , actual )
5683 })
@@ -59,6 +86,11 @@ func TestAttests(t *testing.T) {
5986 attests := Attests {
6087 {Type : "provenance" , Attrs : map [string ]string {"mode" : "max" }},
6188 {Type : "sbom" , Disabled : true },
89+ {Type : "sbom" , Attrs : map [string ]string {
90+ "generator" : "scan" ,
91+ "ENV1" : `"foo,bar"` ,
92+ "Env2" : "hello" ,
93+ }},
6294 }
6395
6496 actual := attests .ToCtyValue ()
@@ -71,6 +103,12 @@ func TestAttests(t *testing.T) {
71103 "type" : cty .StringVal ("sbom" ),
72104 "disabled" : cty .StringVal ("true" ),
73105 }),
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+ }),
74112 })
75113
76114 result := actual .Equals (expected )
0 commit comments