2
2
mirror of https://github.com/octoleo/restic.git synced 2024-10-31 19:02:32 +00:00
restic/cmd/restic/cmd_list_integration_test.go

45 lines
977 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(), cmdList, 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
}