(t *testing.T)
| 41 | } |
| 42 | |
| 43 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…