Re-vendor the canonical files from sneak/prompts at dd4027b (closes #112)
check / check (push) Failing after 7s
check / check (push) Failing after 7s
The shared files are fetched from sneak/prompts dd4027b, with this repository's own entries after the shared content in .gitignore, .editorconfig and .dockerignore. Lint and tests are Dockerfile phases (golangci-lint v2.14.0, Debian Go 1.24.13) that the build stage depends on, and the Makefile targets call the script/ entrypoints. make fmt also formats Markdown with prettier. Fixes for the new lint findings: the auth cookie is always Secure, an IRC connection's relay goroutine stops when the connection closes, and repeated strings are constants. Model: opus-5-5
This commit is contained in:
@@ -4,12 +4,18 @@ import (
|
||||
"testing"
|
||||
|
||||
"sneak.berlin/go/neoirc/internal/ircserver"
|
||||
"sneak.berlin/go/neoirc/pkg/irc"
|
||||
)
|
||||
|
||||
//nolint:funlen // table-driven test
|
||||
func TestParseMessage(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const (
|
||||
nick = "alice"
|
||||
channel = "#general"
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
@@ -24,10 +30,10 @@ func TestParseMessage(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "simple command",
|
||||
input: "PING",
|
||||
input: irc.CmdPing,
|
||||
want: &ircserver.Message{
|
||||
Prefix: "",
|
||||
Command: "PING",
|
||||
Command: irc.CmdPing,
|
||||
Params: nil,
|
||||
},
|
||||
wantNil: false,
|
||||
@@ -38,7 +44,7 @@ func TestParseMessage(t *testing.T) {
|
||||
want: &ircserver.Message{
|
||||
Prefix: "",
|
||||
Command: "NICK",
|
||||
Params: []string{"alice"},
|
||||
Params: []string{nick},
|
||||
},
|
||||
wantNil: false,
|
||||
},
|
||||
@@ -57,8 +63,8 @@ func TestParseMessage(t *testing.T) {
|
||||
input: "PRIVMSG #general :hello world",
|
||||
want: &ircserver.Message{
|
||||
Prefix: "",
|
||||
Command: "PRIVMSG",
|
||||
Params: []string{"#general", "hello world"},
|
||||
Command: irc.CmdPrivmsg,
|
||||
Params: []string{channel, "hello world"},
|
||||
},
|
||||
wantNil: false,
|
||||
},
|
||||
@@ -68,7 +74,7 @@ func TestParseMessage(t *testing.T) {
|
||||
want: &ircserver.Message{
|
||||
Prefix: "server.example.com",
|
||||
Command: "001",
|
||||
Params: []string{"alice", "Welcome to IRC"},
|
||||
Params: []string{nick, "Welcome to IRC"},
|
||||
},
|
||||
wantNil: false,
|
||||
},
|
||||
@@ -79,7 +85,7 @@ func TestParseMessage(t *testing.T) {
|
||||
Prefix: "",
|
||||
Command: "USER",
|
||||
Params: []string{
|
||||
"alice", "0", "*", "Alice Smith",
|
||||
nick, "0", "*", "Alice Smith",
|
||||
},
|
||||
},
|
||||
wantNil: false,
|
||||
@@ -90,7 +96,7 @@ func TestParseMessage(t *testing.T) {
|
||||
want: &ircserver.Message{
|
||||
Prefix: "",
|
||||
Command: "JOIN",
|
||||
Params: []string{"#general"},
|
||||
Params: []string{channel},
|
||||
},
|
||||
wantNil: false,
|
||||
},
|
||||
@@ -99,17 +105,17 @@ func TestParseMessage(t *testing.T) {
|
||||
input: "QUIT :leaving now",
|
||||
want: &ircserver.Message{
|
||||
Prefix: "",
|
||||
Command: "QUIT",
|
||||
Command: irc.CmdQuit,
|
||||
Params: []string{"leaving now"},
|
||||
},
|
||||
wantNil: false,
|
||||
},
|
||||
{
|
||||
name: "quit without reason",
|
||||
input: "QUIT",
|
||||
input: irc.CmdQuit,
|
||||
want: &ircserver.Message{
|
||||
Prefix: "",
|
||||
Command: "QUIT",
|
||||
Command: irc.CmdQuit,
|
||||
Params: nil,
|
||||
},
|
||||
wantNil: false,
|
||||
@@ -120,7 +126,7 @@ func TestParseMessage(t *testing.T) {
|
||||
want: &ircserver.Message{
|
||||
Prefix: "",
|
||||
Command: "MODE",
|
||||
Params: []string{"#general"},
|
||||
Params: []string{channel},
|
||||
},
|
||||
wantNil: false,
|
||||
},
|
||||
@@ -131,7 +137,7 @@ func TestParseMessage(t *testing.T) {
|
||||
Prefix: "",
|
||||
Command: "KICK",
|
||||
Params: []string{
|
||||
"#general", "bob", "misbehaving",
|
||||
channel, "bob", "misbehaving",
|
||||
},
|
||||
},
|
||||
wantNil: false,
|
||||
@@ -141,8 +147,8 @@ func TestParseMessage(t *testing.T) {
|
||||
input: "PRIVMSG #general :",
|
||||
want: &ircserver.Message{
|
||||
Prefix: "",
|
||||
Command: "PRIVMSG",
|
||||
Params: []string{"#general", ""},
|
||||
Command: irc.CmdPrivmsg,
|
||||
Params: []string{channel, ""},
|
||||
},
|
||||
wantNil: false,
|
||||
},
|
||||
@@ -161,7 +167,7 @@ func TestParseMessage(t *testing.T) {
|
||||
input: "PING :irc.example.com",
|
||||
want: &ircserver.Message{
|
||||
Prefix: "",
|
||||
Command: "PING",
|
||||
Command: irc.CmdPing,
|
||||
Params: []string{"irc.example.com"},
|
||||
},
|
||||
wantNil: false,
|
||||
@@ -173,7 +179,7 @@ func TestParseMessage(t *testing.T) {
|
||||
Prefix: "",
|
||||
Command: "TOPIC",
|
||||
Params: []string{
|
||||
"#general",
|
||||
channel,
|
||||
"Welcome to the channel!",
|
||||
},
|
||||
},
|
||||
@@ -237,6 +243,12 @@ func TestParseMessage(t *testing.T) {
|
||||
func TestFormatMessage(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const (
|
||||
nick = "alice"
|
||||
channel = "#general"
|
||||
serverName = "server"
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
prefix string
|
||||
@@ -247,35 +259,35 @@ func TestFormatMessage(t *testing.T) {
|
||||
{
|
||||
name: "simple command",
|
||||
prefix: "",
|
||||
command: "PING",
|
||||
command: irc.CmdPing,
|
||||
params: nil,
|
||||
want: "PING",
|
||||
want: irc.CmdPing,
|
||||
},
|
||||
{
|
||||
name: "with prefix",
|
||||
prefix: "server",
|
||||
prefix: serverName,
|
||||
command: "PONG",
|
||||
params: []string{"server"},
|
||||
params: []string{serverName},
|
||||
want: ":server PONG server",
|
||||
},
|
||||
{
|
||||
name: "privmsg with trailing",
|
||||
prefix: "alice!alice@host",
|
||||
command: "PRIVMSG",
|
||||
params: []string{"#general", "hello world"},
|
||||
command: irc.CmdPrivmsg,
|
||||
params: []string{channel, "hello world"},
|
||||
want: ":alice!alice@host PRIVMSG #general :hello world",
|
||||
},
|
||||
{
|
||||
name: "numeric reply",
|
||||
prefix: "server",
|
||||
prefix: serverName,
|
||||
command: "001",
|
||||
params: []string{"alice", "Welcome to IRC"},
|
||||
params: []string{nick, "Welcome to IRC"},
|
||||
want: ":server 001 alice :Welcome to IRC",
|
||||
},
|
||||
{
|
||||
name: "empty trailing",
|
||||
prefix: "server",
|
||||
command: "PRIVMSG",
|
||||
prefix: serverName,
|
||||
command: irc.CmdPrivmsg,
|
||||
params: []string{"#chan", ""},
|
||||
want: ":server PRIVMSG #chan :",
|
||||
},
|
||||
@@ -302,7 +314,7 @@ func TestParseFormatRoundTrip(t *testing.T) {
|
||||
// parameter either contains a space (gets ':' prefix
|
||||
// on format) or is a non-trailing single token.
|
||||
lines := []string{
|
||||
"PING",
|
||||
irc.CmdPing,
|
||||
"NICK alice",
|
||||
"PRIVMSG #general :hello world",
|
||||
"JOIN #general",
|
||||
|
||||
Reference in New Issue
Block a user