コード例 #1
0
ファイル: reliableget.go プロジェクト: caledhwa/gongeal
func New(config *config.Config) *ReliableGet {
	g := &ReliableGet{}
	g.config = config
	g.factory = cache.NewCacheFactory()
	g.cache = g.factory.GetCache(&config.Cache)
	return g
}
コード例 #2
0
ファイル: cachefactory_test.go プロジェクト: caledhwa/gongeal
	"github.com/caledhwa/gongeal/reliableget/cache"
	"github.com/caledhwa/gongeal/reliableget/config"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"testing"
)

func TestCacheFactory(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "TestCacheFactory")
}

var _ = Describe("Cache Factory", func() {

	It("should return redis cache engine when specified in config", func() {
		cacheFactory := cache.NewCacheFactory()
		engine := cacheFactory.GetCache(&config.Cache{
			Engine: "redis",
		}).(cache.CacheEngine)
		Expect(engine.Engine()).To(BeEquivalentTo("redis"))
	})

	It("should return memory cache engine when specified in config", func() {
		cacheFactory := cache.NewCacheFactory()
		engine := cacheFactory.GetCache(&config.Cache{
			Engine: "memorycache",
		}).(cache.CacheEngine)
		Expect(engine.Engine()).To(BeEquivalentTo("memorycache"))
	})

	It("should return nocache engine when no config specified", func() {