fix: add commit status testing.

This commit is contained in:
Bo-Yi Wu 2017-05-01 20:51:44 +08:00
parent 82548c4587
commit 4329268ee1
No known key found for this signature in database
GPG key ID: 0F84B2110C500B1F
2 changed files with 21 additions and 8 deletions

View file

@ -15,6 +15,7 @@ func Handler() http.Handler {
e.GET("/api/v1/repos/:owner/:name", getRepo) e.GET("/api/v1/repos/:owner/:name", getRepo)
e.GET("/api/v1/repos/:owner/:name/raw/:commit/:file", getRepoFile) 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/hooks", createRepoHook)
e.POST("/api/v1/repos/:owner/:name/statuses/:commit", createRepoCommitStatus)
e.GET("/api/v1/user/repos", getUserRepos) e.GET("/api/v1/user/repos", getUserRepos)
return e 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) { func getRepoFile(c *gin.Context) {
if c.Param("file") == "file_not_found" { if c.Param("file") == "file_not_found" {
c.String(404, "") c.String(404, "")
@ -70,6 +78,7 @@ func getUserRepos(c *gin.Context) {
const repoPayload = ` const repoPayload = `
{ {
"owner": { "owner": {
"login": "test_name",
"username": "test_name", "username": "test_name",
"email": "octocat@github.com", "email": "octocat@github.com",
"avatar_url": "https:\/\/secure.gravatar.com\/avatar\/8c58a0be77ee441bb8f8595b7f1b4e87" "avatar_url": "https:\/\/secure.gravatar.com\/avatar\/8c58a0be77ee441bb8f8595b7f1b4e87"
@ -92,6 +101,7 @@ const userRepoPayload = `
[ [
{ {
"owner": { "owner": {
"login": "test_name",
"username": "test_name", "username": "test_name",
"email": "octocat@github.com", "email": "octocat@github.com",
"avatar_url": "https:\/\/secure.gravatar.com\/avatar\/8c58a0be77ee441bb8f8595b7f1b4e87" "avatar_url": "https:\/\/secure.gravatar.com\/avatar\/8c58a0be77ee441bb8f8595b7f1b4e87"

View file

@ -134,6 +134,11 @@ func Test_gogs(t *testing.T) {
g.Assert(string(raw)).Equal("{ platform: linux/amd64 }") 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.Describe("Given an authentication request", func() {
g.It("Should redirect to login form") g.It("Should redirect to login form")
g.It("Should create an access token") 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 handle a parsing error")
}) })
// g.It("Should return no-op for usupporeted features", func() { g.It("Should return no-op for usupporeted features", func() {
// _, err1 := c.Auth("octocat", "4vyW6b49Z") _, err1 := c.Auth("octocat", "4vyW6b49Z")
// err2 := c.Status(fakeUser, fakeRepo, fakeBuild, "http://gitea.io") err2 := c.Deactivate(nil, nil, "")
// err3 := c.Deactivate(nil, nil, "") g.Assert(err1 != nil).IsTrue()
// g.Assert(err1 != nil).IsTrue() g.Assert(err2 == nil).IsTrue()
// g.Assert(err2 == nil).IsTrue() })
// g.Assert(err3 == nil).IsTrue()
// })
}) })
} }