mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* 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
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
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)
|
|
}
|
|
}
|
|
}
|