From a592264aeaf02c94af52a6c33c3c16c038f80d54 Mon Sep 17 00:00:00 2001 From: Saketh Kalaga <51327242+renormalize@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:55:53 +0530 Subject: [PATCH] Remove hardcoding of tags in mock GCS tag implementation. * Remove hardcoding of tags in mock GCS tag implementation. * Rename the methods of the `tagI` interface to plural since they operate on all tags of the snapshot. --- pkg/snapstore/gcs_snapstore_test.go | 6 +++--- pkg/snapstore/snapshot_test.go | 1 - pkg/snapstore/snapstore_test.go | 14 +++++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/pkg/snapstore/gcs_snapstore_test.go b/pkg/snapstore/gcs_snapstore_test.go index e4b66ee8a..5d2bb7564 100644 --- a/pkg/snapstore/gcs_snapstore_test.go +++ b/pkg/snapstore/gcs_snapstore_test.go @@ -30,11 +30,11 @@ func (m *mockGCSClient) Bucket(name string) stiface.BucketHandle { return &mockBucketHandle{bucket: name, client: m} } -func (m *mockGCSClient) setTag(taggedSnapshotName string, tagMap map[string]string) { - m.objectTags[taggedSnapshotName] = map[string]string{"x-etcd-snapshot-exclude": "true"} +func (m *mockGCSClient) setTags(taggedSnapshotName string, tagMap map[string]string) { + m.objectTags[taggedSnapshotName] = tagMap } -func (m *mockGCSClient) deleteTag(taggedSnapshotName string) { +func (m *mockGCSClient) deleteTags(taggedSnapshotName string) { delete(m.objectTags, taggedSnapshotName) } diff --git a/pkg/snapstore/snapshot_test.go b/pkg/snapstore/snapshot_test.go index 0f2477848..6b00d8aa9 100644 --- a/pkg/snapstore/snapshot_test.go +++ b/pkg/snapstore/snapshot_test.go @@ -328,7 +328,6 @@ var _ = Describe("Snapshot", func() { Kind: brtypes.SnapshotKindDelta, SnapDir: snapdir, } - }) It("should be deletable when its retention period is not set", func() { // do not set the retention period diff --git a/pkg/snapstore/snapstore_test.go b/pkg/snapstore/snapstore_test.go index 6a9c0f24e..72cfba2ef 100644 --- a/pkg/snapstore/snapstore_test.go +++ b/pkg/snapstore/snapstore_test.go @@ -41,12 +41,12 @@ type testSnapStore struct { objectCountPerSnapshot int } -// tagI is the interface that is to be implemented by mock snapstores to set tags on snapshots -type tagI interface { +// tagger is the interface that is to be implemented by mock snapstores to set tags on snapshots +type tagger interface { // Sets all of the tags for a mocked snapshot - setTag(string, map[string]string) + setTags(string, map[string]string) // Deletes all of the tags of a mocked snapshot - deleteTag(string) + deleteTags(string) } var _ = Describe("Save, List, Fetch, Delete from mock snapstore", func() { @@ -316,7 +316,7 @@ var _ = Describe("Save, List, Fetch, Delete from mock snapstore", func() { Expect(snapList[secondSnapshotIndex].SnapName).To(Equal(snap5.SnapName)) // List tests with false and true as arguments only implemented with GCS for now - var tag tagI + var tag tagger switch provider { case "GCS": tag = gcsClient @@ -325,7 +325,7 @@ var _ = Describe("Save, List, Fetch, Delete from mock snapstore", func() { // the tagged snapshot should not be returned by the List() call taggedSnapshot := snapList[0] taggedSnapshotName := path.Join(taggedSnapshot.Prefix, taggedSnapshot.SnapDir, taggedSnapshot.SnapName) - tag.setTag(taggedSnapshotName, map[string]string{"x-etcd-snapshot-exclude": "true"}) + tag.setTags(taggedSnapshotName, map[string]string{brtypes.ExcludeSnapshotMetadataKey: "true"}) snapList, err = snapStore.List(false) Expect(err).ShouldNot(HaveOccurred()) Expect(snapList.Len()).Should(Equal((numberSnapshotsInObjectMap - 1) * snapStore.objectCountPerSnapshot)) @@ -338,7 +338,7 @@ var _ = Describe("Save, List, Fetch, Delete from mock snapstore", func() { Expect(snapList[0].SnapName).Should(Equal(taggedSnapshot.SnapName)) // removing the tag will make the snapshot appear in the List call with false - tag.deleteTag(taggedSnapshotName) + tag.deleteTags(taggedSnapshotName) snapList, err = snapStore.List(false) Expect(err).ShouldNot(HaveOccurred()) Expect(snapList.Len()).Should(Equal(numberSnapshotsInObjectMap * snapStore.objectCountPerSnapshot))