38 lines
872 B
Go
38 lines
872 B
Go
|
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)
|
||
|
}
|
||
|
})
|
||
|
}
|