mirror of
https://github.com/danielmiessler/fabric
synced 2024-11-08 07:11:06 +00:00
test: implement test for common package
This commit is contained in:
parent
4d77ed30e9
commit
6996278c8f
@ -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
1
go.mod
@ -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 (
|
||||||
|
Loading…
Reference in New Issue
Block a user