restic/internal/restic/snapshot_test.go

52 lines
1.1 KiB
Go
Raw Permalink Normal View History

2014-12-05 20:45:49 +00:00
package restic_test
2014-08-04 18:47:04 +00:00
import (
"context"
2014-08-04 18:47:04 +00:00
"testing"
2017-09-02 17:28:09 +00:00
"time"
2014-08-04 18:47:04 +00:00
"github.com/restic/restic/internal/repository"
2017-07-24 15:42:25 +00:00
"github.com/restic/restic/internal/restic"
2017-10-02 13:06:39 +00:00
rtest "github.com/restic/restic/internal/test"
2014-08-04 18:47:04 +00:00
)
func TestNewSnapshot(t *testing.T) {
paths := []string{"/home/foobar"}
2017-09-02 17:28:09 +00:00
_, err := restic.NewSnapshot(paths, nil, "foo", time.Now())
2017-10-02 13:06:39 +00:00
rtest.OK(t, err)
2014-08-04 18:47:04 +00:00
}
func TestTagList(t *testing.T) {
paths := []string{"/home/foobar"}
tags := []string{""}
sn, _ := restic.NewSnapshot(paths, nil, "foo", time.Now())
r := sn.HasTags(tags)
rtest.Assert(t, r, "Failed to match untagged snapshot")
}
func TestLoadJSONUnpacked(t *testing.T) {
repository.TestAllVersions(t, testLoadJSONUnpacked)
}
func testLoadJSONUnpacked(t *testing.T, version uint) {
repo := repository.TestRepositoryWithVersion(t, version)
// archive a snapshot
sn := restic.Snapshot{}
sn.Hostname = "foobar"
sn.Username = "test!"
id, err := restic.SaveSnapshot(context.TODO(), repo, &sn)
rtest.OK(t, err)
// restore
sn2, err := restic.LoadSnapshot(context.TODO(), repo, id)
rtest.OK(t, err)
rtest.Equals(t, sn.Hostname, sn2.Hostname)
rtest.Equals(t, sn.Username, sn2.Username)
}