Skip to content

Commit e71e505

Browse files
author
John Ferguson
committed
test: add maskKey test to improve telemetry coverage
- Add comprehensive TestMaskKey with 6 test cases - Coverage: empty string, short keys, boundary case, long keys, API key format - Telemetry package coverage improved from 47.2% to 50.0% (+2.8%)
1 parent 26aa5ba commit e71e505

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

internal/telemetry/telemetry_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,49 @@ func TestClientStartTransaction(t *testing.T) {
237237
transaction := client.StartTransaction("test_transaction", "test_operation")
238238
assert.Nil(t, transaction)
239239
}
240+
241+
func TestMaskKey(t *testing.T) {
242+
tests := []struct {
243+
name string
244+
input string
245+
expected string
246+
}{
247+
{
248+
name: "Empty string",
249+
input: "",
250+
expected: "[not provided]",
251+
},
252+
{
253+
name: "Very short key (1 char)",
254+
input: "a",
255+
expected: "[masked]",
256+
},
257+
{
258+
name: "Short key (7 chars)",
259+
input: "1234567",
260+
expected: "[masked]",
261+
},
262+
{
263+
name: "Exactly 8 chars",
264+
input: "12345678",
265+
expected: "1234****5678",
266+
},
267+
{
268+
name: "Long key",
269+
input: "abcdefghijklmnopqrstuvwxyz",
270+
expected: "abcd****wxyz",
271+
},
272+
{
273+
name: "API key format",
274+
input: "test_live_abc123def456ghi789jkl012mno345pqr678stu901vwx234",
275+
expected: "test****x234",
276+
},
277+
}
278+
279+
for _, tt := range tests {
280+
t.Run(tt.name, func(t *testing.T) {
281+
result := maskKey(tt.input)
282+
assert.Equal(t, tt.expected, result)
283+
})
284+
}
285+
}

0 commit comments

Comments
 (0)