mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Added async post command to README.
This commit is contained in:
@@ -136,7 +136,7 @@ func startAsyncRunners(ctx context.Context, wg *sync.WaitGroup, i int, url strin
|
||||
task, err := getTask(ctx, url)
|
||||
if err != nil {
|
||||
if err, ok := err.(net.Error); ok && err.Timeout() {
|
||||
log.Infoln("Could not fetch task, timeout. Probably no tasks to run.")
|
||||
log.WithError(err).Errorln("Could not fetch task, timeout.")
|
||||
continue
|
||||
}
|
||||
log.WithError(err).Error("Could not fetch task")
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
package server
|
||||
|
||||
// TODO: this whole file shouldn't be in a non test file
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
type appResponse struct {
|
||||
Message string `json:"message"`
|
||||
App *models.App `json:"app"`
|
||||
}
|
||||
|
||||
type appsResponse struct {
|
||||
Message string `json:"message"`
|
||||
Apps models.Apps `json:"apps"`
|
||||
}
|
||||
|
||||
type routeResponse struct {
|
||||
Message string `json:"message"`
|
||||
Route *models.Route `json:"route"`
|
||||
}
|
||||
|
||||
type routesResponse struct {
|
||||
Message string `json:"message"`
|
||||
Routes models.Routes `json:"routes"`
|
||||
}
|
||||
|
||||
type tasksResponse struct {
|
||||
Message string `json:"message"`
|
||||
Task models.Task `json:"tasksResponse"`
|
||||
}
|
||||
|
||||
func testRouter(s *Server) *gin.Engine {
|
||||
r := gin.Default()
|
||||
ctx := context.Background()
|
||||
r.Use(func(c *gin.Context) {
|
||||
ctx, _ := common.LoggerWithFields(ctx, extractFields(c))
|
||||
c.Set("ctx", ctx)
|
||||
c.Next()
|
||||
})
|
||||
s.bindHandlers()
|
||||
return r
|
||||
}
|
||||
|
||||
func testRunner(t *testing.T) *runner.Runner {
|
||||
r, err := runner.New(runner.NewMetricLogger())
|
||||
if err != nil {
|
||||
t.Fatal("Test: failed to create new runner")
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func routerRequest(t *testing.T, router *gin.Engine, method, path string, body io.Reader) (*http.Request, *httptest.ResponseRecorder) {
|
||||
req, err := http.NewRequest(method, "http://localhost:8080"+path, body)
|
||||
if err != nil {
|
||||
t.Fatalf("Test: Could not create %s request to %s: %v", method, path, err)
|
||||
}
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
router.ServeHTTP(rec, req)
|
||||
|
||||
return req, rec
|
||||
}
|
||||
|
||||
func getErrorResponse(t *testing.T, rec *httptest.ResponseRecorder) models.Error {
|
||||
respBody, err := ioutil.ReadAll(rec.Body)
|
||||
if err != nil {
|
||||
t.Error("Test: Expected not empty response body")
|
||||
}
|
||||
|
||||
var errResp models.Error
|
||||
err = json.Unmarshal(respBody, &errResp)
|
||||
if err != nil {
|
||||
t.Error("Test: Expected response body to be a valid models.Error object")
|
||||
}
|
||||
|
||||
return errResp
|
||||
}
|
||||
Reference in New Issue
Block a user