Skip to content

Commit

Permalink
some unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
kwitsch committed Dec 17, 2021
1 parent c841856 commit e863c7a
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions redis/redis_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package redis

import (
"time"

"github.com/0xERR0R/blocky/config"
"github.com/0xERR0R/blocky/model"
"github.com/0xERR0R/blocky/util"
"github.com/alicebob/miniredis/v2"
"github.com/creasty/defaults"
Expand Down Expand Up @@ -86,14 +87,35 @@ var _ = Describe("Redis client", func() {

Expect(err).Should(Succeed())

redisClient.PublishCache("example.com.", &model.Response{
Res: res,
RType: model.ResponseTypeCACHED,
Reason: "CACHED",
})
redisClient.PublishCache("example.com", res)

time.Sleep(50 * time.Millisecond)

keysLen := len(redisServer.DB(redisConfig.Database).Keys())
Expect(keysLen).To(Equal(1))
})
})
When("GetRedisCache", func() {
It("works", func() {
var res *dns.Msg

origCount := len(redisClient.CacheChannel)
res, err = util.NewMsgWithAnswer("example.com.", 123, dns.TypeA, "123.124.122.123")

Expect(err).Should(Succeed())

redisClient.PublishCache("example.com", res)

time.Sleep(50 * time.Millisecond)

keysLen := len(redisServer.DB(redisConfig.Database).Keys())
Expect(keysLen).To(Equal(1))

redisClient.GetRedisCache()

time.Sleep(50 * time.Millisecond)

Expect(len(redisClient.CacheChannel)).To(Equal(origCount + 1))
})
})
})

0 comments on commit e863c7a

Please sign in to comment.