Skip to content

Commit fe336ff

Browse files
Fix and unit tests for #91
1 parent dde49e8 commit fe336ff

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

examples/dev.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,13 @@ escape:
216216
retention:
217217
after-backup: true
218218

219+
nobackup:
220+
initialize: false
221+
repository: /Volumes/RAMDisk/{{ .Profile.Name }}
222+
password-command: echo test
223+
status-file: /Volumes/RAMDisk/status.json
224+
225+
copy:
226+
initialize: false
227+
repository: /Volumes/RAMDisk/{{ .Profile.Name }}_copy
228+
password-command2: echo test

wrapper.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,14 @@ func (r *resticWrapper) runCommand(command string) error {
315315
rCommand := r.prepareCommand(command, args)
316316

317317
if command == constants.CommandBackup && len(r.progress) > 0 {
318-
if r.profile.Backup.ExtendedStatus {
319-
rCommand.scanOutput = shell.ScanBackupJson
320-
} else if !term.OsStdoutIsTerminal() {
321-
// restic detects its output is not a terminal and no longer displays the progress.
322-
// Scan plain output only if resticprofile is not run from a terminal (e.g. schedule)
323-
rCommand.scanOutput = shell.ScanBackupPlain
318+
if r.profile.Backup != nil {
319+
if r.profile.Backup.ExtendedStatus {
320+
rCommand.scanOutput = shell.ScanBackupJson
321+
} else if !term.OsStdoutIsTerminal() {
322+
// restic detects its output is not a terminal and no longer displays the progress.
323+
// Scan plain output only if resticprofile is not run from a terminal (e.g. schedule)
324+
rCommand.scanOutput = shell.ScanBackupPlain
325+
}
324326
}
325327
}
326328

wrapper_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/creativeprojects/resticprofile/config"
1515
"github.com/creativeprojects/resticprofile/constants"
1616
"github.com/creativeprojects/resticprofile/progress"
17+
"github.com/creativeprojects/resticprofile/status"
1718
"github.com/creativeprojects/resticprofile/term"
1819
"github.com/stretchr/testify/assert"
1920
"github.com/stretchr/testify/require"
@@ -341,6 +342,22 @@ func TestBackupWithError(t *testing.T) {
341342
require.Error(t, err)
342343
}
343344

345+
func TestBackupWithNoConfiguration(t *testing.T) {
346+
profile := config.NewProfile(nil, "name")
347+
wrapper := newResticWrapper(mockBinary, false, profile, "", []string{"--exit", "1"}, nil)
348+
err := wrapper.runCommand("backup")
349+
require.Error(t, err)
350+
}
351+
352+
func TestBackupWithNoConfigurationButStatusFile(t *testing.T) {
353+
profile := config.NewProfile(nil, "name")
354+
profile.StatusFile = "status.json"
355+
wrapper := newResticWrapper(mockBinary, false, profile, "", []string{"--exit", "1"}, nil)
356+
wrapper.addProgress(status.NewProgress(profile, status.NewStatus("status.json")))
357+
err := wrapper.runCommand("backup")
358+
require.Error(t, err)
359+
}
360+
344361
func TestBackupWithWarningAsError(t *testing.T) {
345362
profile := config.NewProfile(nil, "name")
346363
profile.Backup = &config.BackupSection{}

0 commit comments

Comments
 (0)