mirror of
https://github.com/restic/restic.git
synced 2026-06-27 11:04:17 +00:00
backup - show excluded files and directories in verbose mode - text/JSON (#21887)
This commit is contained in:
committed by
GitHub
parent
8d7679c831
commit
d30d6b6281
@@ -666,6 +666,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts global.Options, te
|
||||
arch.CompleteItem = progressReporter.CompleteItem
|
||||
arch.StartFile = progressReporter.StartFile
|
||||
arch.CompleteBlob = progressReporter.CompleteBlob
|
||||
arch.ExcludedItem = progressReporter.ExcludedItem
|
||||
|
||||
if opts.IgnoreInode {
|
||||
// --ignore-inode implies --ignore-ctime: on FUSE, the ctime is not
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -15,6 +18,7 @@ import (
|
||||
"github.com/restic/restic/internal/global"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
"github.com/restic/restic/internal/ui/backup"
|
||||
)
|
||||
|
||||
func testRunBackupAssumeFailure(t testing.TB, dir string, target []string, opts BackupOptions, gopts global.Options) error {
|
||||
@@ -30,6 +34,13 @@ func testRunBackupAssumeFailure(t testing.TB, dir string, target []string, opts
|
||||
})
|
||||
}
|
||||
|
||||
func testRunBackupOutput(t testing.TB, opts BackupOptions, gopts global.Options, target []string) ([]byte, error) {
|
||||
buf, err := withCaptureStdout(t, gopts, func(ctx context.Context, gopts global.Options) error {
|
||||
return runBackup(ctx, opts, gopts, gopts.Term, target)
|
||||
})
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
||||
func testRunBackup(t testing.TB, dir string, target []string, opts BackupOptions, gopts global.Options) {
|
||||
err := testRunBackupAssumeFailure(t, dir, target, opts, gopts)
|
||||
rtest.Assert(t, err == nil, "Error while backing up: %v", err)
|
||||
@@ -730,3 +741,40 @@ func TestBackupSkipIfUnchanged(t *testing.T) {
|
||||
|
||||
testRunCheck(t, env.gopts)
|
||||
}
|
||||
|
||||
func TestBackupExcludeWithOutput(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
|
||||
testSetupBackupData(t, env)
|
||||
backupOptions := BackupOptions{}
|
||||
backupOptions.Excludes = []string{"*.py"}
|
||||
|
||||
env.gopts.JSON = true
|
||||
env.gopts.Verbosity = 2
|
||||
output, err := testRunBackupOutput(t, backupOptions, env.gopts, []string{filepath.Join(env.testdata, "0", "for_cmd_ls")})
|
||||
rtest.OK(t, err)
|
||||
|
||||
foundExclude := false
|
||||
for _, line := range bytes.Split(output, []byte("\n")) {
|
||||
if len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
type MessageType struct {
|
||||
MessageType string `json:"message_type"` // any
|
||||
}
|
||||
var mType MessageType
|
||||
rtest.OK(t, json.Unmarshal(line, &mType))
|
||||
if mType.MessageType != "excluded_item" {
|
||||
continue
|
||||
}
|
||||
|
||||
var excludeLine backup.VerboseExclude
|
||||
rtest.OK(t, json.Unmarshal(line, &excludeLine))
|
||||
rtest.Assert(t, strings.Contains(excludeLine.Item, ".py"), "expected excluded pathname to be ending in .py, but contains %q",
|
||||
excludeLine.Item)
|
||||
foundExclude = true
|
||||
}
|
||||
rtest.Assert(t, foundExclude, "expected at least one excluded item, but found none")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user