From ce3acbd30a8638bb6b43e32029aae73a95a27869 Mon Sep 17 00:00:00 2001 From: Pauline Middelink Date: Thu, 11 May 2017 21:03:28 +0200 Subject: [PATCH] Remove unused SnapshotFilter and FilterSnapshots(). --- src/restic/snapshot_filter.go | 34 -------------- src/restic/snapshot_filter_test.go | 71 ------------------------------ 2 files changed, 105 deletions(-) diff --git a/src/restic/snapshot_filter.go b/src/restic/snapshot_filter.go index 69b9e44f8..559150a5e 100644 --- a/src/restic/snapshot_filter.go +++ b/src/restic/snapshot_filter.go @@ -25,40 +25,6 @@ func (sn Snapshots) Swap(i, j int) { sn[i], sn[j] = sn[j], sn[i] } -// SnapshotFilter configures criteria for filtering snapshots before an -// ExpirePolicy can be applied. -type SnapshotFilter struct { - Hostname string - Username string - Paths []string - Tags []string -} - -// FilterSnapshots returns the snapshots from s which match the filter f. -func FilterSnapshots(s Snapshots, f SnapshotFilter) (result Snapshots) { - for _, snap := range s { - if f.Hostname != "" && f.Hostname != snap.Hostname { - continue - } - - if f.Username != "" && f.Username != snap.Username { - continue - } - - if f.Paths != nil && !reflect.DeepEqual(f.Paths, snap.Paths) { - continue - } - - if !snap.HasTags(f.Tags) { - continue - } - - result = append(result, snap) - } - - return result -} - // ExpirePolicy configures which snapshots should be automatically removed. type ExpirePolicy struct { Last int // keep the last n snapshots diff --git a/src/restic/snapshot_filter_test.go b/src/restic/snapshot_filter_test.go index fbeef229d..c31eeab57 100644 --- a/src/restic/snapshot_filter_test.go +++ b/src/restic/snapshot_filter_test.go @@ -7,7 +7,6 @@ import ( "path/filepath" "reflect" "restic" - "sort" "testing" "time" ) @@ -21,76 +20,6 @@ func parseTimeUTC(s string) time.Time { return t.UTC() } -var testFilterSnapshots = restic.Snapshots{ - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-01 01:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, - {Hostname: "bar", Username: "testuser", Time: parseTimeUTC("2016-01-01 01:03:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-03 07:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, - {Hostname: "bar", Username: "testuser", Time: parseTimeUTC("2016-01-01 07:08:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 10:23:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 11:23:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:23:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:24:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"test"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:28:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"test"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 12:30:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"test", "foo", "bar"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-04 16:23:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"test", "test2"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-05 09:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"foo"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-06 08:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"fox"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-07 10:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"fox"}}, - {Hostname: "foo", Username: "root", Time: parseTimeUTC("2016-01-08 20:02:03"), Paths: []string{"/usr", "/sbin"}, Tags: []string{"foo"}}, - {Hostname: "foo", Username: "root", Time: parseTimeUTC("2016-01-09 21:02:03"), Paths: []string{"/usr", "/sbin"}, Tags: []string{"fox"}}, - {Hostname: "bar", Username: "root", Time: parseTimeUTC("2016-01-12 21:02:03"), Paths: []string{"/usr", "/sbin"}, Tags: []string{"foo"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-12 21:08:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"bar"}}, - {Hostname: "foo", Username: "testuser", Time: parseTimeUTC("2016-01-18 12:02:03"), Paths: []string{"/usr", "/bin"}, Tags: []string{"bar"}}, -} - -var filterTests = []restic.SnapshotFilter{ - {Hostname: "foo"}, - {Username: "root"}, - {Hostname: "foo", Username: "root"}, - {Paths: []string{"/usr", "/bin"}}, - {Hostname: "bar", Paths: []string{"/usr", "/bin"}}, - {Hostname: "foo", Username: "root", Paths: []string{"/usr", "/sbin"}}, - {Tags: []string{"foo"}}, - {Tags: []string{"fox"}, Username: "root"}, - {Tags: []string{"foo", "test"}}, - {Tags: []string{"foo", "test2"}}, -} - -func TestFilterSnapshots(t *testing.T) { - sort.Sort(testFilterSnapshots) - - for i, f := range filterTests { - res := restic.FilterSnapshots(testFilterSnapshots, f) - - goldenFilename := filepath.Join("testdata", fmt.Sprintf("filter_snapshots_%d", i)) - - if *updateGoldenFiles { - buf, err := json.MarshalIndent(res, "", " ") - if err != nil { - t.Fatalf("error marshaling result: %v", err) - } - - if err = ioutil.WriteFile(goldenFilename, buf, 0644); err != nil { - t.Fatalf("unable to update golden file: %v", err) - } - } - - buf, err := ioutil.ReadFile(goldenFilename) - if err != nil { - t.Errorf("error loading golden file %v: %v", goldenFilename, err) - continue - } - - var want restic.Snapshots - err = json.Unmarshal(buf, &want) - - if !reflect.DeepEqual(res, want) { - t.Errorf("test %v: wrong result, want:\n %#v\ngot:\n %#v", i, want, res) - continue - } - } -} - func TestExpireSnapshotOps(t *testing.T) { data := []struct { expectEmpty bool