Exemplo n.º 1
0
func TestReposCache(t *testing.T) {

	g := goblin.Goblin(t)
	g.Describe("Repo List Cache", func() {

		var c *gin.Context
		g.BeforeEach(func() {
			c = new(gin.Context)
			cache.ToContext(c, cache.Default())
		})

		g.It("should skip when no user session", func() {
			Perms(c)

			_, ok := c.Get("perm")
			g.Assert(ok).IsFalse()
		})

		g.It("should get repos from cache", func() {
			c.Set("user", fakeUser)
			cache.SetRepos(c, fakeUser, fakeRepos)

			Repos(c)

			repos, ok := c.Get("repos")
			g.Assert(ok).IsTrue()
			g.Assert(repos).Equal(fakeRepos)
		})

	})
}
Exemplo n.º 2
0
func Default() gin.HandlerFunc {
	cc := cache.Default()
	return func(c *gin.Context) {
		cache.ToContext(c, cc)
		c.Next()
	}
}
Exemplo n.º 3
0
func TestPermCache(t *testing.T) {

	g := goblin.Goblin(t)
	g.Describe("Perm Cache", func() {

		var c *gin.Context
		g.BeforeEach(func() {
			c = new(gin.Context)
			cache.ToContext(c, cache.Default())
		})

		g.It("should skip when no user session", func() {
			c.Params = gin.Params{
				gin.Param{Key: "owner", Value: "octocat"},
				gin.Param{Key: "name", Value: "hello-world"},
			}

			Perms(c)

			_, ok := c.Get("perm")
			g.Assert(ok).IsFalse()
		})

		g.It("should get perms from cache", func() {
			c.Params = gin.Params{
				gin.Param{Key: "owner", Value: "octocat"},
				gin.Param{Key: "name", Value: "hello-world"},
			}
			c.Set("user", fakeUser)
			cache.SetPerms(c, fakeUser, fakePerm, "octocat", "hello-world")

			Perms(c)

			perm, ok := c.Get("perm")
			g.Assert(ok).IsTrue()
			g.Assert(perm).Equal(fakePerm)
		})

	})
}