2023-05-06 08:37:17 +00:00
|
|
|
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 {
|
2023-05-07 20:06:39 +00:00
|
|
|
buf, err := withCaptureStdout(func() error {
|
2024-01-21 16:43:13 +00:00
|
|
|
return runList(context.TODO(), opts, []string{tpe})
|
2023-05-07 20:06:39 +00:00
|
|
|
})
|
|
|
|
rtest.OK(t, err)
|
2023-05-06 08:37:17 +00:00
|
|
|
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
|
|
|
|
}
|