generated from caicloud/golang-template-project
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,6 @@ coverage.out | |
dist/ | ||
.vscode/ | ||
|
||
.cache/ | ||
|
||
training-serving.ipynb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
}) | ||
}) | ||
}) | ||
}) |