v0.19.1 dep update, test helper package
This commit is contained in:
1 parent
cb0da23070
commit
81463e305c
11 files changed
+179
-161
No files matched your search
@@ -2,23 +2,14 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"logwisp/internal/config"
|
||||
"logwisp/internal/testutil"
|
||||
|
||||
lconfig "github.com/lixenwraith/config"
|
||||
"github.com/lixenwraith/log"
|
||||
)
|
||||
|
||||
func testLogger(t *testing.T) {
|
||||
t.Helper()
|
||||
logger = log.NewLogger()
|
||||
t.Cleanup(func() { logger = nil })
|
||||
}
|
||||
|
||||
func TestWatchErrorsDoNotTriggerReloadAndChangesAreCoalesced(t *testing.T) {
|
||||
testLogger(t)
|
||||
for _, event := range []string{lconfig.EventFileDeleted, lconfig.EventPermissionsChanged, lconfig.EventReloadTimeout, lconfig.EventReloadError + ":invalid TOML"} {
|
||||
@@ -39,29 +30,6 @@ func TestWatchErrorsDoNotTriggerReloadAndChangesAreCoalesced(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func loadTestConfig(t *testing.T, path string) *config.Config {
|
||||
t.Helper()
|
||||
for _, entry := range os.Environ() {
|
||||
key, value, _ := strings.Cut(entry, "=")
|
||||
if strings.HasPrefix(key, "LOGWISP_") {
|
||||
t.Setenv(key, value)
|
||||
if err := os.Unsetenv(key); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
m, err := config.Load([]string{"-c", path, "--quiet", "--status_reporter=false"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(m.Close)
|
||||
cfg, err := m.Snapshot()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func TestShippedConfigurationBuildsWithCheckedPluginDecoder(t *testing.T) {
|
||||
testLogger(t)
|
||||
path, err := filepath.Abs(filepath.Join("..", "..", "config", "logwisp.toml"))
|
||||
@@ -87,9 +55,7 @@ func TestShippedConfigurationBuildsWithCheckedPluginDecoder(t *testing.T) {
|
||||
func TestInvalidReloadLeavesStatusReporterRunning(t *testing.T) {
|
||||
testLogger(t)
|
||||
path := filepath.Join(t.TempDir(), "config.toml")
|
||||
if err := os.WriteFile(path, []byte("[logging]\nlevel = \"info\"\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testutil.WriteFile(t, path, "[logging]\nlevel = \"info\"\n")
|
||||
for _, mode := range []string{"empty-pipelines", "duplicate-names", "fractional-plugin-integer", "plugin-overflow"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
cfg := loadTestConfig(t, path)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"logwisp/internal/config"
|
||||
"logwisp/internal/testutil"
|
||||
|
||||
"github.com/lixenwraith/log"
|
||||
)
|
||||
|
||||
func testLogger(t *testing.T) {
|
||||
t.Helper()
|
||||
previous := logger
|
||||
logger = log.NewLogger()
|
||||
t.Cleanup(func() { logger = previous })
|
||||
}
|
||||
|
||||
func loadTestConfig(t *testing.T, path string) *config.Config {
|
||||
t.Helper()
|
||||
testutil.ClearEnvPrefix(t, "LOGWISP_")
|
||||
m, err := config.Load([]string{"-c", path, "--quiet", "--status_reporter=false"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(m.Close)
|
||||
cfg, err := m.Snapshot()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
Reference in new issue
Block a user