HTTP Triggers hookup (#1086)

* Initial suypport for invoking tiggers

* dupe method

* tighten server constraints

* runner tests not working yet

* basic route tests passing

* post rebase fixes

* add hybrid support for trigger invoke and tests

* consoloidate all hybrid evil into one place

* cleanup and make triggers unique by source

* fix oops with Agent

* linting

* review fixes
This commit is contained in:
Owen Cliffe
2018-07-05 18:56:07 +01:00
committed by Reed Allman
parent b07a000a18
commit b8b544ed25
38 changed files with 2208 additions and 865 deletions

69
api/server/hybrid_test.go Normal file
View File

@@ -0,0 +1,69 @@
package server
import (
"bytes"
"encoding/json"
"github.com/fnproject/fn/api/datastore"
"github.com/fnproject/fn/api/id"
"github.com/fnproject/fn/api/logs"
"github.com/fnproject/fn/api/models"
"github.com/fnproject/fn/api/mqs"
"net/http"
"strings"
"testing"
)
func TestHybridEndpoints(t *testing.T) {
buf := setLogBuffer()
app := &models.App{ID: "app_id", Name: "myapp"}
ds := datastore.NewMockInit(
[]*models.App{app},
[]*models.Route{{
AppID: app.ID,
Path: "yodawg",
}},
)
logDB := logs.NewMock()
srv := testServer(ds, &mqs.Mock{}, logDB, nil /* TODO */, ServerTypeAPI)
newCallBody := func() string {
call := &models.Call{
AppID: app.ID,
ID: id.New().String(),
Path: "yodawg",
// TODO ?
}
var b bytes.Buffer
json.NewEncoder(&b).Encode(&call)
return b.String()
}
for _, test := range []struct {
name string
method string
path string
body string
expectedCode int
}{
// TODO change all these tests to just do an async task in normal order once plumbing is done
{"post async call", "PUT", "/v2/runner/async", newCallBody(), http.StatusNoContent},
// TODO this one only works if it's not the same as the first since update isn't hooked up
{"finish call", "POST", "/v2/runner/finish", newCallBody(), http.StatusNoContent},
// TODO these won't work until update works and the agent gets shut off
//{"get async call", "GET", "/v1/runner/async", "", http.StatusOK},
//{"start call", "POST", "/v1/runner/start", "TODO", http.StatusOK},
} {
_, rec := routerRequest(t, srv.Router, test.method, test.path, strings.NewReader(test.body))
if rec.Code != test.expectedCode {
t.Log(buf.String())
t.Errorf("Test \"%s\": Expected status code to be %d but was %d",
test.name, test.expectedCode, rec.Code)
}
}
}