test working

This commit is contained in:
Dean Karn
2018-07-31 08:46:17 -07:00
parent 1d0289a3ae
commit fe5cf5a911
6 changed files with 4154 additions and 3903 deletions
+2780 -2644
View File
File diff suppressed because it is too large Load Diff
+10 -7
View File
@@ -47,14 +47,14 @@ func newServer(handler http.HandlerFunc) *httptest.Server {
} }
func TestBadNoEventHeader(t *testing.T) { func TestBadNoEventHeader(t *testing.T) {
payload := "{}"
var parseError error var parseError error
server := newServer(func(w http.ResponseWriter, r *http.Request) { server := newServer(func(w http.ResponseWriter, r *http.Request) {
_, parseError = hook.Parse(r, CreateEvent) _, parseError = hook.Parse(r, CreateEvent)
}) })
defer server.Close() defer server.Close()
payload := "{}"
req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload)))
Equal(t, err, nil) Equal(t, err, nil)
@@ -68,12 +68,13 @@ func TestBadNoEventHeader(t *testing.T) {
} }
func TestUnsubscribedEvent(t *testing.T) { func TestUnsubscribedEvent(t *testing.T) {
payload := "{}"
var parseError error var parseError error
server := newServer(func(w http.ResponseWriter, r *http.Request) { server := newServer(func(w http.ResponseWriter, r *http.Request) {
_, parseError = hook.Parse(r, CreateEvent) _, parseError = hook.Parse(r, CreateEvent)
}) })
defer server.Close() defer server.Close()
payload := "{}"
req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload)))
Equal(t, err, nil) Equal(t, err, nil)
@@ -89,12 +90,12 @@ func TestUnsubscribedEvent(t *testing.T) {
} }
func TestBadBody(t *testing.T) { func TestBadBody(t *testing.T) {
payload := ""
var parseError error var parseError error
server := newServer(func(w http.ResponseWriter, r *http.Request) { server := newServer(func(w http.ResponseWriter, r *http.Request) {
_, parseError = hook.Parse(r, CommitCommentEvent) _, parseError = hook.Parse(r, CommitCommentEvent)
}) })
defer server.Close() defer server.Close()
payload := ""
req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload)))
Equal(t, err, nil) Equal(t, err, nil)
@@ -112,12 +113,13 @@ func TestBadBody(t *testing.T) {
} }
func TestBadSignatureLength(t *testing.T) { func TestBadSignatureLength(t *testing.T) {
payload := "{}"
var parseError error var parseError error
server := newServer(func(w http.ResponseWriter, r *http.Request) { server := newServer(func(w http.ResponseWriter, r *http.Request) {
_, parseError = hook.Parse(r, CommitCommentEvent) _, parseError = hook.Parse(r, CommitCommentEvent)
}) })
defer server.Close() defer server.Close()
payload := "{}"
req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload)))
Equal(t, err, nil) Equal(t, err, nil)
@@ -135,12 +137,13 @@ func TestBadSignatureLength(t *testing.T) {
} }
func TestBadSignatureMatch(t *testing.T) { func TestBadSignatureMatch(t *testing.T) {
payload := "{}"
var parseError error var parseError error
server := newServer(func(w http.ResponseWriter, r *http.Request) { server := newServer(func(w http.ResponseWriter, r *http.Request) {
_, parseError = hook.Parse(r, CommitCommentEvent) _, parseError = hook.Parse(r, CommitCommentEvent)
}) })
defer server.Close() defer server.Close()
payload := "{}"
req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload))) req, err := http.NewRequest(http.MethodPost, server.URL+path, bytes.NewBuffer([]byte(payload)))
Equal(t, err, nil) Equal(t, err, nil)
@@ -1574,7 +1577,7 @@ func TestIssueCommentEvent(t *testing.T) {
"created_at": "2015-05-05T23:40:28Z", "created_at": "2015-05-05T23:40:28Z",
"updated_at": "2015-05-05T23:40:28Z", "updated_at": "2015-05-05T23:40:28Z",
"closed_at": null, "closed_at": null,
"body": "It looks like you accidentally spelled 'commit' with two 't's." "body": "It looks like you accidently spelled 'commit' with two 't's."
}, },
"comment": { "comment": {
"url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments/99262140", "url": "https://api.github.com/repos/baxterthehacker/public-repo/issues/comments/99262140",
+7 -7
View File
@@ -11,12 +11,12 @@ import (
// parse errors // parse errors
var ( var (
ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse") ErrEventNotSpecifiedToParse = errors.New("no Event specified to parse")
ErrInvalidHTTPMethod = errors.New("invalid HTTP Method") ErrInvalidHTTPMethod = errors.New("invalid HTTP Method")
ErrMissingGitLabEventHeader = errors.New("missing X-Gitlab-Event Header") ErrMissingGitLabEventHeader = errors.New("missing X-Gitlab-Event Header")
ErrMissingGitLabTokenHeader = errors.New("missing X-Gitlab-Token Header") ErrGitLabTokenVerificationFailed = errors.New("X-Gitlab-Token validation failed")
ErrEventNotFound = errors.New("event not defined to be parsed") ErrEventNotFound = errors.New("event not defined to be parsed")
ErrParsingPayload = errors.New("error parsing payload") ErrParsingPayload = errors.New("error parsing payload")
// ErrHMACVerificationFailed = errors.New("HMAC verification failed") // ErrHMACVerificationFailed = errors.New("HMAC verification failed")
) )
@@ -111,7 +111,7 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
if len(hook.secret) > 0 { if len(hook.secret) > 0 {
signature := r.Header.Get("X-Gitlab-Token") signature := r.Header.Get("X-Gitlab-Token")
if signature != hook.secret { if signature != hook.secret {
return nil, ErrMissingGitLabTokenHeader return nil, ErrGitLabTokenVerificationFailed
} }
} }
+1078 -967
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -427,14 +427,14 @@ type LabelChanges struct {
// Label contains all of the GitLab label information // Label contains all of the GitLab label information
type Label struct { type Label struct {
Id int64 `json:"id"` ID int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Color string `json:"color"` Color string `json:"color"`
ProjectId int64 `json:"project_id"` ProjectID int64 `json:"project_id"`
CreatedAt customTime `json:"created_at"` CreatedAt customTime `json:"created_at"`
UpdatedAt customTime `json:"updated_at"` UpdatedAt customTime `json:"updated_at"`
Template bool `json:"template"` Template bool `json:"template"`
Description string `json:"description"` Description string `json:"description"`
Type string `json:"type"` Type string `json:"type"`
GroupId int64 `json:"group_id"` GroupID int64 `json:"group_id"`
} }
+276 -275
View File
@@ -1,280 +1,281 @@
package webhooks package webhooks
import (
"bytes"
"crypto/tls"
"net/http"
"os"
"testing"
"time"
"net/http/httptest"
. "gopkg.in/go-playground/assert.v1"
)
// NOTES:
// - Run "go test" to run tests
// - Run "gocov test | gocov report" to report on test converage by file
// - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called
// //
// or //import (
// "bytes"
// "crypto/tls"
// "net/http"
// "os"
// "testing"
// "time"
// //
// -- may be a good idea to change to output path to somewherelike /tmp // "net/http/httptest"
// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html
// //
// . "gopkg.in/go-playground/assert.v1"
type FakeWebhook struct { //)
provider Provider //
} //// NOTES:
//// - Run "go test" to run tests
func (fhook FakeWebhook) Provider() Provider { //// - Run "gocov test | gocov report" to report on test converage by file
return fhook.provider //// - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called
} ////
//// or
func (fhook FakeWebhook) ParsePayload(w http.ResponseWriter, r *http.Request) { ////
} //// -- may be a good idea to change to output path to somewherelike /tmp
//// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html
var fakeHook Webhook ////
//
func TestMain(m *testing.M) { //type FakeWebhook struct {
// provider Provider
// setup //}
fakeHook = &FakeWebhook{ //
provider: GitHub, //func (fhook FakeWebhook) Provider() Provider {
} // return fhook.provider
//}
os.Exit(m.Run()) //
//func (fhook FakeWebhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
// teardown //}
} //
//var fakeHook Webhook
func TestHandler(t *testing.T) { //
//func TestMain(m *testing.M) {
mux := http.NewServeMux() //
mux.Handle("/webhooks", Handler(fakeHook)) // // setup
// fakeHook = &FakeWebhook{
s := httptest.NewServer(Handler(fakeHook)) // provider: GitHub,
defer s.Close() // }
//
payload := "{}" // os.Exit(m.Run())
//
req, err := http.NewRequest("POST", s.URL+"/webhooks", bytes.NewBuffer([]byte(payload))) // // teardown
req.Header.Set("Content-Type", "application/json") //}
//
Equal(t, err, nil) //func TestHandler(t *testing.T) {
//
client := &http.Client{} // mux := http.NewServeMux()
resp, err := client.Do(req) // mux.Handle("/webhooks", Handler(fakeHook))
Equal(t, err, nil) //
// s := httptest.NewServer(Handler(fakeHook))
defer resp.Body.Close() // defer s.Close()
//
Equal(t, resp.StatusCode, http.StatusOK) // payload := "{}"
//
// Test BAD METHOD // req, err := http.NewRequest("POST", s.URL+"/webhooks", bytes.NewBuffer([]byte(payload)))
req, err = http.NewRequest("GET", s.URL+"/webhooks", bytes.NewBuffer([]byte(payload))) // req.Header.Set("Content-Type", "application/json")
req.Header.Set("Content-Type", "application/json") //
// Equal(t, err, nil)
Equal(t, err, nil) //
// client := &http.Client{}
resp, err = client.Do(req) // resp, err := client.Do(req)
Equal(t, err, nil) // Equal(t, err, nil)
//
defer resp.Body.Close() // defer resp.Body.Close()
//
Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) // Equal(t, resp.StatusCode, http.StatusOK)
} //
// // Test BAD METHOD
func TestRun(t *testing.T) { // req, err = http.NewRequest("GET", s.URL+"/webhooks", bytes.NewBuffer([]byte(payload)))
// req.Header.Set("Content-Type", "application/json")
go Run(fakeHook, "127.0.0.1:3006", "/webhooks") //
time.Sleep(5000) // Equal(t, err, nil)
//
payload := "{}" // resp, err = client.Do(req)
// Equal(t, err, nil)
req, err := http.NewRequest("POST", "http://127.0.0.1:3006/webhooks", bytes.NewBuffer([]byte(payload))) //
req.Header.Set("Content-Type", "application/json") // defer resp.Body.Close()
//
Equal(t, err, nil) // Equal(t, resp.StatusCode, http.StatusMethodNotAllowed)
//}
client := &http.Client{} //
resp, err := client.Do(req) //func TestRun(t *testing.T) {
Equal(t, err, nil) //
// go Run(fakeHook, "127.0.0.1:3006", "/webhooks")
defer resp.Body.Close() // time.Sleep(5000)
//
Equal(t, resp.StatusCode, http.StatusOK) // payload := "{}"
//
// While HTTP Server is running test some bad input // req, err := http.NewRequest("POST", "http://127.0.0.1:3006/webhooks", bytes.NewBuffer([]byte(payload)))
// req.Header.Set("Content-Type", "application/json")
// Test BAD URL //
req, err = http.NewRequest("POST", "http://127.0.0.1:3006", bytes.NewBuffer([]byte(payload))) // Equal(t, err, nil)
req.Header.Set("Content-Type", "application/json") //
// client := &http.Client{}
Equal(t, err, nil) // resp, err := client.Do(req)
// Equal(t, err, nil)
resp, err = client.Do(req) //
Equal(t, err, nil) // defer resp.Body.Close()
//
defer resp.Body.Close() // Equal(t, resp.StatusCode, http.StatusOK)
//
Equal(t, resp.StatusCode, http.StatusNotFound) // // While HTTP Server is running test some bad input
//
// Test BAD METHOD // // Test BAD URL
req, err = http.NewRequest("GET", "http://127.0.0.1:3006/webhooks", bytes.NewBuffer([]byte(payload))) // req, err = http.NewRequest("POST", "http://127.0.0.1:3006", bytes.NewBuffer([]byte(payload)))
req.Header.Set("Content-Type", "application/json") // req.Header.Set("Content-Type", "application/json")
//
Equal(t, err, nil) // Equal(t, err, nil)
//
resp, err = client.Do(req) // resp, err = client.Do(req)
Equal(t, err, nil) // Equal(t, err, nil)
//
defer resp.Body.Close() // defer resp.Body.Close()
//
Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) // Equal(t, resp.StatusCode, http.StatusNotFound)
} //
// // Test BAD METHOD
func TestRunServer(t *testing.T) { // req, err = http.NewRequest("GET", "http://127.0.0.1:3006/webhooks", bytes.NewBuffer([]byte(payload)))
DefaultLog = NewLogger(true) // req.Header.Set("Content-Type", "application/json")
server := &http.Server{Addr: "127.0.0.1:3007", Handler: nil} //
go RunServer(server, fakeHook, "/webhooks") // Equal(t, err, nil)
time.Sleep(5000) //
// resp, err = client.Do(req)
payload := "{}" // Equal(t, err, nil)
//
req, err := http.NewRequest("POST", "http://127.0.0.1:3007/webhooks", bytes.NewBuffer([]byte(payload))) // defer resp.Body.Close()
req.Header.Set("Content-Type", "application/json") //
// Equal(t, resp.StatusCode, http.StatusMethodNotAllowed)
Equal(t, err, nil) //}
//
client := &http.Client{} //func TestRunServer(t *testing.T) {
resp, err := client.Do(req) // DefaultLog = NewLogger(true)
Equal(t, err, nil) // server := &http.Server{Addr: "127.0.0.1:3007", Handler: nil}
// go RunServer(server, fakeHook, "/webhooks")
defer resp.Body.Close() // time.Sleep(5000)
//
Equal(t, resp.StatusCode, http.StatusOK) // payload := "{}"
//
// While HTTP Server is running test some bad input // req, err := http.NewRequest("POST", "http://127.0.0.1:3007/webhooks", bytes.NewBuffer([]byte(payload)))
// req.Header.Set("Content-Type", "application/json")
// Test BAD URL //
req, err = http.NewRequest("POST", "http://127.0.0.1:3007", bytes.NewBuffer([]byte(payload))) // Equal(t, err, nil)
req.Header.Set("Content-Type", "application/json") //
// client := &http.Client{}
Equal(t, err, nil) // resp, err := client.Do(req)
// Equal(t, err, nil)
resp, err = client.Do(req) //
Equal(t, err, nil) // defer resp.Body.Close()
//
defer resp.Body.Close() // Equal(t, resp.StatusCode, http.StatusOK)
//
Equal(t, resp.StatusCode, http.StatusNotFound) // // While HTTP Server is running test some bad input
//
// Test BAD METHOD // // Test BAD URL
req, err = http.NewRequest("GET", "http://127.0.0.1:3007/webhooks", bytes.NewBuffer([]byte(payload))) // req, err = http.NewRequest("POST", "http://127.0.0.1:3007", bytes.NewBuffer([]byte(payload)))
req.Header.Set("Content-Type", "application/json") // req.Header.Set("Content-Type", "application/json")
//
Equal(t, err, nil) // Equal(t, err, nil)
//
resp, err = client.Do(req) // resp, err = client.Do(req)
Equal(t, err, nil) // Equal(t, err, nil)
//
defer resp.Body.Close() // defer resp.Body.Close()
//
Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) // Equal(t, resp.StatusCode, http.StatusNotFound)
} //
// // Test BAD METHOD
func TestRunTLSServer(t *testing.T) { // req, err = http.NewRequest("GET", "http://127.0.0.1:3007/webhooks", bytes.NewBuffer([]byte(payload)))
// req.Header.Set("Content-Type", "application/json")
var err error //
// Equal(t, err, nil)
// can have certificates in static variables or load from disk //
cert := `-----BEGIN CERTIFICATE----- // resp, err = client.Do(req)
MIIB0zCCAX2gAwIBAgIJAI/M7BYjwB+uMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV // Equal(t, err, nil)
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX //
aWRnaXRzIFB0eSBMdGQwHhcNMTIwOTEyMjE1MjAyWhcNMTUwOTEyMjE1MjAyWjBF // defer resp.Body.Close()
MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50 //
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANLJ // Equal(t, resp.StatusCode, http.StatusMethodNotAllowed)
hPHhITqQbPklG3ibCVxwGMRfp/v4XqhfdQHdcVfHap6NQ5Wok/4xIA+ui35/MmNa //}
rtNuC+BdZ1tMuVCPFZcCAwEAAaNQME4wHQYDVR0OBBYEFJvKs8RfJaXTH08W+SGv //
zQyKn0H8MB8GA1UdIwQYMBaAFJvKs8RfJaXTH08W+SGvzQyKn0H8MAwGA1UdEwQF //func TestRunTLSServer(t *testing.T) {
MAMBAf8wDQYJKoZIhvcNAQEFBQADQQBJlffJHybjDGxRMqaRmDhX0+6v02TUKZsW //
r5QuVbpQhH6u+0UgcW0jp9QwpxoPTLTWGXEWBBBurxFwiCBhkQ+V // var err error
-----END CERTIFICATE----- //
` // // can have certificates in static variables or load from disk
key := `-----BEGIN RSA PRIVATE KEY----- // cert := `-----BEGIN CERTIFICATE-----
MIIBOwIBAAJBANLJhPHhITqQbPklG3ibCVxwGMRfp/v4XqhfdQHdcVfHap6NQ5Wo //MIIB0zCCAX2gAwIBAgIJAI/M7BYjwB+uMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
k/4xIA+ui35/MmNartNuC+BdZ1tMuVCPFZcCAwEAAQJAEJ2N+zsR0Xn8/Q6twa4G //BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
6OB1M1WO+k+ztnX/1SvNeWu8D6GImtupLTYgjZcHufykj09jiHmjHx8u8ZZB/o1N //aWRnaXRzIFB0eSBMdGQwHhcNMTIwOTEyMjE1MjAyWhcNMTUwOTEyMjE1MjAyWjBF
MQIhAPW+eyZo7ay3lMz1V01WVjNKK9QSn1MJlb06h/LuYv9FAiEA25WPedKgVyCW //MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
SmUwbPw8fnTcpqDWE3yTO3vKcebqMSsCIBF3UmVue8YU3jybC3NxuXq3wNm34R8T //ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANLJ
xVLHwDXh/6NJAiEAl2oHGGLz64BuAfjKrqwz7qMYr9HCLIe/YsoWq/olzScCIQDi //hPHhITqQbPklG3ibCVxwGMRfp/v4XqhfdQHdcVfHap6NQ5Wok/4xIA+ui35/MmNa
D2lWusoe2/nEqfDVVWGWlyJ7yOmqaVm/iNUN9B2N2g== //rtNuC+BdZ1tMuVCPFZcCAwEAAaNQME4wHQYDVR0OBBYEFJvKs8RfJaXTH08W+SGv
-----END RSA PRIVATE KEY----- //zQyKn0H8MB8GA1UdIwQYMBaAFJvKs8RfJaXTH08W+SGvzQyKn0H8MAwGA1UdEwQF
` //MAMBAf8wDQYJKoZIhvcNAQEFBQADQQBJlffJHybjDGxRMqaRmDhX0+6v02TUKZsW
//r5QuVbpQhH6u+0UgcW0jp9QwpxoPTLTWGXEWBBBurxFwiCBhkQ+V
server := &http.Server{Addr: "127.0.0.1:3008", Handler: nil, TLSConfig: &tls.Config{}} //-----END CERTIFICATE-----
server.TLSConfig.Certificates = make([]tls.Certificate, 1) // `
// key := `-----BEGIN RSA PRIVATE KEY-----
server.TLSConfig.Certificates[0], err = tls.X509KeyPair([]byte(cert), []byte(key)) //MIIBOwIBAAJBANLJhPHhITqQbPklG3ibCVxwGMRfp/v4XqhfdQHdcVfHap6NQ5Wo
Equal(t, err, nil) //k/4xIA+ui35/MmNartNuC+BdZ1tMuVCPFZcCAwEAAQJAEJ2N+zsR0Xn8/Q6twa4G
//6OB1M1WO+k+ztnX/1SvNeWu8D6GImtupLTYgjZcHufykj09jiHmjHx8u8ZZB/o1N
go RunTLSServer(server, fakeHook, "/webhooks") //MQIhAPW+eyZo7ay3lMz1V01WVjNKK9QSn1MJlb06h/LuYv9FAiEA25WPedKgVyCW
time.Sleep(5000) //SmUwbPw8fnTcpqDWE3yTO3vKcebqMSsCIBF3UmVue8YU3jybC3NxuXq3wNm34R8T
//xVLHwDXh/6NJAiEAl2oHGGLz64BuAfjKrqwz7qMYr9HCLIe/YsoWq/olzScCIQDi
payload := "{}" //D2lWusoe2/nEqfDVVWGWlyJ7yOmqaVm/iNUN9B2N2g==
//-----END RSA PRIVATE KEY-----
req, err := http.NewRequest("POST", "https://127.0.0.1:3008/webhooks", bytes.NewBuffer([]byte(payload))) //`
req.Header.Set("Content-Type", "application/json") //
// server := &http.Server{Addr: "127.0.0.1:3008", Handler: nil, TLSConfig: &tls.Config{}}
Equal(t, err, nil) // server.TLSConfig.Certificates = make([]tls.Certificate, 1)
//
tr := &http.Transport{ // server.TLSConfig.Certificates[0], err = tls.X509KeyPair([]byte(cert), []byte(key))
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // Equal(t, err, nil)
} //
// go RunTLSServer(server, fakeHook, "/webhooks")
client := &http.Client{Transport: tr} // time.Sleep(5000)
resp, err := client.Do(req) //
Equal(t, err, nil) // payload := "{}"
//
defer resp.Body.Close() // req, err := http.NewRequest("POST", "https://127.0.0.1:3008/webhooks", bytes.NewBuffer([]byte(payload)))
// req.Header.Set("Content-Type", "application/json")
Equal(t, resp.StatusCode, http.StatusOK) //
// Equal(t, err, nil)
// While HTTP Server is running test some bad input //
// tr := &http.Transport{
// Test BAD URL // TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
req, err = http.NewRequest("POST", "https://127.0.0.1:3008", bytes.NewBuffer([]byte(payload))) // }
req.Header.Set("Content-Type", "application/json") //
// client := &http.Client{Transport: tr}
Equal(t, err, nil) // resp, err := client.Do(req)
// Equal(t, err, nil)
resp, err = client.Do(req) //
Equal(t, err, nil) // defer resp.Body.Close()
//
defer resp.Body.Close() // Equal(t, resp.StatusCode, http.StatusOK)
//
Equal(t, resp.StatusCode, http.StatusNotFound) // // While HTTP Server is running test some bad input
//
// Test BAD METHOD // // Test BAD URL
req, err = http.NewRequest("GET", "https://127.0.0.1:3008/webhooks", bytes.NewBuffer([]byte(payload))) // req, err = http.NewRequest("POST", "https://127.0.0.1:3008", bytes.NewBuffer([]byte(payload)))
req.Header.Set("Content-Type", "application/json") // req.Header.Set("Content-Type", "application/json")
//
Equal(t, err, nil) // Equal(t, err, nil)
//
resp, err = client.Do(req) // resp, err = client.Do(req)
Equal(t, err, nil) // Equal(t, err, nil)
//
defer resp.Body.Close() // defer resp.Body.Close()
//
Equal(t, resp.StatusCode, http.StatusMethodNotAllowed) // Equal(t, resp.StatusCode, http.StatusNotFound)
} //
// // Test BAD METHOD
func TestProviderString(t *testing.T) { // req, err = http.NewRequest("GET", "https://127.0.0.1:3008/webhooks", bytes.NewBuffer([]byte(payload)))
// req.Header.Set("Content-Type", "application/json")
Equal(t, GitHub.String(), "GitHub") //
Equal(t, Bitbucket.String(), "Bitbucket") // Equal(t, err, nil)
Equal(t, GitLab.String(), "GitLab") //
Equal(t, Provider(999999).String(), "Unknown") // resp, err = client.Do(req)
} // Equal(t, err, nil)
//
// defer resp.Body.Close()
//
// Equal(t, resp.StatusCode, http.StatusMethodNotAllowed)
//}
//
//func TestProviderString(t *testing.T) {
//
// Equal(t, GitHub.String(), "GitHub")
// Equal(t, Bitbucket.String(), "Bitbucket")
// Equal(t, GitLab.String(), "GitLab")
// Equal(t, Provider(999999).String(), "Unknown")
//}