From 17258bcd717f81ca5cc1a7082936c12e6a920ee6 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Thu, 25 Sep 2025 11:22:00 +0200 Subject: [PATCH 01/11] add fsbackup backend_config_based.go and the test cases --- pkg/source/fsbackup/backend_config_based.go | 56 +++++++++++++ .../fsbackup/backend_config_based_test.go | 84 +++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 pkg/source/fsbackup/backend_config_based.go create mode 100644 pkg/source/fsbackup/backend_config_based_test.go diff --git a/pkg/source/fsbackup/backend_config_based.go b/pkg/source/fsbackup/backend_config_based.go new file mode 100644 index 0000000..c869a57 --- /dev/null +++ b/pkg/source/fsbackup/backend_config_based.go @@ -0,0 +1,56 @@ +package fsbackup + +import ( + "context" + "fmt" + "os" + + "github.com/pkg/errors" +) + +type Options struct { + Path string `validate:"min=1"` +} + +type ConfigBasedBackend struct { + cfg *Config +} + +func NewConfigBasedBackend() (*ConfigBasedBackend, error) { + config := &Config{ + Options: &Options{}, + } + + if err := config.InitFromViper(); err != nil { + return nil, err + } + + return &ConfigBasedBackend{cfg: config}, nil +} + +func (b *ConfigBasedBackend) CreateBackup(_ context.Context) error { + path := b.cfg.Options.Path + + info, err := os.Stat(path) + if err != nil { + return errors.WithStack(err) + } + + if !info.IsDir() { + return errors.WithStack(fmt.Errorf("configured path %s is not a directory", path)) + } + + return nil +} + +func (b *ConfigBasedBackend) GetBackupPath() string { + return b.cfg.Options.Path +} + +func (b *ConfigBasedBackend) GetHostname() string { + return b.cfg.HostName +} + +func (b *ConfigBasedBackend) CleanUp() error { + return nil +} diff --git a/pkg/source/fsbackup/backend_config_based_test.go b/pkg/source/fsbackup/backend_config_based_test.go new file mode 100644 index 0000000..551f610 --- /dev/null +++ b/pkg/source/fsbackup/backend_config_based_test.go @@ -0,0 +1,84 @@ +package fsbackup + +import ( + "bytes" + "context" + "fmt" + "os" + "path/filepath" + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/require" +) + +func loadConfig(t *testing.T, path, host string) { + t.Helper() + + viper.Reset() + viper.SetConfigType("yaml") + config := fmt.Sprintf( + ` +fsbackup: + options: + path: %s + hostName: %s +`, path, host, + ) + + err := viper.ReadConfig(bytes.NewBufferString(config)) + require.NoError(t, err) +} + +func TestCreateBackup_PathExists(t *testing.T) { + t.Parallel() + + dir := t.TempDir() + host := "fsbackup-test-host" + + loadConfig(t, dir, host) + + backend, err := NewConfigBasedBackend() + require.NoError(t, err) + + err = backend.CreateBackup(context.Background()) + require.NoError(t, err) + + require.Equal(t, dir, backend.GetBackupPath()) + require.Equal(t, host, backend.GetHostname()) +} + +func TestCreateBackup_PathMissing(t *testing.T) { + t.Parallel() + + missingDir := filepath.Join(t.TempDir(), "missing") + host := "fsbackup-missing-test" + + loadConfig(t, missingDir, host) + + backend, err := NewConfigBasedBackend() + require.NoError(t, err) + + err = backend.CreateBackup(context.Background()) + require.Error(t, err) +} + +func TestCleanUp_NoOp(t *testing.T) { + t.Parallel() + + dir := t.TempDir() + + loadConfig(t, dir, "fsbackup-cleanup-host") + + backend, err := NewConfigBasedBackend() + require.NoError(t, err) + + err = backend.CreateBackup(context.Background()) + require.NoError(t, err) + + err = backend.CleanUp() + require.NoError(t, err) + + _, statErr := os.Stat(dir) + require.NoError(t, statErr) +} From ae91d75e5745ac6470ed6594e2d91b3b3ff9bb92 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Thu, 25 Sep 2025 11:22:26 +0200 Subject: [PATCH 02/11] add fsbackup to the known backup kinds in backup.go --- pkg/source/backup.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/source/backup.go b/pkg/source/backup.go index 70e20ad..7a9b706 100644 --- a/pkg/source/backup.go +++ b/pkg/source/backup.go @@ -12,6 +12,7 @@ import ( log "github.com/sirupsen/logrus" + "github.com/mittwald/brudi/pkg/source/fsbackup" "github.com/mittwald/brudi/pkg/source/mongodump" "github.com/mittwald/brudi/pkg/source/mysqldump" "github.com/mittwald/brudi/pkg/source/redisdump" @@ -29,6 +30,8 @@ func getGenericBackendForKind(kind string) (Generic, error) { return redisdump.NewConfigBasedBackend() case tar.Kind: return tar.NewConfigBasedBackend() + case fsbackup.Kind: + return fsbackup.NewConfigBasedBackend() default: return nil, fmt.Errorf("unsupported kind '%s'", kind) } From ccfdd81668d29c99380520c2d46e309921fcc4d7 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Thu, 25 Sep 2025 11:23:01 +0200 Subject: [PATCH 03/11] add integration test for fsbackup --- test/pkg/source/fsbackup/fsbackup_test.go | 92 +++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 test/pkg/source/fsbackup/fsbackup_test.go diff --git a/test/pkg/source/fsbackup/fsbackup_test.go b/test/pkg/source/fsbackup/fsbackup_test.go new file mode 100644 index 0000000..bad41c6 --- /dev/null +++ b/test/pkg/source/fsbackup/fsbackup_test.go @@ -0,0 +1,92 @@ +package fsbackup_test + +import ( + "bytes" + "context" + "fmt" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/mittwald/brudi/pkg/source" + "github.com/mittwald/brudi/pkg/source/fsbackup" + commons "github.com/mittwald/brudi/test/pkg/source/internal" + "github.com/spf13/viper" + "github.com/stretchr/testify/suite" +) + +type FSBackupSuite struct { + suite.Suite +} + +func (s *FSBackupSuite) SetupTest() { + commons.TestSetup() +} + +func (s *FSBackupSuite) TearDownTest() { + viper.Reset() +} + +func (s *FSBackupSuite) TestResticBackupDirectory() { + ctx := context.Background() + + resticContainer, err := commons.NewTestContainerSetup(ctx, &commons.ResticReq, commons.ResticPort) + s.Require().NoError(err) + defer func() { + resticErr := resticContainer.Container.Terminate(ctx) + if resticErr != nil { + s.T().Logf("failed to terminate restic container: %v", resticErr) + } + }() + + sourceDir := s.T().TempDir() + restoreDir := s.T().TempDir() + host := "fsbackup-restic-host" + + filePath := filepath.Join(sourceDir, "sample.txt") + fileContent := []byte("fsbackup restic content") + err = os.WriteFile(filePath, fileContent, 0o600) + s.Require().NoError(err) + + config := createFSBackupConfig(host, sourceDir, resticContainer.Address, resticContainer.Port) + err = viper.ReadConfig(bytes.NewBuffer(config)) + s.Require().NoError(err) + + err = source.DoBackupForKind(ctx, fsbackup.Kind, false, true, false, false) + s.Require().NoError(err) + + err = commons.DoResticRestore(ctx, resticContainer, restoreDir) + s.Require().NoError(err) + + relativeSourcePath := strings.TrimPrefix(sourceDir, string(os.PathSeparator)) + restoredFilePath := filepath.Join(restoreDir, relativeSourcePath, "sample.txt") + + restoredContent, err := os.ReadFile(restoredFilePath) + s.Require().NoError(err) + s.Equal(fileContent, restoredContent) +} + +func TestFSBackupSuite(t *testing.T) { + suite.Run(t, new(FSBackupSuite)) +} + +func createFSBackupConfig(host, path, resticIP, resticPort string) []byte { + return []byte(fmt.Sprintf( + ` +fsbackup: + options: + path: %s + hostName: %s +restic: + global: + flags: + repo: rest:http://%s:%s/ + restore: + flags: + path: %s + target: "/" + id: "latest" +`, path, host, resticIP, resticPort, path, + )) +} From 7946319d40dc2b93c4ada8e0d6d14a0dd1f6abd8 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Thu, 25 Sep 2025 11:23:24 +0200 Subject: [PATCH 04/11] add the fsbackup brudi command --- cmd/fsbackup.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 cmd/fsbackup.go diff --git a/cmd/fsbackup.go b/cmd/fsbackup.go new file mode 100644 index 0000000..08bc45d --- /dev/null +++ b/cmd/fsbackup.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "context" + + "github.com/mittwald/brudi/pkg/source" + "github.com/mittwald/brudi/pkg/source/fsbackup" + + "github.com/spf13/cobra" +) + +var ( + fsbackupCmd = &cobra.Command{ + Use: "fsbackup", + Short: "Backs up directories directly with restic", + Long: "Backs up configured directories using restic without creating intermediate archives.", + Run: func(cmd *cobra.Command, args []string) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + if err := source.DoBackupForKind(ctx, fsbackup.Kind, cleanup, useRestic, useResticForget, useResticPrune); err != nil { + panic(err) + } + }, + } +) + +func init() { + rootCmd.AddCommand(fsbackupCmd) +} From c2cd02ac6f2c6b91a303aba20616ba457feb1cb6 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Thu, 25 Sep 2025 11:24:23 +0200 Subject: [PATCH 05/11] create the fsrestore config --- pkg/source/fsrestore/config.go | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pkg/source/fsrestore/config.go diff --git a/pkg/source/fsrestore/config.go b/pkg/source/fsrestore/config.go new file mode 100644 index 0000000..77d21e2 --- /dev/null +++ b/pkg/source/fsrestore/config.go @@ -0,0 +1,35 @@ +package fsrestore + +import ( + "os" + + "github.com/pkg/errors" + + "github.com/mittwald/brudi/pkg/config" +) + +const ( + // Kind identifies the fsrestore backend in configuration. + Kind = "fsrestore" +) + +type Config struct { + Options *Options + HostName string `validate:"min=1"` +} + +func (c *Config) InitFromViper() error { + err := config.InitializeStructFromViper(Kind, c) + if err != nil { + return errors.WithStack(err) + } + + if c.HostName == "" { + c.HostName, err = os.Hostname() + if err != nil { + return errors.WithStack(err) + } + } + + return config.Validate(c) +} From 5416d2110665cfc3588ecb7238a1e39f1699a96c Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Thu, 25 Sep 2025 11:24:52 +0200 Subject: [PATCH 06/11] create the backend_config_based.go and test cases for fsrestore --- pkg/source/fsrestore/backend_config_based.go | 39 +++++++++++ .../fsrestore/backend_config_based_test.go | 65 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 pkg/source/fsrestore/backend_config_based.go create mode 100644 pkg/source/fsrestore/backend_config_based_test.go diff --git a/pkg/source/fsrestore/backend_config_based.go b/pkg/source/fsrestore/backend_config_based.go new file mode 100644 index 0000000..6cd33c9 --- /dev/null +++ b/pkg/source/fsrestore/backend_config_based.go @@ -0,0 +1,39 @@ +package fsrestore + +import "context" + +type Options struct { + Path string `validate:"min=1"` +} + +type ConfigBasedBackend struct { + cfg *Config +} + +func NewConfigBasedBackend() (*ConfigBasedBackend, error) { + config := &Config{ + Options: &Options{}, + } + + if err := config.InitFromViper(); err != nil { + return nil, err + } + + return &ConfigBasedBackend{cfg: config}, nil +} + +func (b *ConfigBasedBackend) RestoreBackup(context.Context) error { + return nil +} + +func (b *ConfigBasedBackend) GetBackupPath() string { + return b.cfg.Options.Path +} + +func (b *ConfigBasedBackend) GetHostname() string { + return b.cfg.HostName +} + +func (b *ConfigBasedBackend) CleanUp() error { + return nil +} diff --git a/pkg/source/fsrestore/backend_config_based_test.go b/pkg/source/fsrestore/backend_config_based_test.go new file mode 100644 index 0000000..190b407 --- /dev/null +++ b/pkg/source/fsrestore/backend_config_based_test.go @@ -0,0 +1,65 @@ +package fsrestore + +import ( + "bytes" + "context" + "fmt" + "os" + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/require" +) + +func loadConfig(t *testing.T, path, host string) { + t.Helper() + + viper.Reset() + viper.SetConfigType("yaml") + config := fmt.Sprintf( + ` +fsrestore: + options: + path: %s + hostName: %s +`, path, host, + ) + + err := viper.ReadConfig(bytes.NewBufferString(config)) + require.NoError(t, err) +} + +func TestRestoreBackup_NoOp(t *testing.T) { + t.Parallel() + + dir := t.TempDir() + host, err := os.Hostname() + require.NoError(t, err) + + loadConfig(t, dir, host) + + backend, err := NewConfigBasedBackend() + require.NoError(t, err) + + err = backend.RestoreBackup(context.Background()) + require.NoError(t, err) + require.Equal(t, dir, backend.GetBackupPath()) + require.Equal(t, host, backend.GetHostname()) +} + +func TestCleanUp_NoOp(t *testing.T) { + t.Parallel() + + dir := t.TempDir() + + loadConfig(t, dir, "fsrestore-cleanup-host") + + backend, err := NewConfigBasedBackend() + require.NoError(t, err) + + err = backend.CleanUp() + require.NoError(t, err) + + _, statErr := os.Stat(dir) + require.NoError(t, statErr) +} From 6cf44404b0d8e749bf139d697059b6f7bca6aab2 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Thu, 25 Sep 2025 11:25:14 +0200 Subject: [PATCH 07/11] add the fsrestore kind to known restore kinds in restore.go --- pkg/source/restore.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/source/restore.go b/pkg/source/restore.go index 1ccf90f..a95f8a7 100644 --- a/pkg/source/restore.go +++ b/pkg/source/restore.go @@ -7,6 +7,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/mittwald/brudi/pkg/restic" + "github.com/mittwald/brudi/pkg/source/fsrestore" "github.com/mittwald/brudi/pkg/source/mongorestore" "github.com/mittwald/brudi/pkg/source/mysqlrestore" "github.com/mittwald/brudi/pkg/source/pgrestore" @@ -26,6 +27,8 @@ func getGenericRestoreBackendForKind(kind string) (GenericRestore, error) { return tarrestore.NewConfigBasedBackend() case psql.Kind: return psql.NewConfigBasedBackend() + case fsrestore.Kind: + return fsrestore.NewConfigBasedBackend() default: return nil, fmt.Errorf("unsupported kind '%s'", kind) } From c922ab967c0195a1504a7e21f746c1d757899d2c Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Thu, 25 Sep 2025 11:25:27 +0200 Subject: [PATCH 08/11] create the fsrestore command --- cmd/fsrestore.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 cmd/fsrestore.go diff --git a/cmd/fsrestore.go b/cmd/fsrestore.go new file mode 100644 index 0000000..af86dea --- /dev/null +++ b/cmd/fsrestore.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "context" + + "github.com/mittwald/brudi/pkg/source" + "github.com/mittwald/brudi/pkg/source/fsrestore" + + "github.com/spf13/cobra" +) + +var ( + fsrestoreCmd = &cobra.Command{ + Use: "fsrestore", + Short: "Restores directories directly from restic", + Long: "Restores directories from restic snapshots without additional processing.", + Run: func(cmd *cobra.Command, args []string) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + if err := source.DoRestoreForKind(ctx, fsrestore.Kind, cleanup, useRestic); err != nil { + panic(err) + } + }, + } +) + +func init() { + rootCmd.AddCommand(fsrestoreCmd) +} From 3fc42f5b303e773ef46d8427ee4cf486975d4607 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Thu, 25 Sep 2025 11:25:38 +0200 Subject: [PATCH 09/11] add integration test for fsrestore --- test/pkg/source/fsrestore/fsrestore_test.go | 120 ++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 test/pkg/source/fsrestore/fsrestore_test.go diff --git a/test/pkg/source/fsrestore/fsrestore_test.go b/test/pkg/source/fsrestore/fsrestore_test.go new file mode 100644 index 0000000..8a8583b --- /dev/null +++ b/test/pkg/source/fsrestore/fsrestore_test.go @@ -0,0 +1,120 @@ +package fsrestore_test + +import ( + "bytes" + "context" + "fmt" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/mittwald/brudi/pkg/source" + "github.com/mittwald/brudi/pkg/source/fsbackup" + "github.com/mittwald/brudi/pkg/source/fsrestore" + commons "github.com/mittwald/brudi/test/pkg/source/internal" + "github.com/spf13/viper" + "github.com/stretchr/testify/suite" +) + +type FSRestoreSuite struct { + suite.Suite +} + +func (s *FSRestoreSuite) SetupTest() { + commons.TestSetup() +} + +func (s *FSRestoreSuite) TearDownTest() { + viper.Reset() +} + +func (s *FSRestoreSuite) TestResticRestoreDirectory() { + ctx := context.Background() + + resticContainer, err := commons.NewTestContainerSetup(ctx, &commons.ResticReq, commons.ResticPort) + s.Require().NoError(err) + defer func() { + resticErr := resticContainer.Container.Terminate(ctx) + if resticErr != nil { + s.T().Logf("failed to terminate restic container: %v", resticErr) + } + }() + + sourceDir := s.T().TempDir() + host := "fsrestore-restic-host" + + filePath := filepath.Join(sourceDir, "sample.txt") + fileContent := []byte("fsrestore restic content") + err = os.WriteFile(filePath, fileContent, 0o600) + s.Require().NoError(err) + + backupConfig := createFSBackupConfig(host, sourceDir, resticContainer.Address, resticContainer.Port) + err = viper.ReadConfig(bytes.NewBuffer(backupConfig)) + s.Require().NoError(err) + + err = source.DoBackupForKind(ctx, fsbackup.Kind, false, true, false, false) + s.Require().NoError(err) + + restoreRoot := s.T().TempDir() + + viper.Reset() + commons.TestSetup() + + restoreConfig := createFSRestoreConfig(host, sourceDir, restoreRoot, resticContainer.Address, resticContainer.Port) + err = viper.ReadConfig(bytes.NewBuffer(restoreConfig)) + s.Require().NoError(err) + + err = source.DoRestoreForKind(ctx, fsrestore.Kind, false, true) + s.Require().NoError(err) + + relativeSourcePath := strings.TrimPrefix(sourceDir, string(os.PathSeparator)) + restoredFile := filepath.Join(restoreRoot, relativeSourcePath, "sample.txt") + + restoredContent, err := os.ReadFile(restoredFile) + s.Require().NoError(err) + s.Equal(fileContent, restoredContent) +} + +func TestFSRestoreSuite(t *testing.T) { + suite.Run(t, new(FSRestoreSuite)) +} + +func createFSBackupConfig(host, path, resticIP, resticPort string) []byte { + return []byte(fmt.Sprintf( + ` +fsbackup: + options: + path: %s + hostName: %s +restic: + global: + flags: + repo: rest:http://%s:%s/ + restore: + flags: + path: %s + target: "/" + id: "latest" +`, path, host, resticIP, resticPort, path, + )) +} + +func createFSRestoreConfig(host, path, target, resticIP, resticPort string) []byte { + return []byte(fmt.Sprintf( + ` +fsrestore: + options: + path: %s + hostName: %s +restic: + global: + flags: + repo: rest:http://%s:%s/ + restore: + flags: + target: %s + id: "latest" +`, path, host, resticIP, resticPort, target, + )) +} From 9c87e1b7d69ce2c7719e5f649513937fba50a844 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Thu, 25 Sep 2025 11:28:52 +0200 Subject: [PATCH 10/11] Update README.md to add fsbackup and fsrestore commands --- README.md | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 703ed47..7707a3b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,8 @@ Besides creating backups, `brudi` can also be used to restore your data from bac - [CLI](#cli) - [Docker](#docker) - [Configuration](#configuration) - - [Sources](#sources) + - [Sources](#sources) + - [FsBackup](#fsbackup) - [Tar](#tar) - [MySQLDump](#mysqldump) - [MongoDump](#mongodump) @@ -29,6 +30,7 @@ Besides creating backups, `brudi` can also be used to restore your data from bac - [Sensitive data: Environment variables](#sensitive-data-environment-variables) - [Gzip support for binaries without native gzip support](#gzip-support-for-binaries-without-native-gzip-support) - [Restoring from backup](#restoring-from-backup) + - [FsRestore](#fsrestore) - [TarRestore](#tarrestore) - [MongoRestore](#mongorestore) - [MySQLRestore](#mysqlrestore) @@ -65,6 +67,8 @@ Usage: Available Commands: help Help about any command + fsbackup Backs up directories directly. Use it with the --restic flag. + fsrestore Restores directories directly. Use it with the --restic flag. mongodump Creates a mongodump of your desired server mongorestore Restores a server from a mongodump mysqldump Creates a mysqldump of your desired server @@ -127,6 +131,19 @@ In case the same config file has been provided more than once, only the first in #### Sources +##### FsBackup + +```yaml +fsbackup: + options: + path: /srv/data + hostName: autoGeneratedIfEmpty +``` + +Running: `brudi fsbackup -c ${HOME}/.brudi.yml --restic` + +The `fsbackup` command validates that the configured directory exists and then hands it over to `restic backup` without creating intermediate archives. + ##### Tar ```yaml @@ -343,6 +360,24 @@ mysqlrestore: #### Restoring from backup +##### FsRestore + +```yaml +fsrestore: + options: + path: /srv/data + hostName: autoGeneratedIfEmpty +restic: + restore: + flags: + target: /restore-target + id: "latest" +``` + +Running: `brudi fsrestore -c ${HOME}/.brudi.yml --restic` + +`fsrestore` triggers `restic restore` for the stored directory path without any additional processing. The configured `target` controls where the restored files are written. + ##### TarRestore ```yaml @@ -494,6 +529,7 @@ It is also possible to specify concrete snapshot-ids instead of `latest`. ### Source backup methods +- [x] `fsbackup` - [x] `mysqldump` - [x] `mongodump` - [x] `tar` @@ -502,6 +538,7 @@ It is also possible to specify concrete snapshot-ids instead of `latest`. ### Restore backup methods +- [x] `fsrestore` - [x] `mysqlrestore` - [x] `mongorestore` - [x] `tarrestore` From 7ebe3c5e16b4b862a897b861ee62e8929135af94 Mon Sep 17 00:00:00 2001 From: Levent Koch Date: Thu, 25 Sep 2025 11:53:38 +0200 Subject: [PATCH 11/11] remove unnecessary tests --- .../fsbackup/backend_config_based_test.go | 84 ------------------- .../fsrestore/backend_config_based_test.go | 65 -------------- 2 files changed, 149 deletions(-) delete mode 100644 pkg/source/fsbackup/backend_config_based_test.go delete mode 100644 pkg/source/fsrestore/backend_config_based_test.go diff --git a/pkg/source/fsbackup/backend_config_based_test.go b/pkg/source/fsbackup/backend_config_based_test.go deleted file mode 100644 index 551f610..0000000 --- a/pkg/source/fsbackup/backend_config_based_test.go +++ /dev/null @@ -1,84 +0,0 @@ -package fsbackup - -import ( - "bytes" - "context" - "fmt" - "os" - "path/filepath" - "testing" - - "github.com/spf13/viper" - "github.com/stretchr/testify/require" -) - -func loadConfig(t *testing.T, path, host string) { - t.Helper() - - viper.Reset() - viper.SetConfigType("yaml") - config := fmt.Sprintf( - ` -fsbackup: - options: - path: %s - hostName: %s -`, path, host, - ) - - err := viper.ReadConfig(bytes.NewBufferString(config)) - require.NoError(t, err) -} - -func TestCreateBackup_PathExists(t *testing.T) { - t.Parallel() - - dir := t.TempDir() - host := "fsbackup-test-host" - - loadConfig(t, dir, host) - - backend, err := NewConfigBasedBackend() - require.NoError(t, err) - - err = backend.CreateBackup(context.Background()) - require.NoError(t, err) - - require.Equal(t, dir, backend.GetBackupPath()) - require.Equal(t, host, backend.GetHostname()) -} - -func TestCreateBackup_PathMissing(t *testing.T) { - t.Parallel() - - missingDir := filepath.Join(t.TempDir(), "missing") - host := "fsbackup-missing-test" - - loadConfig(t, missingDir, host) - - backend, err := NewConfigBasedBackend() - require.NoError(t, err) - - err = backend.CreateBackup(context.Background()) - require.Error(t, err) -} - -func TestCleanUp_NoOp(t *testing.T) { - t.Parallel() - - dir := t.TempDir() - - loadConfig(t, dir, "fsbackup-cleanup-host") - - backend, err := NewConfigBasedBackend() - require.NoError(t, err) - - err = backend.CreateBackup(context.Background()) - require.NoError(t, err) - - err = backend.CleanUp() - require.NoError(t, err) - - _, statErr := os.Stat(dir) - require.NoError(t, statErr) -} diff --git a/pkg/source/fsrestore/backend_config_based_test.go b/pkg/source/fsrestore/backend_config_based_test.go deleted file mode 100644 index 190b407..0000000 --- a/pkg/source/fsrestore/backend_config_based_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package fsrestore - -import ( - "bytes" - "context" - "fmt" - "os" - "testing" - - "github.com/spf13/viper" - "github.com/stretchr/testify/require" -) - -func loadConfig(t *testing.T, path, host string) { - t.Helper() - - viper.Reset() - viper.SetConfigType("yaml") - config := fmt.Sprintf( - ` -fsrestore: - options: - path: %s - hostName: %s -`, path, host, - ) - - err := viper.ReadConfig(bytes.NewBufferString(config)) - require.NoError(t, err) -} - -func TestRestoreBackup_NoOp(t *testing.T) { - t.Parallel() - - dir := t.TempDir() - host, err := os.Hostname() - require.NoError(t, err) - - loadConfig(t, dir, host) - - backend, err := NewConfigBasedBackend() - require.NoError(t, err) - - err = backend.RestoreBackup(context.Background()) - require.NoError(t, err) - require.Equal(t, dir, backend.GetBackupPath()) - require.Equal(t, host, backend.GetHostname()) -} - -func TestCleanUp_NoOp(t *testing.T) { - t.Parallel() - - dir := t.TempDir() - - loadConfig(t, dir, "fsrestore-cleanup-host") - - backend, err := NewConfigBasedBackend() - require.NoError(t, err) - - err = backend.CleanUp() - require.NoError(t, err) - - _, statErr := os.Stat(dir) - require.NoError(t, statErr) -}