test: implement test for common package

This commit is contained in:
Eugen Eisler 2024-08-22 21:00:18 +02:00
parent 4d77ed30e9
commit 6996278c8f
2 changed files with 6 additions and 7 deletions

View File

@ -16,7 +16,7 @@ func TestConfigurable_AddSetting(t *testing.T) {
} }
setting := conf.AddSetting("test_setting", true) setting := conf.AddSetting("test_setting", true)
assert.Equal(t, "TEST_test_setting", setting.EnvVariable) assert.Equal(t, "TEST_TEST_SETTING", setting.EnvVariable)
assert.True(t, setting.Required) assert.True(t, setting.Required)
assert.Contains(t, conf.Settings, setting) assert.Contains(t, conf.Settings, setting)
} }
@ -31,7 +31,7 @@ func TestConfigurable_Configure(t *testing.T) {
Label: "TestConfigurable", Label: "TestConfigurable",
} }
os.Setenv("TEST_SETTING", "test_value") _ = os.Setenv("TEST_SETTING", "test_value")
err := conf.Configure() err := conf.Configure()
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "test_value", setting.Value) assert.Equal(t, "test_value", setting.Value)
@ -65,7 +65,7 @@ func TestSetting_IsValid(t *testing.T) {
} }
func TestSetting_Configure(t *testing.T) { func TestSetting_Configure(t *testing.T) {
os.Setenv("TEST_SETTING", "test_value") _ = os.Setenv("TEST_SETTING", "test_value")
setting := &Setting{ setting := &Setting{
EnvVariable: "TEST_SETTING", EnvVariable: "TEST_SETTING",
Required: true, Required: true,
@ -129,7 +129,7 @@ func TestSettings_IsConfigured(t *testing.T) {
} }
func TestSettings_Configure(t *testing.T) { func TestSettings_Configure(t *testing.T) {
os.Setenv("TEST_SETTING", "test_value") _ = os.Setenv("TEST_SETTING", "test_value")
settings := Settings{ settings := Settings{
{EnvVariable: "TEST_SETTING", Required: true}, {EnvVariable: "TEST_SETTING", Required: true},
} }
@ -159,7 +159,7 @@ func captureOutput(f func()) string {
f() f()
_ = w.Close() _ = w.Close()
os.Stdout = stdout os.Stdout = stdout
buf.ReadFrom(r) _, _ = buf.ReadFrom(r)
return buf.String() return buf.String()
} }
@ -167,7 +167,7 @@ func captureOutput(f func()) string {
func captureInput(input string) func() { func captureInput(input string) func() {
r, w, _ := os.Pipe() r, w, _ := os.Pipe()
_, _ = w.WriteString(input) _, _ = w.WriteString(input)
w.Close() _ = w.Close()
stdin := os.Stdin stdin := os.Stdin
os.Stdin = r os.Stdin = r
return func() { return func() {

1
go.mod
View File

@ -18,7 +18,6 @@ require (
github.com/sashabaranov/go-openai v1.28.2 github.com/sashabaranov/go-openai v1.28.2
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.9.0
google.golang.org/api v0.192.0 google.golang.org/api v0.192.0
gopkg.in/gookit/color.v1 v1.1.6
) )
require ( require (