cacheinterface/driver/memory/memory_test.go
Tyler 41d0ef3d97
Some checks failed
continuous-integration/drone Build is failing
Initial v2 version, better testing, updates
2023-02-04 20:22:41 -05:00

66 lines
1.5 KiB
Go

package memory
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"meow.tf/go/cacheinterface/v2/encoder"
"time"
)
var _ = Describe("Memory driver", func() {
Context("Basic operations", func() {
var (
cache *Cache
)
BeforeEach(func() {
var err error
cache, err = New(Options{
Encoder: encoder.JSON,
})
Expect(err).To(BeNil())
})
It("Should store a value in the cache", func() {
value := "test"
Expect(cache.Set("test", value, time.Minute)).To(BeNil())
})
It("Should get a value from the cache", func() {
value := "test"
var newValue string
Expect(cache.Set("test", value, time.Minute)).To(BeNil())
Expect(cache.Get("test", &newValue)).To(BeNil())
Expect(newValue).To(Equal(value))
})
It("Should get a value from the cache as bytes", func() {
value := "test"
Expect(cache.Set("test", value, time.Minute)).To(BeNil())
newValue, err := cache.GetBytes("test")
Expect(err).To(BeNil())
Expect(newValue).To(Equal([]byte(value)))
})
It("Should check if the cache has a value", func() {
value := "test"
Expect(cache.Set("test", value, time.Minute)).To(BeNil())
Expect(cache.Has("test")).To(BeTrue())
})
It("Should delete a value from the cache", func() {
value := "test"
Expect(cache.Set("test", value, time.Minute)).To(BeNil())
Expect(cache.Has("test")).To(BeTrue())
Expect(cache.Del("test")).To(BeNil())
Expect(cache.Has("test")).To(BeFalse())
})
})
})