From 595115945c0e606774d443ce8c1a3d39a6d6aef7 Mon Sep 17 00:00:00 2001 From: lyx0 Date: Thu, 28 Oct 2021 23:31:59 +0200 Subject: [PATCH] add config tests --- pkg/config/config.go | 6 ++++++ pkg/config/config_test.go | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 pkg/config/config_test.go diff --git a/pkg/config/config.go b/pkg/config/config.go index 8587620..4538075 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -32,3 +32,9 @@ func LoadConfig() *Config { return cfg } + +// Only for tests +func LoadConfigTest() { + os.Setenv("TEST_VALUE", "xDLUL420") + // defer os.Unsetenv("TEST_VALUE") +} diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go new file mode 100644 index 0000000..48fc16e --- /dev/null +++ b/pkg/config/config_test.go @@ -0,0 +1,20 @@ +package config + +import ( + "os" + "testing" +) + +func TestLoadConfig(t *testing.T) { + t.Run("loads a testing value from the .env file", func(t *testing.T) { + LoadConfigTest() + + got := os.Getenv("TEST_VALUE") + want := "xDLUL420" + + if got != want { + t.Errorf("got %q, want %q", got, want) + } + + }) +}