Skip to content

Commit

Permalink
Remove hardcoding of tags in mock GCS tag implementation.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
renormalize committed Sep 12, 2024
1 parent f40496b commit a592264
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions pkg/snapstore/gcs_snapstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion pkg/snapstore/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pkg/snapstore/snapstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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))
Expand Down

0 comments on commit a592264

Please sign in to comment.