trigger test
parent
0a23484069
commit
6b8df0e4fd
|
@ -0,0 +1,52 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
|
||||
"github.com/rusenask/keel/provider"
|
||||
"github.com/rusenask/keel/types"
|
||||
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type fakeProvider struct {
|
||||
submitted []types.Event
|
||||
}
|
||||
|
||||
func (p *fakeProvider) Submit(event types.Event) error {
|
||||
p.submitted = append(p.submitted, event)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *fakeProvider) GetName() string {
|
||||
return "fakeProvider"
|
||||
}
|
||||
|
||||
func TestNativeWebhookHandler(t *testing.T) {
|
||||
|
||||
fp := &fakeProvider{}
|
||||
providers := map[string]provider.Provider{
|
||||
fp.GetName(): fp,
|
||||
}
|
||||
srv := NewTriggerServer(&Opts{Providers: providers})
|
||||
srv.registerRoutes(srv.router)
|
||||
|
||||
req, err := http.NewRequest("POST", "/v1/native", bytes.NewBuffer([]byte(`{"client":"test_client", "mountpoint": "xx"}`)))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create req: %s", err)
|
||||
}
|
||||
|
||||
//The response recorder used to record HTTP responses
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
srv.router.ServeHTTP(rec, req)
|
||||
if rec.Code != 200 {
|
||||
t.Errorf("unexpected status code: %d", rec.Code)
|
||||
}
|
||||
|
||||
if len(fp.submitted) != 1 {
|
||||
t.Errorf("unexpected number of events submitted: %d", len(fp.submitted))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue