Skip to content

Commit

Permalink
add unit test for documrnt manager
Browse files Browse the repository at this point in the history
Signed-off-by: zwwhdls <[email protected]>
  • Loading branch information
zwwhdls committed Oct 29, 2023
1 parent bd30de9 commit 8973772
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
67 changes: 67 additions & 0 deletions pkg/document/manager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright 2023 NanaFS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package document

import (
"context"

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

"github.com/basenana/nanafs/pkg/types"
)

var _ = Describe("testDocumentManage", func() {
var docId string
Context("create document", func() {
It("create should be succeed", func() {
doc := &types.Document{
Name: "test_create_doc",
}
err := docManager.CreateDocument(context.TODO(), doc)
Expect(err).Should(BeNil())
docId = doc.ID
})
It("query should be succeed", func() {
doc, err := docManager.GetDocument(context.TODO(), docId)
Expect(err).Should(BeNil())
Expect(doc.Name).Should(Equal("test_create_doc"))
})
})
Context("update document", func() {
It("update should be succeed", func() {
err := docManager.UpdateDocument(context.TODO(), &types.Document{
ID: docId,
Name: "test_create_doc",
Content: "abc",
})
Expect(err).Should(BeNil())
doc, err := docManager.GetDocument(context.TODO(), docId)
Expect(err).Should(BeNil())
Expect(doc.Content).Should(Equal("abc"))
})
})
Context("delete document", func() {
It("delete should be succeed", func() {
err := docManager.DeleteDocument(context.TODO(), docId)
Expect(err).Should(BeNil())
doc, err := docManager.GetDocument(context.TODO(), docId)
Expect(err).ShouldNot(BeNil())
Expect(doc).Should(BeNil())
})
})
})
65 changes: 65 additions & 0 deletions pkg/document/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright 2023 NanaFS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package document

import (
"os"
"testing"

"github.com/basenana/nanafs/config"
"github.com/basenana/nanafs/pkg/metastore"
"github.com/basenana/nanafs/pkg/plugin"
"github.com/basenana/nanafs/pkg/storage"
"github.com/basenana/nanafs/pkg/types"
"github.com/basenana/nanafs/utils/logger"

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

var (
docRecorder metastore.DocumentRecorder
docManager Manager
root *types.Metadata

workdir string
)

func TestDEntry(t *testing.T) {
logger.InitLogger()
defer logger.Sync()
RegisterFailHandler(Fail)

var err error
workdir, err = os.MkdirTemp(os.TempDir(), "ut-nanafs-dentry-")
Expect(err).Should(BeNil())
t.Logf("unit test workdir on: %s", workdir)
storage.InitLocalCache(config.Config{CacheDir: workdir, CacheSize: 1})

RunSpecs(t, "DEntry Suite")
}

var _ = BeforeSuite(func() {
memMeta, err := metastore.NewMetaStorage(storage.MemoryStorage, config.Meta{})
Expect(err).Should(BeNil())
docRecorder = memMeta
docManager, _ = NewManager(docRecorder)

// init plugin
err = plugin.Init(&config.Plugin{}, memMeta)
Expect(err).Should(BeNil())
})

0 comments on commit 8973772

Please sign in to comment.