Skip to content

Commit e32070e

Browse files
committed
Add unit tests for restoreSecrets slice and nested logic
Signed-off-by: EdgeN8v <ckx19921555595@gmail.com>
1 parent b621a64 commit e32070e

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

otelcol/command_print_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,46 @@ func TestPrintCommand(t *testing.T) {
250250
}
251251
}
252252
}
253+
func TestRestoreSecrets(t *testing.T) {
254+
tests := []struct {
255+
name string
256+
base any
257+
raw any
258+
expected any
259+
}{
260+
{
261+
name: "replace in map",
262+
base: map[string]any{"key1": "[REDACTED]", "key2": "normal"},
263+
raw: map[string]any{"key1": "secret1", "key2": "normal"},
264+
expected: map[string]any{"key1": "secret1", "key2": "normal"},
265+
},
266+
{
267+
name: "replace in slice",
268+
base: []any{"[REDACTED]", "normal"},
269+
raw: []any{"secret_in_slice", "normal"},
270+
expected: []any{"secret_in_slice", "normal"},
271+
},
272+
{
273+
name: "nested structures",
274+
base: map[string]any{
275+
"nested_slice": []any{"[REDACTED]"},
276+
"nested_map": map[string]any{"deep_key": "[REDACTED]"},
277+
},
278+
raw: map[string]any{
279+
"nested_slice": []any{"deep_secret1"},
280+
"nested_map": map[string]any{"deep_key": "deep_secret2"},
281+
},
282+
expected: map[string]any{
283+
"nested_slice": []any{"deep_secret1"},
284+
"nested_map": map[string]any{"deep_key": "deep_secret2"},
285+
},
286+
},
287+
}
288+
289+
for _, tt := range tests {
290+
t.Run(tt.name, func(t *testing.T) {
291+
restoreSecrets(tt.base, tt.raw)
292+
require.Equal(t, tt.expected, tt.base)
293+
})
294+
}
295+
}

0 commit comments

Comments
 (0)