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