test(ircserver): cover VERSION/ADMIN/TIME under the default empty SERVER_NAME
Some checks failed
check / check (push) Failing after 1m16s
Some checks failed
check / check (push) Failing after 1m16s
Both wire test environments hardcoded ServerName: "test.irc", so no test exercised the shipped default and the empty server-name parameter went unnoticed for five rework rounds. Parameterize the env's server name and add a wire test that runs with it empty, asserting the numerics name "neoirc" and contain no empty parameter. Verified to fail against the pre-fix handlers.
This commit is contained in:
@@ -1241,3 +1241,80 @@ func TestIntegrationThirdClientObserver(t *testing.T) {
|
||||
"carol receives trio message",
|
||||
)
|
||||
}
|
||||
|
||||
// assertNoEmptyParam fails if any line contains a doubled
|
||||
// space, which is what FormatMessage emits for an empty
|
||||
// non-trailing parameter. A numeric whose server-name
|
||||
// parameter came out empty is malformed on the wire even
|
||||
// though it still contains the numeric code, so the other
|
||||
// assertions in this file would not catch it.
|
||||
func assertNoEmptyParam(
|
||||
t *testing.T,
|
||||
lines []string,
|
||||
context string,
|
||||
) {
|
||||
t.Helper()
|
||||
|
||||
for _, line := range lines {
|
||||
if strings.Contains(line, " ") {
|
||||
t.Errorf(
|
||||
"%s: empty parameter in wire line: %q",
|
||||
context, line,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestIntegrationDefaultServerNameFallback runs the wire
|
||||
// server with SERVER_NAME unset, which is the shipped
|
||||
// default from config.go, and verifies that VERSION, ADMIN
|
||||
// and TIME fall back to "neoirc" exactly as the HTTP path
|
||||
// does instead of emitting an empty server-name parameter.
|
||||
//
|
||||
// Every other wire test hardcodes ServerName: "test.irc",
|
||||
// so none of them exercise the default configuration.
|
||||
func TestIntegrationDefaultServerNameFallback(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
env := newTestEnvWithServerName(t, "")
|
||||
|
||||
alice := env.dial(t)
|
||||
alice.register("alice")
|
||||
|
||||
alice.send("VERSION")
|
||||
|
||||
versionReply := alice.readUntil(func(l string) bool {
|
||||
return strings.Contains(l, " 351 ")
|
||||
})
|
||||
assertNoEmptyParam(t, versionReply, "VERSION")
|
||||
assertContains(
|
||||
t, versionReply, "neoirc",
|
||||
"VERSION falls back to default server name",
|
||||
)
|
||||
|
||||
alice.send("ADMIN")
|
||||
|
||||
adminReply := alice.readUntil(func(l string) bool {
|
||||
return strings.Contains(l, " 259 ")
|
||||
})
|
||||
assertNoEmptyParam(t, adminReply, "ADMIN")
|
||||
assertContains(
|
||||
t, adminReply, " 256 alice neoirc ",
|
||||
"RPL_ADMINME names the default server",
|
||||
)
|
||||
assertContains(
|
||||
t, adminReply, "admin@neoirc",
|
||||
"RPL_ADMINEMAIL is a well-formed address",
|
||||
)
|
||||
|
||||
alice.send("TIME")
|
||||
|
||||
timeReply := alice.readUntil(func(l string) bool {
|
||||
return strings.Contains(l, " 391 ")
|
||||
})
|
||||
assertNoEmptyParam(t, timeReply, "TIME")
|
||||
assertContains(
|
||||
t, timeReply, " 391 alice neoirc ",
|
||||
"RPL_TIME names the default server",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -38,6 +38,20 @@ type testEnv struct {
|
||||
func newTestEnv(t *testing.T) *testEnv {
|
||||
t.Helper()
|
||||
|
||||
return newTestEnvWithServerName(t, "test.irc")
|
||||
}
|
||||
|
||||
// newTestEnvWithServerName creates a test environment with
|
||||
// an explicit SERVER_NAME. Passing "" exercises the shipped
|
||||
// default from config.go, under which the server must fall
|
||||
// back to "neoirc" rather than emitting an empty
|
||||
// server-name parameter.
|
||||
func newTestEnvWithServerName(
|
||||
t *testing.T,
|
||||
serverName string,
|
||||
) *testEnv {
|
||||
t.Helper()
|
||||
|
||||
dsn := fmt.Sprintf(
|
||||
"file:%s?mode=memory&cache=shared&_journal_mode=WAL",
|
||||
t.Name(),
|
||||
@@ -67,7 +81,7 @@ func newTestEnv(t *testing.T) *testEnv {
|
||||
brk := broker.New()
|
||||
|
||||
cfg := &config.Config{ //nolint:exhaustruct
|
||||
ServerName: "test.irc",
|
||||
ServerName: serverName,
|
||||
MOTD: "Welcome to test IRC",
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user