MCPcopy
hub / github.com/iron-io/functions / TestRouteRunnerAsyncExecution

Function TestRouteRunnerAsyncExecution

api/server/runner_async_test.go:43–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

41}
42
43func TestRouteRunnerAsyncExecution(t *testing.T) {
44 tasks := mockTasksConduit()
45 ds := datastore.NewMockInit(
46 []*models.App{
47 {Name: "myapp", Config: map[string]string{"app": "true"}},
48 },
49 []*models.Route{
50 {Type: "async", Path: "/myroute", AppName: "myapp", Image: "iron/hello", Config: map[string]string{"test": "true"}},
51 {Type: "async", Path: "/myerror", AppName: "myapp", Image: "iron/error", Config: map[string]string{"test": "true"}},
52 {Type: "async", Path: "/myroute/:param", AppName: "myapp", Image: "iron/hello", Config: map[string]string{"test": "true"}},
53 },
54 )
55 mq := &mqs.Mock{}
56
57 for i, test := range []struct {
58 path string
59 body string
60 headers map[string][]string
61 expectedCode int
62 expectedEnv map[string]string
63 }{
64 {"/r/myapp/myroute", ``, map[string][]string{}, http.StatusAccepted, map[string]string{"TEST": "true", "APP": "true"}},
65 // FIXME: this just hangs
66 //{"/r/myapp/myroute/1", ``, map[string][]string{}, http.StatusAccepted, map[string]string{"TEST": "true", "APP": "true"}},
67 {"/r/myapp/myerror", ``, map[string][]string{}, http.StatusAccepted, map[string]string{"TEST": "true", "APP": "true"}},
68 {"/r/myapp/myroute", `{ "name": "test" }`, map[string][]string{}, http.StatusAccepted, map[string]string{"TEST": "true", "APP": "true"}},
69 {
70 "/r/myapp/myroute",
71 ``,
72 map[string][]string{"X-Function": []string{"test"}},
73 http.StatusAccepted,
74 map[string]string{
75 "TEST": "true",
76 "APP": "true",
77 "HEADER_X_FUNCTION": "test",
78 },
79 },
80 } {
81 body := bytes.NewBuffer([]byte(test.body))
82 var wg sync.WaitGroup
83
84 wg.Add(1)
85 fmt.Println("About to start router")
86 rnr, cancel := testRunner(t)
87 router := testRouterAsync(ds, mq, rnr, tasks, func(_ context.Context, _ models.MessageQueue, task *models.Task) (*models.Task, error) {
88 if test.body != task.Payload {
89 t.Errorf("Test %d: Expected task Payload to be the same as the test body", i)
90 }
91
92 if test.expectedEnv != nil {
93 for name, value := range test.expectedEnv {
94 taskName := name
95 if value != task.EnvVars[taskName] {
96 t.Errorf("Test %d: Expected header `%s` to be `%s` but was `%s`",
97 i, name, value, task.EnvVars[taskName])
98 }
99 }
100 }

Callers

nothing calls this directly

Calls 6

mockTasksConduitFunction · 0.85
testRouterAsyncFunction · 0.85
newRouterRequestFunction · 0.85
testRunnerFunction · 0.70
SetMethod · 0.65
ServeHTTPMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…