@@ -209,6 +209,148 @@ func TestSecret(t *testing.T) {
209209 }),
210210 },
211211 },
212+ {
213+ name : "with includeAllData" ,
214+ secretCollector : & troubleshootv1beta2.Secret {
215+ Namespace : "test-namespace" ,
216+ Name : "test-secret" ,
217+ IncludeAllData : true ,
218+ },
219+ mockSecrets : []corev1.Secret {
220+ {
221+ ObjectMeta : metav1.ObjectMeta {
222+ Name : "test-secret" ,
223+ Namespace : "test-namespace" ,
224+ },
225+ Data : map [string ][]byte {
226+ "database-password" : []byte ("secret123" ),
227+ "api-key" : []byte ("abc123xyz" ),
228+ "jwt-secret" : []byte ("mysupersecret" ),
229+ },
230+ },
231+ },
232+ want : CollectorResult {
233+ "secrets/test-namespace/test-secret.json" : mustJSONMarshalIndent (t , SecretOutput {
234+ Namespace : "test-namespace" ,
235+ Name : "test-secret" ,
236+ SecretExists : true ,
237+ Data : map [string ]string {
238+ "database-password" : "secret123" ,
239+ "api-key" : "abc123xyz" ,
240+ "jwt-secret" : "mysupersecret" ,
241+ },
242+ }),
243+ },
244+ },
245+ {
246+ name : "with includeAllData and specific key" ,
247+ secretCollector : & troubleshootv1beta2.Secret {
248+ Namespace : "test-namespace" ,
249+ Name : "test-secret" ,
250+ Key : "database-password" ,
251+ IncludeValue : true ,
252+ IncludeAllData : true ,
253+ },
254+ mockSecrets : []corev1.Secret {
255+ {
256+ ObjectMeta : metav1.ObjectMeta {
257+ Name : "test-secret" ,
258+ Namespace : "test-namespace" ,
259+ },
260+ Data : map [string ][]byte {
261+ "database-password" : []byte ("secret123" ),
262+ "api-key" : []byte ("abc123xyz" ),
263+ "jwt-secret" : []byte ("mysupersecret" ),
264+ },
265+ },
266+ },
267+ want : CollectorResult {
268+ "secrets/test-namespace/test-secret.json" : mustJSONMarshalIndent (t , SecretOutput {
269+ Namespace : "test-namespace" ,
270+ Name : "test-secret" ,
271+ Key : "database-password" ,
272+ SecretExists : true ,
273+ Data : map [string ]string {
274+ "database-password" : "secret123" ,
275+ "api-key" : "abc123xyz" ,
276+ "jwt-secret" : "mysupersecret" ,
277+ },
278+ }),
279+ },
280+ },
281+ {
282+ name : "with includeAllData secret not found" ,
283+ secretCollector : & troubleshootv1beta2.Secret {
284+ Namespace : "test-namespace" ,
285+ Name : "test-secret" ,
286+ IncludeAllData : true ,
287+ },
288+ mockSecrets : []corev1.Secret {
289+ {
290+ ObjectMeta : metav1.ObjectMeta {
291+ Name : "other-secret" ,
292+ Namespace : "test-namespace" ,
293+ },
294+ Data : map [string ][]byte {
295+ "test-key" : []byte ("test-value" ),
296+ },
297+ },
298+ },
299+ want : CollectorResult {
300+ "secrets/test-namespace/test-secret.json" : mustJSONMarshalIndent (t , SecretOutput {
301+ Namespace : "test-namespace" ,
302+ Name : "test-secret" ,
303+ SecretExists : false ,
304+ }),
305+ "secrets-errors/test-namespace/test-secret.json" : mustJSONMarshalIndent (t , []string {
306+ `secrets "test-secret" not found` ,
307+ }),
308+ },
309+ },
310+ {
311+ name : "with includeAllData by selector" ,
312+ secretCollector : & troubleshootv1beta2.Secret {
313+ Namespace : "test-namespace" ,
314+ Selector : []string {
315+ "app=my-app" ,
316+ },
317+ IncludeAllData : true ,
318+ },
319+ mockSecrets : []corev1.Secret {
320+ {
321+ ObjectMeta : metav1.ObjectMeta {
322+ Name : "test-secret" ,
323+ Namespace : "test-namespace" ,
324+ Labels : map [string ]string {"app" : "my-app" },
325+ },
326+ Data : map [string ][]byte {
327+ "database-password" : []byte ("secret123" ),
328+ "api-key" : []byte ("abc123xyz" ),
329+ },
330+ },
331+ {
332+ ObjectMeta : metav1.ObjectMeta {
333+ Name : "other-secret" ,
334+ Namespace : "test-namespace" ,
335+ Labels : map [string ]string {"app" : "not-my-app" },
336+ },
337+ Data : map [string ][]byte {
338+ "test-key" : []byte ("test-value" ),
339+ },
340+ },
341+ },
342+ want : CollectorResult {
343+ "secrets/test-namespace/test-secret.json" : mustJSONMarshalIndent (t , SecretOutput {
344+ Namespace : "test-namespace" ,
345+ Name : "test-secret" ,
346+ SecretExists : true ,
347+ Data : map [string ]string {
348+ "database-password" : "secret123" ,
349+ "api-key" : "abc123xyz" ,
350+ },
351+ }),
352+ },
353+ },
212354 }
213355 for _ , tt := range tests {
214356 t .Run (tt .name , func (t * testing.T ) {
0 commit comments