refactor: change configruation to yml

This commit is contained in:
2024-04-29 21:50:16 +02:00
parent 727b083e52
commit 5860f81aa2
13 changed files with 63 additions and 65 deletions

3
internal/watcher/testdata/config.yml vendored Normal file
View File

@@ -0,0 +1,3 @@
script_binary_path: "/bin/bash"
webhook_script_path: "testdata/test-script.sh"
file_to_watch_path: "testdata/test_monitor.txt"

View File

@@ -0,0 +1,2 @@
#!/bin/bash
echo "deploy script has been called"

View File

@@ -3,10 +3,11 @@ package watcher
import (
"context"
"errors"
"fmt"
"testing"
"time"
"gitea.urkob.com/urko/git-webhook-ci/kit/cfg"
"gitea.urkob.com/urko/git-webhook-ci/kit/config"
"gitea.urkob.com/urko/git-webhook-ci/pkg"
"github.com/fsnotify/fsnotify"
"github.com/stretchr/testify/require"
@@ -32,7 +33,7 @@ var (
binaryPath = ""
scriptPath = ""
executionMaxTimeout = time.Second * 2
config *cfg.Config
cfg *config.Config
events = []fsnotify.Event{
{
Name: "test event",
@@ -45,7 +46,7 @@ var (
}
)
func init() {
func TestMain(t *testing.M) {
mockDeploy = func(binaryPath, scriptPath string) error {
return nil
}
@@ -53,8 +54,16 @@ func init() {
mockErrorDeploy = func(binaryPath, scriptPath string) error {
return errIntentional
}
}
func LoadConfig(t *testing.T) {
t.Helper()
cf, err := config.LoadConfig("testdata/config.yaml")
if err != nil {
panic(fmt.Errorf("Error loading config: %w", err))
}
cfg = cf
config = cfg.NewConfig("../../.env")
}
func sendTestEvents(w *watcher) {
@@ -76,6 +85,7 @@ func newWatcherWithCtorError() *watcher {
}
func Test_NewNotifier(t *testing.T) {
LoadConfig(t)
require.NotNil(t, NewNotifier())
}
@@ -97,7 +107,7 @@ func Test_Close(t *testing.T) {
func Test_Monitor(t *testing.T) {
w := newWatcher()
err := w.Monitor(config.TestFileToWatchPath)
err := w.Monitor(cfg.FileToWatchPath)
require.NoError(t, err)
}