Skip to content

Commit

Permalink
[tests-only] Improve ini metadata backend unit tests (#3674)
Browse files Browse the repository at this point in the history
* Fix ini metadata backend unit tests

* Adapt changelog
  • Loading branch information
aduffeck authored Feb 27, 2023
1 parent f852e0e commit ce922f2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
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())
})
})
})
})

0 comments on commit ce922f2

Please sign in to comment.