瀏覽代碼

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 <wushuzh@outlook.com>
wushuzh 1 年之前
父節點
當前提交
ffcd19e748
共有 3 個文件被更改,包括 7 次插入5 次删除
  1. 2 1
      Makefile
  2. 1 1
      integration-tests/Makefile
  3. 4 3
      internal/config/config_reloader.go

+ 2 - 1
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
 

+ 1 - 1
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"

+ 4 - 3
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 {