2014-12-05 20:45:49 +00:00
|
|
|
package restic_test
|
2014-08-04 18:47:04 +00:00
|
|
|
|
|
|
|
import (
|
2022-06-12 12:38:19 +00:00
|
|
|
"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
|
|
|
|
2022-06-12 12:38:19 +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
|
|
|
)
|
|
|
|
|
2015-04-30 00:59:06 +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
|
|
|
}
|
2021-07-15 01:38:15 +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")
|
|
|
|
}
|
2022-06-12 12:38:19 +00:00
|
|
|
|
|
|
|
func TestLoadJSONUnpacked(t *testing.T) {
|
|
|
|
repository.TestAllVersions(t, testLoadJSONUnpacked)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testLoadJSONUnpacked(t *testing.T, version uint) {
|
|
|
|
repo, cleanup := repository.TestRepositoryWithVersion(t, version)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|