Skip to content

Commit 61c6cc6

Browse files
committed
test(http-hooks): improve test coverage
1 parent e38fab1 commit 61c6cc6

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

monitor/hook/sender_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,10 @@ func TestConfidentialURL(t *testing.T) {
274274
assert.Equal(t, 1, calls)
275275
}
276276

277-
// TODO: check if env vars have changed
278277
func TestURLEncoding(t *testing.T) {
279278
ctx := Context{
280-
ProfileName: "unused",
281-
ProfileCommand: "unused",
279+
ProfileName: "unencoded/name",
280+
ProfileCommand: "unencoded/command",
282281
Error: ErrorContext{
283282
Message: "some/error/message",
284283
CommandLine: "some < tricky || command & line",
@@ -292,18 +291,26 @@ func TestURLEncoding(t *testing.T) {
292291
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
293292
query := r.URL.Query()
294293

294+
assert.Equal(t, fmt.Sprintf("/%s-%s", ctx.ProfileName, ctx.ProfileCommand), r.URL.Path)
295+
295296
assert.Equal(t, ctx.Error.Message, query.Get("message"))
296297
assert.Equal(t, ctx.Error.CommandLine, query.Get("command_line"))
297298
assert.Equal(t, ctx.Error.ExitCode, query.Get("exit_code"))
298299
assert.Equal(t, ctx.Error.Stderr, query.Get("stderr"))
299300

301+
assert.Equal(t, "$TEST_MONITOR_URL", query.Get("escaped"))
302+
300303
calls++
301304
}))
302305
defer server.Close()
303306

307+
// test if env vars are untouched
308+
t.Setenv("TEST_MONITOR_URL", server.URL)
309+
304310
serverURL := fmt.Sprintf(
305-
"%s/?message=$%s&command_line=$%s&exit_code=$%s&stderr=$%s",
306-
server.URL,
311+
"$TEST_MONITOR_URL/$%s-$%s?message=$%s&command_line=$%s&exit_code=$%s&stderr=$%s&escaped=$$TEST_MONITOR_URL",
312+
constants.EnvProfileName,
313+
constants.EnvProfileCommand,
307314
constants.EnvError,
308315
constants.EnvErrorCommandLine,
309316
constants.EnvErrorExitCode,

0 commit comments

Comments
 (0)