mirror of
https://github.com/octoleo/restic.git
synced 2024-12-25 12:09:59 +00:00
Add integration test to make sure cmd_backup adds tags when required.
This commit is contained in:
parent
7238a3ee89
commit
edd5c8b44d
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -160,6 +161,33 @@ func testRunFind(t testing.TB, gopts GlobalOptions, pattern string) []string {
|
|||||||
return strings.Split(string(buf.Bytes()), "\n")
|
return strings.Split(string(buf.Bytes()), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testRunSnapshots(t testing.TB, gopts GlobalOptions) (*Snapshot, map[string]Snapshot) {
|
||||||
|
buf := bytes.NewBuffer(nil)
|
||||||
|
globalOptions.stdout = buf
|
||||||
|
globalOptions.JSON = true
|
||||||
|
defer func() {
|
||||||
|
globalOptions.stdout = os.Stdout
|
||||||
|
globalOptions.JSON = gopts.JSON
|
||||||
|
}()
|
||||||
|
|
||||||
|
opts := SnapshotOptions{}
|
||||||
|
|
||||||
|
OK(t, runSnapshots(opts, globalOptions, []string{}))
|
||||||
|
|
||||||
|
snapshots := []Snapshot{}
|
||||||
|
OK(t, json.Unmarshal(buf.Bytes(), &snapshots))
|
||||||
|
|
||||||
|
var newest *Snapshot
|
||||||
|
snapmap := make(map[string]Snapshot, len(snapshots))
|
||||||
|
for _, sn := range snapshots {
|
||||||
|
snapmap[sn.ID] = sn
|
||||||
|
if newest == nil || sn.Time.After(newest.Time) {
|
||||||
|
newest = &sn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newest, snapmap
|
||||||
|
}
|
||||||
|
|
||||||
func testRunForget(t testing.TB, gopts GlobalOptions, args ...string) {
|
func testRunForget(t testing.TB, gopts GlobalOptions, args ...string) {
|
||||||
opts := ForgetOptions{}
|
opts := ForgetOptions{}
|
||||||
OK(t, runForget(opts, gopts, args))
|
OK(t, runForget(opts, gopts, args))
|
||||||
@ -602,6 +630,31 @@ func TestIncrementalBackup(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBackupTags(t *testing.T) {
|
||||||
|
withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) {
|
||||||
|
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
||||||
|
testRunInit(t, gopts)
|
||||||
|
SetupTarTestFixture(t, env.testdata, datafile)
|
||||||
|
|
||||||
|
opts := BackupOptions{}
|
||||||
|
|
||||||
|
testRunBackup(t, []string{env.testdata}, opts, gopts)
|
||||||
|
testRunCheck(t, gopts)
|
||||||
|
newest, _ := testRunSnapshots(t, gopts)
|
||||||
|
Assert(t, newest != nil, "expected a new backup, got nil")
|
||||||
|
Assert(t, len(newest.Tags) == 0,
|
||||||
|
"expected no tags, got %v", newest.Tags)
|
||||||
|
|
||||||
|
opts.Tags = []string{"NL"}
|
||||||
|
testRunBackup(t, []string{env.testdata}, opts, gopts)
|
||||||
|
testRunCheck(t, gopts)
|
||||||
|
newest, _ = testRunSnapshots(t, gopts)
|
||||||
|
Assert(t, newest != nil, "expected a new backup, got nil")
|
||||||
|
Assert(t, len(newest.Tags) == 1 && newest.Tags[0] == "NL",
|
||||||
|
"expected one NL tag, got %v", newest.Tags)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testRunKeyListOtherIDs(t testing.TB, gopts GlobalOptions) []string {
|
func testRunKeyListOtherIDs(t testing.TB, gopts GlobalOptions) []string {
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user