From ffcd19e748752fce719aa5deb2d4a4fde637ae4c Mon Sep 17 00:00:00 2001 From: wushuzh <3007906+wushuzh@users.noreply.github.com> Date: Mon, 22 Jul 2024 17:33:56 +0800 Subject: [PATCH] bugfix: use cross-platform module filepath to set usedConfigDir (#369) * bugfix: use filepath to set correct configDir in Windows * test: improve unittest rep folder creation --------- Co-authored-by: wushuzh --- Makefile | 3 ++- integration-tests/Makefile | 2 +- internal/config/config_reloader.go | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index ad55dc5..1e701ef 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,8 @@ daemon-codestyle: gocritic check ./... daemon-unittests: - mkdir -p reports + $(call delete-files,reports) + mkdir reports go test ./... -coverprofile reports/unittests.out go tool cover -html=reports/unittests.out -o reports/unittests.html diff --git a/integration-tests/Makefile b/integration-tests/Makefile index 46132c0..a0a6622 100644 --- a/integration-tests/Makefile +++ b/integration-tests/Makefile @@ -4,7 +4,7 @@ test-install: npm install --no-fund test-run: - ./node_modules/.bin/mocha -t 10000 + npx mocha -t 10000 find-flakey-tests: echo "Running test-run infinately" diff --git a/internal/config/config_reloader.go b/internal/config/config_reloader.go index 5042d12..c33f91a 100644 --- a/internal/config/config_reloader.go +++ b/internal/config/config_reloader.go @@ -4,9 +4,10 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - log "github.com/sirupsen/logrus" "os" - "path" + "path/filepath" + + log "github.com/sirupsen/logrus" "github.com/spf13/viper" ) @@ -38,7 +39,7 @@ func Reload(cfg *Config) { metricConfigReloadedCount.Inc() metricConfigActionCount.Set(float64(len(cfg.Actions))) - cfg.SetDir(path.Dir(viper.ConfigFileUsed())) + cfg.SetDir(filepath.Dir(viper.ConfigFileUsed())) cfg.Sanitize() for _, l := range listeners {