From a2046b9c8f24e31e94dde5b2910f79059dadbf17 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sun, 5 Apr 2026 23:26:45 +0200 Subject: [PATCH] fix test --- internal/location_test.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/internal/location_test.go b/internal/location_test.go index 911ae7b..46d2874 100644 --- a/internal/location_test.go +++ b/internal/location_test.go @@ -1,6 +1,14 @@ package internal -import "testing" +import ( + "os" + "path" + "sync" + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/assert" +) func TestGetType(t *testing.T) { @@ -100,12 +108,28 @@ func TestLocationBackupWithMock(t *testing.T) { // Inject mock mock := &MockExecutor{ ExecuteResticFunc: func(options ExecuteOptions, args ...string) (int, string, error) { - assertEqual(t, args[0], "backup") + assert.Equal(t, "backup", args[0]) return 0, "success", nil }, } DefaultExecutor = mock + // Setup dummy config + workDir := t.TempDir() + configFile := path.Join(workDir, ".autorestic.yml") + err := os.WriteFile(configFile, []byte("version: 2"), 0644) + assert.NoError(t, err) + + viper.Reset() + viper.SetConfigFile(configFile) + viper.Set("version", 2) + // Register test-backend + viper.Set("backends.test-backend.type", "local") + viper.Set("backends.test-backend.path", workDir) + + config = nil + once = sync.Once{} + loc := Location{ name: "test-location", To: []string{"test-backend"},