From 43ac0cdb9c4eea9d3c5eceb2c11b9e5b98b87b00 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Mon, 30 May 2022 13:41:24 +0100 Subject: [chore] Global server configuration overhaul (#575) * move config flag names and usage to config package, rewrite config package to use global Configuration{} struct Signed-off-by: kim * improved code comment Signed-off-by: kim * linter Signed-off-by: kim * fix unmarshaling Signed-off-by: kim * remove kim's custom go compiler changes Signed-off-by: kim * generate setter and flag-name functions, implement these in codebase Signed-off-by: kim * update deps Signed-off-by: kim * small change Signed-off-by: kim * appease the linter... Signed-off-by: kim * move configuration into ConfigState structure, ensure reloading to/from viper settings to keep in sync Signed-off-by: kim * lint Signed-off-by: kim * update code comments Signed-off-by: kim * fix merge issue Signed-off-by: kim * fix merge issue Signed-off-by: kim * improved version string (removes time + go version) Signed-off-by: kim * fix version string build to pass test script + consolidate logic in func Signed-off-by: kim * add license text, update config.Defaults comment Signed-off-by: kim * add license text to generated config helpers file Signed-off-by: kim * defer unlock on config.Set___(), to ensure unlocked on panic Signed-off-by: kim * make it more obvious which cmd flags are being attached Signed-off-by: kim --- internal/router/session_test.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'internal/router/session_test.go') diff --git a/internal/router/session_test.go b/internal/router/session_test.go index d36da9596..5f4777a48 100644 --- a/internal/router/session_test.go +++ b/internal/router/session_test.go @@ -21,7 +21,6 @@ package router_test import ( "testing" - "github.com/spf13/viper" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/router" @@ -37,8 +36,8 @@ func (suite *SessionTestSuite) SetupTest() { } func (suite *SessionTestSuite) TestDeriveSessionNameLocalhostWithPort() { - viper.Set(config.Keys.Protocol, "http") - viper.Set(config.Keys.Host, "localhost:8080") + config.SetProtocol("http") + config.SetHost("localhost:8080") sessionName, err := router.SessionName() suite.NoError(err) @@ -46,8 +45,8 @@ func (suite *SessionTestSuite) TestDeriveSessionNameLocalhostWithPort() { } func (suite *SessionTestSuite) TestDeriveSessionNameLocalhost() { - viper.Set(config.Keys.Protocol, "http") - viper.Set(config.Keys.Host, "localhost") + config.SetProtocol("http") + config.SetHost("localhost") sessionName, err := router.SessionName() suite.NoError(err) @@ -55,8 +54,8 @@ func (suite *SessionTestSuite) TestDeriveSessionNameLocalhost() { } func (suite *SessionTestSuite) TestDeriveSessionNoProtocol() { - viper.Set(config.Keys.Protocol, "") - viper.Set(config.Keys.Host, "localhost") + config.SetProtocol("") + config.SetHost("localhost") sessionName, err := router.SessionName() suite.EqualError(err, "parse \"://localhost\": missing protocol scheme") @@ -64,9 +63,9 @@ func (suite *SessionTestSuite) TestDeriveSessionNoProtocol() { } func (suite *SessionTestSuite) TestDeriveSessionNoHost() { - viper.Set(config.Keys.Protocol, "https") - viper.Set(config.Keys.Host, "") - viper.Set(config.Keys.Port, 0) + config.SetProtocol("https") + config.SetHost("") + config.SetPort(0) sessionName, err := router.SessionName() suite.EqualError(err, "could not derive hostname without port from https://") @@ -74,8 +73,8 @@ func (suite *SessionTestSuite) TestDeriveSessionNoHost() { } func (suite *SessionTestSuite) TestDeriveSessionOK() { - viper.Set(config.Keys.Protocol, "https") - viper.Set(config.Keys.Host, "example.org") + config.SetProtocol("https") + config.SetHost("example.org") sessionName, err := router.SessionName() suite.NoError(err) @@ -83,8 +82,8 @@ func (suite *SessionTestSuite) TestDeriveSessionOK() { } func (suite *SessionTestSuite) TestDeriveSessionIDNOK() { - viper.Set(config.Keys.Protocol, "https") - viper.Set(config.Keys.Host, "fóid.org") + config.SetProtocol("https") + config.SetHost("fóid.org") sessionName, err := router.SessionName() suite.NoError(err) -- cgit v1.2.3