Skip to content

Commit

Permalink
feat: Add test for cache (#68)
Browse files Browse the repository at this point in the history
* feat: Add test for cache

Signed-off-by: Ce Gao <[email protected]>

* feat: Add more test cases

Signed-off-by: Ce Gao <[email protected]>
  • Loading branch information
gaocegege authored Jun 18, 2020
1 parent c723bbe commit c314986
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ coverage.out
dist/
.vscode/

.cache/

training-serving.ipynb
13 changes: 13 additions & 0 deletions pkg/oras/cache/cache_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cache

import (
"testing"

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

func TestCache(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Cache Suite")
}
68 changes: 68 additions & 0 deletions pkg/oras/cache/cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package cache

import (
"os"

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

"github.com/caicloud/ormb/pkg/model"
"github.com/caicloud/ormb/pkg/oci"
)

var _ = Describe("Cache", func() {
Describe("with real use cases", func() {
var c *Cache
var err error
var rootPath string

BeforeEach(func() {
var i Interface
rootPath = ".cache"

i, err = New(CacheOptRoot(rootPath), CacheOptDebug(true), CacheOptWriter(os.Stdout))
c = i.(*Cache)
})

It("Should create the cache successfully", func() {
Expect(err).To(BeNil())
Expect(c.rootDir).To(Equal(rootPath))
})

Describe("with a cached artifact caicloud/test:v2", func() {
var m *model.Model
var ref *oci.Reference

BeforeEach(func() {
m = &model.Model{
Metadata: &model.Metadata{
Format: "SavedModel",
},
Content: []byte("test12345"),
}
refStr := "caicloud/test:v1"
ref, err = oci.ParseReference(refStr)
Expect(err).To(BeNil())

actual, err := c.StoreReference(ref, m)
Expect(err).To(BeNil())
Expect(actual.Model).To(Equal(m))
Expect(actual.Name).To(Equal(refStr))

Expect(c.AddManifest(ref, actual.Manifest)).To(BeNil())
})

It("Should list the cached artifact successfully", func() {
actual, err := c.ListReferences()
Expect(err).To(BeNil())
Expect(len(actual)).To(Equal(1))
})

It("Should delete the reference successfully", func() {
actual, err := c.DeleteReference(ref)
Expect(err).To(BeNil())
Expect(actual.Name).To(Equal(ref.FullName()))
})
})
})
})

0 comments on commit c314986

Please sign in to comment.