2015-11-11 23:42:31 +02:00
|
|
|
package github
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/franela/goblin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHook(t *testing.T) {
|
|
|
|
var (
|
2016-05-03 02:47:58 +02:00
|
|
|
github client
|
2015-11-11 23:42:31 +02:00
|
|
|
r *http.Request
|
|
|
|
body *bytes.Buffer
|
|
|
|
)
|
|
|
|
|
|
|
|
g := goblin.Goblin(t)
|
|
|
|
|
|
|
|
g.Describe("Hook", func() {
|
|
|
|
g.BeforeEach(func() {
|
2016-05-03 02:47:58 +02:00
|
|
|
github = client{}
|
2015-11-11 23:42:31 +02:00
|
|
|
body = bytes.NewBuffer([]byte{})
|
|
|
|
r, _ = http.NewRequest("POST", "https://drone.com/hook", body)
|
|
|
|
})
|
|
|
|
|
|
|
|
g.Describe("For a Pull Request", func() {
|
|
|
|
g.BeforeEach(func() {
|
|
|
|
r.Header.Set("X-Github-Event", "pull_request")
|
|
|
|
})
|
|
|
|
|
|
|
|
g.It("Should set build author to the pull request author", func() {
|
2016-05-03 02:47:58 +02:00
|
|
|
hookJSON, ioerr := ioutil.ReadFile("fixtures/pull_request.json")
|
|
|
|
if ioerr != nil {
|
|
|
|
panic(ioerr)
|
2015-11-11 23:42:31 +02:00
|
|
|
}
|
2016-05-03 02:47:58 +02:00
|
|
|
body.Write(hookJSON)
|
2015-11-11 23:42:31 +02:00
|
|
|
|
|
|
|
_, build, err := github.Hook(r)
|
|
|
|
g.Assert(err).Equal(nil)
|
|
|
|
g.Assert(build.Author).Equal("author")
|
|
|
|
g.Assert(build.Avatar).Equal("https://avatars.githubusercontent.com/u/55555?v=3")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2016-03-10 21:30:14 +02:00
|
|
|
|
2016-04-29 21:39:56 +02:00
|
|
|
//
|
|
|
|
// func TestLoad(t *testing.T) {
|
|
|
|
// conf := "https://github.com?client_id=client&client_secret=secret&scope=scope1,scope2"
|
|
|
|
//
|
|
|
|
// g := Load(conf)
|
|
|
|
// if g.URL != "https://github.com" {
|
|
|
|
// t.Errorf("g.URL = %q; want https://github.com", g.URL)
|
|
|
|
// }
|
|
|
|
// if g.Client != "client" {
|
|
|
|
// t.Errorf("g.Client = %q; want client", g.Client)
|
|
|
|
// }
|
|
|
|
// if g.Secret != "secret" {
|
|
|
|
// t.Errorf("g.Secret = %q; want secret", g.Secret)
|
|
|
|
// }
|
|
|
|
// if g.Scope != "scope1,scope2" {
|
|
|
|
// t.Errorf("g.Scope = %q; want scope1,scope2", g.Scope)
|
|
|
|
// }
|
|
|
|
// if g.API != DefaultAPI {
|
|
|
|
// t.Errorf("g.API = %q; want %q", g.API, DefaultAPI)
|
|
|
|
// }
|
|
|
|
// if g.MergeRef != DefaultMergeRef {
|
|
|
|
// t.Errorf("g.MergeRef = %q; want %q", g.MergeRef, DefaultMergeRef)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// g = Load("")
|
|
|
|
// if g.Scope != DefaultScope {
|
|
|
|
// t.Errorf("g.Scope = %q; want %q", g.Scope, DefaultScope)
|
|
|
|
// }
|
|
|
|
// }
|