From 00fff032c73de9d932dc259844a7f2b9659c14ba Mon Sep 17 00:00:00 2001 From: Ava Affine Date: Thu, 14 Nov 2024 09:57:06 -0800 Subject: [PATCH 1/3] Add testing CI This commit extends our CI definitions to add a testing phase to the pipeline. The testing phase is intended to be comprised of separate stages per package that has tests included. Currently this consists of the state and config packages. Signed-off-by: Ava Affine --- .gitlab-ci.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7eecc75..93a2f9b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,6 +2,7 @@ image: golang:latest stages: - build + - test compile: stage: build @@ -11,3 +12,13 @@ compile: paths: - bingobot - start.sh + +tests-state-pkg: + stage: test + script: + - go test ./internal/state + +tests-config-pkg: + stage: test + script: + - go test ./internal/config From 6afd0122c918f8409e8aed0e3b9f3ed8157e35e3 Mon Sep 17 00:00:00 2001 From: Ava Affine Date: Thu, 14 Nov 2024 10:27:45 -0800 Subject: [PATCH 2/3] Fix config unit tests Recent changes to config and logging modules have left the tests needing to initialize both config and logging packages. This commit updates the config module to automatically initialize into at least useful defaults at module load time. This commit also fixes the config unit tests by using the more up to date interface that the package provides. Signed-off-by: Ava Affine --- internal/config/config.go | 12 ++++++++++++ internal/config/config_test.go | 5 +---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 90fc69e..e8f7b5c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -18,10 +18,22 @@ type AppConfig struct { var config *AppConfig +func init() { + setDefaults() + viper.Unmarshal(&config) +} + func Get() *AppConfig { return config } +func GetDefaultConfig() *AppConfig { + var config *AppConfig + setDefaults() + viper.Unmarshal(&config) + return config +} + func Init() error { setDefaults() diff --git a/internal/config/config_test.go b/internal/config/config_test.go index eb9f022..9fef00f 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -25,12 +25,9 @@ log_compression: false func TestDefaultConfigs(t *testing.T) { k := "testdefaultkey" v := "testdefaultval" - viper.SetDefault(k, v) - _, err := Parse() - - if err != nil { + if err := Init(); err != nil { t.Error(err) } From 9668106959a0036db26ce3a9f501c04676c502b9 Mon Sep 17 00:00:00 2001 From: Ava Affine Date: Thu, 14 Nov 2024 10:30:04 -0800 Subject: [PATCH 3/3] Fix state unit tests Logging needs to be initialized in order for the state unit tests to function without issue. See previous commit ("Fix config unit tests") for more information. Signed-off-by: Ava Affine --- internal/state/state_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/state/state_test.go b/internal/state/state_test.go index 3d98b1c..e775e74 100644 --- a/internal/state/state_test.go +++ b/internal/state/state_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" "time" + + "gitlab.com/whom/bingobot/internal/logging" ) /* WARNING: @@ -12,8 +14,15 @@ import ( */ const TestTok = "TEST_NAME" +var loggingInitialized = false func SetupTest(t *testing.T) { + // have to set up logger + if !loggingInitialized { + logging.Init() + loggingInitialized = true + } + old, _ := time.Parse( time.RFC3339, VeryOldVote,