Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only] Improve ini metadata backend unit tests #3674

Merged
merged 2 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion changelog/unreleased/materialized-xattrs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Enhancement: Introduce ini file based metadata backend

We added a new metadata backend for the decomposed storage driver that uses an additional `.ini` file to store file metadata. This allows scaling beyond some filesystem specific xattr limitations.

https://github.com/cs3org/reva/pull/3649
https://github.com/cs3org/reva/pull/3674
https://github.com/cs3org/reva/pull/3649
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package backend_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestBackend(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Backend Suite")
}
41 changes: 40 additions & 1 deletion pkg/storage/utils/decomposedfs/xattrs/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var _ = Describe("Backend", func() {

Describe("IniBackend", func() {
BeforeEach(func() {
backend = xattrsBackend.IniBackend{}
backend = xattrsBackend.NewIniBackend()
})

Describe("Set", func() {
Expand All @@ -81,6 +81,15 @@ var _ = Describe("Backend", func() {
Expect(err).ToNot(HaveOccurred())
Expect(string(content)).To(Equal("foo = baz\n"))
})

It("encodes where needed", func() {
err := backend.Set(file, "user.ocis.cs.foo", "bar")
Expect(err).ToNot(HaveOccurred())

content, err := os.ReadFile(metafile)
Expect(err).ToNot(HaveOccurred())
Expect(string(content)).To(Equal("user.ocis.cs.foo = YmFy\n"))
})
})

Describe("SetMultiple", func() {
Expand All @@ -105,6 +114,20 @@ var _ = Describe("Backend", func() {
lines := strings.Split(strings.Trim(string(content), "\n"), "\n")
Expect(lines).To(ConsistOf("foo = bar", "baz = qux"))
})

It("encodes where needed", func() {
err := backend.SetMultiple(file, map[string]string{
"user.ocis.something.foo": "bar",
"user.ocis.cs.foo": "bar",
"user.ocis.md.foo": "bar",
"user.ocis.grant.foo": "bar",
})
Expect(err).ToNot(HaveOccurred())

content, err := os.ReadFile(metafile)
Expect(err).ToNot(HaveOccurred())
Expect(strings.ReplaceAll(string(content), " ", "")).To(Equal("user.ocis.something.foo=bar\nuser.ocis.cs.foo=YmFy\nuser.ocis.md.foo=YmFy\nuser.ocis.grant.foo=YmFy\n"))
})
})

Describe("All", func() {
Expand Down Expand Up @@ -191,5 +214,21 @@ var _ = Describe("Backend", func() {
Expect(err).To(HaveOccurred())
})
})

Describe("UsesExternalMetadataFile", func() {
It("returns true", func() {
Expect(backend.UsesExternalMetadataFile()).To(BeTrue())
})
})

Describe("IsMetaFile", func() {
It("returns true", func() {
Expect(backend.IsMetaFile("foo.ini")).To(BeTrue())
})

It("returns false", func() {
Expect(backend.IsMetaFile("foo.txt")).To(BeFalse())
})
})
})
})