From 4329268ee1a349d16f6615e9ab0da7d206b00c21 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 1 May 2017 20:51:44 +0800 Subject: [PATCH] fix: add commit status testing. --- remote/gitea/fixtures/handler.go | 10 ++++++++++ remote/gitea/gitea_test.go | 19 +++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/remote/gitea/fixtures/handler.go b/remote/gitea/fixtures/handler.go index 5904a1dd..adfe14c3 100644 --- a/remote/gitea/fixtures/handler.go +++ b/remote/gitea/fixtures/handler.go @@ -15,6 +15,7 @@ func Handler() http.Handler { e.GET("/api/v1/repos/:owner/:name", getRepo) e.GET("/api/v1/repos/:owner/:name/raw/:commit/:file", getRepoFile) e.POST("/api/v1/repos/:owner/:name/hooks", createRepoHook) + e.POST("/api/v1/repos/:owner/:name/statuses/:commit", createRepoCommitStatus) e.GET("/api/v1/user/repos", getUserRepos) return e @@ -29,6 +30,13 @@ func getRepo(c *gin.Context) { } } +func createRepoCommitStatus(c *gin.Context) { + if c.Param("commit") == "v1.0.0" || c.Param("commit") == "9ecad50" { + c.String(200, repoPayload) + } + c.String(404, "") +} + func getRepoFile(c *gin.Context) { if c.Param("file") == "file_not_found" { c.String(404, "") @@ -70,6 +78,7 @@ func getUserRepos(c *gin.Context) { const repoPayload = ` { "owner": { + "login": "test_name", "username": "test_name", "email": "octocat@github.com", "avatar_url": "https:\/\/secure.gravatar.com\/avatar\/8c58a0be77ee441bb8f8595b7f1b4e87" @@ -92,6 +101,7 @@ const userRepoPayload = ` [ { "owner": { + "login": "test_name", "username": "test_name", "email": "octocat@github.com", "avatar_url": "https:\/\/secure.gravatar.com\/avatar\/8c58a0be77ee441bb8f8595b7f1b4e87" diff --git a/remote/gitea/gitea_test.go b/remote/gitea/gitea_test.go index 982449fd..e52fe632 100644 --- a/remote/gitea/gitea_test.go +++ b/remote/gitea/gitea_test.go @@ -134,6 +134,11 @@ func Test_gogs(t *testing.T) { g.Assert(string(raw)).Equal("{ platform: linux/amd64 }") }) + g.It("Should return nil frome send build status", func() { + err := c.Status(fakeUser, fakeRepo, fakeBuild, "http://gitea.io") + g.Assert(err == nil).IsTrue() + }) + g.Describe("Given an authentication request", func() { g.It("Should redirect to login form") g.It("Should create an access token") @@ -147,14 +152,12 @@ func Test_gogs(t *testing.T) { g.It("Should handle a parsing error") }) - // g.It("Should return no-op for usupporeted features", func() { - // _, err1 := c.Auth("octocat", "4vyW6b49Z") - // err2 := c.Status(fakeUser, fakeRepo, fakeBuild, "http://gitea.io") - // err3 := c.Deactivate(nil, nil, "") - // g.Assert(err1 != nil).IsTrue() - // g.Assert(err2 == nil).IsTrue() - // g.Assert(err3 == nil).IsTrue() - // }) + g.It("Should return no-op for usupporeted features", func() { + _, err1 := c.Auth("octocat", "4vyW6b49Z") + err2 := c.Deactivate(nil, nil, "") + g.Assert(err1 != nil).IsTrue() + g.Assert(err2 == nil).IsTrue() + }) }) }