ministream/server/config_test.go

38 lines
872 B
Go
Raw Normal View History

2023-12-04 23:45:43 +00:00
package server_test
import (
"strings"
"testing"
"git.t-juice.club/torjus/ministream/server"
)
func TestConfig(t *testing.T) {
t.Run("FromReader", func(t *testing.T) {
configString := `SiteName = "ministream.example.org"`
expectedSiteName := "ministream.example.org"
r := strings.NewReader(configString)
c, err := server.ConfigFromReader(r)
if err != nil {
t.Fatalf("Error reading config: %s", err)
}
if c.SiteName != expectedSiteName {
t.Errorf("SiteName incorrect. Got %s want %s", c.SiteName, expectedSiteName)
}
})
t.Run("OverrideFromEnv", func(t *testing.T) {
c := server.DefaultConfig()
expectedSiteName := "ms.example.org"
t.Setenv("MINISTREAM_SITENAME", expectedSiteName)
c.OverrideFromEnv()
if c.SiteName != expectedSiteName {
t.Errorf("SiteName incorrect. Got %s want %s", c.SiteName, expectedSiteName)
}
})
}