2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-02 01:48:30 +00:00
restic/cmd/restic/cmd_snapshots_integration_test.go
2023-05-26 19:38:44 +02:00

33 lines
726 B
Go

package main
import (
"context"
"encoding/json"
"testing"
"github.com/restic/restic/internal/restic"
rtest "github.com/restic/restic/internal/test"
)
func testRunSnapshots(t testing.TB, gopts GlobalOptions) (newest *Snapshot, snapmap map[restic.ID]Snapshot) {
buf, err := withCaptureStdout(func() error {
gopts.JSON = true
opts := SnapshotOptions{}
return runSnapshots(context.TODO(), opts, gopts, []string{})
})
rtest.OK(t, err)
snapshots := []Snapshot{}
rtest.OK(t, json.Unmarshal(buf.Bytes(), &snapshots))
snapmap = make(map[restic.ID]Snapshot, len(snapshots))
for _, sn := range snapshots {
snapmap[*sn.ID] = sn
if newest == nil || sn.Time.After(newest.Time) {
newest = &sn
}
}
return
}