@@ -29,6 +29,28 @@ func TestIsSuccessState(t *testing.T) {
2929 }
3030}
3131
32+ func TestIsSuccessStateWithLegacyValueResult (t * testing.T ) {
33+ testCases := []struct {
34+ result * Result
35+ want bool
36+ }{
37+ {& Result {ID : "1" , Value : "" }, false },
38+ {& Result {ID : "2" , Value : "aaa" }, false },
39+ {& Result {ID : "3" , Value : []interface {}{}}, false },
40+ {& Result {ID : "4" , Value : []string {"aaa" }}, false },
41+ {& Result {ID : "5" , Value : true }, true },
42+ {& Result {ID : "6" , Value : false }, false },
43+ }
44+
45+ for idx , tc := range testCases {
46+ t .Run (string (idx ), func (t * testing.T ) {
47+ if got , want := tc .result .IsSuccessState (), tc .want ; got != want {
48+ t .Fatalf ("got!=want: got=%v, want=%v" , got , want )
49+ }
50+ })
51+ }
52+ }
53+
3254func TestIsFailureState (t * testing.T ) {
3355 testCases := []struct {
3456 result * Result
@@ -48,6 +70,28 @@ func TestIsFailureState(t *testing.T) {
4870 }
4971}
5072
73+ func TestIsFailureStateWithLegacyValueResult (t * testing.T ) {
74+ testCases := []struct {
75+ result * Result
76+ want bool
77+ }{
78+ {& Result {ID : "1" , Value : "" }, false },
79+ {& Result {ID : "2" , Value : "aaa" }, false },
80+ {& Result {ID : "3" , Value : []interface {}{}}, false },
81+ {& Result {ID : "4" , Value : []string {"aaa" }}, false },
82+ {& Result {ID : "5" , Value : true }, false },
83+ {& Result {ID : "6" , Value : false }, true },
84+ }
85+
86+ for idx , tc := range testCases {
87+ t .Run (string (idx ), func (t * testing.T ) {
88+ if got , want := tc .result .IsFailureState (), tc .want ; got != want {
89+ t .Fatalf ("got!=want: got=%v, want=%v" , got , want )
90+ }
91+ })
92+ }
93+ }
94+
5195func TestNewResultCollectionFromRegoResultSet (t * testing.T ) {
5296 err1 := "ResultSet does not contain 1 exact element"
5397 err2 := "'expressions' does not contain exactly 1 element"
@@ -104,12 +148,12 @@ func TestNewResultCollectionFromRegoResultSet(t *testing.T) {
104148 }
105149
106150 expectedResults := []* Result {
107- & Result {ID : "_1_4_3" , Violations : []string {}, Package : "package.name" },
108- & Result {ID : "_1_4_4" , Violations : []string {"violation" }, Package : "package.name" },
109- & Result {ID : "_1_4_5" , Violations : []string {}, Package : "package.name" },
110- & Result {ID : "_1_4_6" , Violations : []string {}, Package : "package.name" },
111- & Result {ID : "node_pools_with_legacy_endpoints_enabled" , Violations : []string {}, Package : "package.name" },
112- & Result {ID : "node_pools_without_cloud_platform_scope" , Violations : []string {"violation" }, Package : "package.name" },
151+ & Result {ID : "_1_4_3" , Value : [] string {}, Violations : []string {}, Package : "package.name" },
152+ & Result {ID : "_1_4_4" , Value : [] string { "violation" }, Violations : []string {"violation" }, Package : "package.name" },
153+ & Result {ID : "_1_4_5" , Value : [] string {}, Violations : []string {}, Package : "package.name" },
154+ & Result {ID : "_1_4_6" , Value : [] string {}, Violations : []string {}, Package : "package.name" },
155+ & Result {ID : "node_pools_with_legacy_endpoints_enabled" , Value : [] string {}, Violations : []string {}, Package : "package.name" },
156+ & Result {ID : "node_pools_without_cloud_platform_scope" , Value : [] string { "violation" }, Violations : []string {"violation" }, Package : "package.name" },
113157 }
114158
115159 rc , err := NewResultCollectionFromRegoResultSet (regoResultSet )
0 commit comments