mirror of
https://github.com/octoleo/restic.git
synced 2024-11-13 08:46:33 +00:00
66103aea3d
Now, every command uses an options struct, which is passed to the run* function by the command.RunE method.
45 lines
968 B
Go
45 lines
968 B
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/restic/restic/internal/restic"
|
|
rtest "github.com/restic/restic/internal/test"
|
|
)
|
|
|
|
func testRunList(t testing.TB, tpe string, opts GlobalOptions) restic.IDs {
|
|
buf, err := withCaptureStdout(func() error {
|
|
return runList(context.TODO(), opts, []string{tpe})
|
|
})
|
|
rtest.OK(t, err)
|
|
return parseIDsFromReader(t, buf)
|
|
}
|
|
|
|
func parseIDsFromReader(t testing.TB, rd io.Reader) restic.IDs {
|
|
t.Helper()
|
|
IDs := restic.IDs{}
|
|
sc := bufio.NewScanner(rd)
|
|
|
|
for sc.Scan() {
|
|
id, err := restic.ParseID(sc.Text())
|
|
if err != nil {
|
|
t.Logf("parse id %v: %v", sc.Text(), err)
|
|
continue
|
|
}
|
|
|
|
IDs = append(IDs, id)
|
|
}
|
|
|
|
return IDs
|
|
}
|
|
|
|
func testListSnapshots(t testing.TB, opts GlobalOptions, expected int) restic.IDs {
|
|
t.Helper()
|
|
snapshotIDs := testRunList(t, "snapshots", opts)
|
|
rtest.Assert(t, len(snapshotIDs) == expected, "expected %v snapshot, got %v", expected, snapshotIDs)
|
|
return snapshotIDs
|
|
}
|