Let an empty IRC_LISTEN_ADDR disable the IRC listener (closes #124)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
Viper treats an environment variable set to the empty string as unset, so an empty IRC_LISTEN_ADDR fell back to the :6667 default and the IRC listener could not be disabled from the environment. The config now reads IRC_LISTEN_ADDR with os.LookupEnv as well, so an empty value disables the listener and an unset one keeps :6667. Viper's own switch for this applies to every setting, so it is not used. New config tests cover both cases, and README.md says how to disable the listener. Model: opus-5-5 Co-authored-by: clawbot <sneak+clawbot@sneak.cloud>
This commit was merged in pull request #137.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"sneak.berlin/go/neoirc/internal/config"
|
||||
"sneak.berlin/go/neoirc/internal/globals"
|
||||
"sneak.berlin/go/neoirc/internal/logger"
|
||||
)
|
||||
|
||||
func newConfig(t *testing.T) *config.Config {
|
||||
t.Helper()
|
||||
|
||||
globs := &globals.Globals{
|
||||
Appname: "neoirc-test",
|
||||
Version: "test",
|
||||
StartTime: time.Now(),
|
||||
}
|
||||
|
||||
log, err := logger.New(nil, logger.Params{Globals: globs})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cfg, err := config.New(
|
||||
nil, config.Params{Globals: globs, Logger: log},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func TestIRCListenAddrUnsetKeepsDefault(t *testing.T) {
|
||||
// t.Setenv puts back whatever value was there after the test.
|
||||
t.Setenv("IRC_LISTEN_ADDR", "")
|
||||
|
||||
err := os.Unsetenv("IRC_LISTEN_ADDR")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
const want = ":6667"
|
||||
|
||||
cfg := newConfig(t)
|
||||
if cfg.IRCListenAddr != want {
|
||||
t.Errorf("IRCListenAddr = %q, want %q", cfg.IRCListenAddr, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIRCListenAddrEmptyTurnsListenerOff(t *testing.T) {
|
||||
t.Setenv("IRC_LISTEN_ADDR", "")
|
||||
|
||||
cfg := newConfig(t)
|
||||
if cfg.IRCListenAddr != "" {
|
||||
t.Errorf("IRCListenAddr = %q, want empty", cfg.IRCListenAddr)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user