@@ -2,7 +2,6 @@ package models_test
2
2
3
3
import (
4
4
"encoding/json"
5
- "fmt"
6
5
"testing"
7
6
8
7
"github.com/bloodhoundad/azurehound/v2/models"
@@ -89,7 +88,14 @@ func TestStripEmptyEntries(t *testing.T) {
89
88
90
89
t .Run ("should recursively strip non-empty, nested map[string]any entries" , func (t * testing.T ) {
91
90
data := map [string ]any {
92
- "empty" : map [string ]any {},
91
+ "empty" : map [string ]any {
92
+ "false" : false ,
93
+ "emptystring" : "" ,
94
+ "emptynest" : map [string ]any {
95
+ "false" : false ,
96
+ "emptystring" : "" ,
97
+ },
98
+ },
93
99
"nonempty" : map [string ]any {
94
100
"emptyprop" : 0 ,
95
101
"nonemptyprop" : 1 ,
@@ -106,9 +112,25 @@ func TestStripEmptyEntries(t *testing.T) {
106
112
require .Equal (t , 1 , nested ["nonemptyprop" ])
107
113
})
108
114
109
- t .Run ("should strip non- empty slice entries of type map[string]any" , func (t * testing.T ) {
115
+ t .Run ("should strip empty slice entries of type map[string]any" , func (t * testing.T ) {
110
116
data := map [string ]any {
111
- "empty" : []any {},
117
+ "empty" : []any {
118
+ map [string ]any {
119
+ "false" : false ,
120
+ "emptystring" : "" ,
121
+ },
122
+ },
123
+ "emptynestedslice" : []any {
124
+ map [string ]any {
125
+ "nestedslice" : []any {
126
+ map [string ]any {
127
+ "false" : false ,
128
+ "emptystring" : "" ,
129
+ },
130
+ },
131
+ "emptystring" : "" ,
132
+ },
133
+ },
112
134
"nonempty" : []any {
113
135
map [string ]any {
114
136
"emptyprop" : 0 ,
@@ -117,13 +139,12 @@ func TestStripEmptyEntries(t *testing.T) {
117
139
},
118
140
}
119
141
120
- fmt .Println (data ["nonempty" ])
121
142
models .StripEmptyEntries (data )
122
143
require .Nil (t , data ["empty" ])
144
+ require .Nil (t , data ["emptynestedslice" ])
123
145
require .NotNil (t , data ["nonempty" ])
124
146
require .IsType (t , []any {}, data ["nonempty" ])
125
147
slice := data ["nonempty" ].([]any )
126
- fmt .Println (slice )
127
148
require .IsType (t , map [string ]any {}, slice [0 ])
128
149
entry := slice [0 ].(map [string ]any )
129
150
require .Nil (t , entry ["emptyprop" ])
@@ -147,7 +168,7 @@ func TestOmitEmpty(t *testing.T) {
147
168
require .Equal (t , `{}` , string (filtered ))
148
169
})
149
170
150
- t .Run ("should not omit non-empty basic types" , func (t * testing.T ) {
171
+ t .Run ("should not omit non-empty basic types except empty structs " , func (t * testing.T ) {
151
172
data := json .RawMessage (`{
152
173
"string": "foo",
153
174
"number": 1,
@@ -158,17 +179,17 @@ func TestOmitEmpty(t *testing.T) {
158
179
159
180
filtered , err := models .OmitEmpty (data )
160
181
require .Nil (t , err )
161
- require .Equal (t , `{"array":[1],"boolean":true,"number":1,"object":{}," string":"foo"}` , string (filtered ))
182
+ require .Equal (t , `{"array":[1],"boolean":true,"number":1,"string":"foo"}` , string (filtered ))
162
183
})
163
184
164
- t .Run ("should not omit empty struct/object types, just their empty properties" , func (t * testing.T ) {
185
+ t .Run ("should omit empty struct/object types, just their empty properties" , func (t * testing.T ) {
165
186
data := json .RawMessage (`{
166
187
"object": { "bar": "" }
167
188
}` )
168
189
169
190
filtered , err := models .OmitEmpty (data )
170
191
require .Nil (t , err )
171
- require .Equal (t , `{"object":{} }` , string (filtered ))
192
+ require .Equal (t , `{}` , string (filtered ))
172
193
})
173
194
174
195
t .Run ("should recursively strip non-empty, nested object entries" , func (t * testing.T ) {
0 commit comments