2025-09-23 14:01:09 -04:00
|
|
|
package data_test
|
2014-08-04 14:47:04 -04:00
|
|
|
|
|
|
|
|
import (
|
2022-06-12 08:38:19 -04:00
|
|
|
"context"
|
2014-08-04 14:47:04 -04:00
|
|
|
"testing"
|
2017-09-02 13:28:09 -04:00
|
|
|
"time"
|
2014-08-04 14:47:04 -04:00
|
|
|
|
2025-09-23 14:01:09 -04:00
|
|
|
"github.com/restic/restic/internal/data"
|
2022-06-12 08:38:19 -04:00
|
|
|
"github.com/restic/restic/internal/repository"
|
2017-10-02 09:06:39 -04:00
|
|
|
rtest "github.com/restic/restic/internal/test"
|
2014-08-04 14:47:04 -04:00
|
|
|
)
|
|
|
|
|
|
2015-04-29 20:59:06 -04:00
|
|
|
func TestNewSnapshot(t *testing.T) {
|
|
|
|
|
paths := []string{"/home/foobar"}
|
|
|
|
|
|
2025-09-23 14:01:09 -04:00
|
|
|
_, err := data.NewSnapshot(paths, nil, "foo", time.Now())
|
2017-10-02 09:06:39 -04:00
|
|
|
rtest.OK(t, err)
|
2014-08-04 14:47:04 -04:00
|
|
|
}
|
2021-07-14 21:38:15 -04:00
|
|
|
|
|
|
|
|
func TestTagList(t *testing.T) {
|
|
|
|
|
paths := []string{"/home/foobar"}
|
|
|
|
|
tags := []string{""}
|
|
|
|
|
|
2025-09-23 14:01:09 -04:00
|
|
|
sn, _ := data.NewSnapshot(paths, nil, "foo", time.Now())
|
2021-07-14 21:38:15 -04:00
|
|
|
|
|
|
|
|
r := sn.HasTags(tags)
|
|
|
|
|
rtest.Assert(t, r, "Failed to match untagged snapshot")
|
|
|
|
|
}
|
2022-06-12 08:38:19 -04:00
|
|
|
|
|
|
|
|
func TestLoadJSONUnpacked(t *testing.T) {
|
|
|
|
|
repository.TestAllVersions(t, testLoadJSONUnpacked)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testLoadJSONUnpacked(t *testing.T, version uint) {
|
2024-12-01 06:19:16 -05:00
|
|
|
repo, _, _ := repository.TestRepositoryWithVersion(t, version)
|
2022-06-12 08:38:19 -04:00
|
|
|
|
|
|
|
|
// archive a snapshot
|
2025-09-23 14:01:09 -04:00
|
|
|
sn := data.Snapshot{}
|
2022-06-12 08:38:19 -04:00
|
|
|
sn.Hostname = "foobar"
|
|
|
|
|
sn.Username = "test!"
|
|
|
|
|
|
2025-09-23 14:01:09 -04:00
|
|
|
id, err := data.SaveSnapshot(context.TODO(), repo, &sn)
|
2022-06-12 08:38:19 -04:00
|
|
|
rtest.OK(t, err)
|
|
|
|
|
|
|
|
|
|
// restore
|
2025-09-23 14:01:09 -04:00
|
|
|
sn2, err := data.LoadSnapshot(context.TODO(), repo, id)
|
2022-06-12 08:38:19 -04:00
|
|
|
rtest.OK(t, err)
|
|
|
|
|
|
|
|
|
|
rtest.Equals(t, sn.Hostname, sn2.Hostname)
|
|
|
|
|
rtest.Equals(t, sn.Username, sn2.Username)
|
|
|
|
|
}
|