cleaning up the middleware and adding caching with TTL

This commit is contained in:
Brad Rydzewski
2015-10-13 02:08:08 -07:00
parent 7be93921bd
commit a7a1b1dfb7
14 changed files with 430 additions and 73 deletions

46
router/middleware/cache/repos_test.go vendored Normal file
View File

@@ -0,0 +1,46 @@
package cache
import (
"testing"
"github.com/drone/drone/model"
"github.com/franela/goblin"
"github.com/gin-gonic/gin"
)
func TestReposCache(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("Repo List Cache", func() {
g.BeforeEach(func() {
cache.Purge()
})
g.It("should skip when no user session", func() {
c := &gin.Context{}
Perms(c)
_, ok := c.Get("perm")
g.Assert(ok).IsFalse()
})
g.It("should get repos from cache", func() {
c := &gin.Context{}
c.Set("user", fakeUser)
set("repos/octocat", fakeRepos, 999)
Repos(c)
repos, ok := c.Get("repos")
g.Assert(ok).IsTrue()
g.Assert(repos).Equal(fakeRepos)
})
})
}
var fakeRepos = []*model.RepoLite{
{Owner: "octocat", Name: "hello-world"},
}