(t *testing.T)
| 364 | } |
| 365 | |
| 366 | func TestGetServiceLog(t *testing.T) { |
| 367 | mockCtl := gomock.NewController(t) |
| 368 | defer mockCtl.Finish() |
| 369 | mockAmi := mock.NewMockAMI(mockCtl) |
| 370 | e := engineImpl{ |
| 371 | ami: mockAmi, |
| 372 | sto: nil, |
| 373 | nod: nil, |
| 374 | cfg: config.Config{}, |
| 375 | log: log.With(log.Any("engine", "any")), |
| 376 | } |
| 377 | assert.NotNil(t, e) |
| 378 | |
| 379 | router := routing.New() |
| 380 | router.Get("/services/<service>/log", e.GetServiceLog) |
| 381 | go fasthttp.ListenAndServe(":50030", router.HandleRequest) |
| 382 | time.Sleep(100 * time.Millisecond) |
| 383 | |
| 384 | client := &fasthttp.Client{} |
| 385 | |
| 386 | mockAmi.EXPECT().FetchLog("baetyl-edge", "service1", int64(10), int64(60)).Return(io.NopCloser(strings.NewReader("hello world")), nil).Times(1) |
| 387 | req := fasthttp.AcquireRequest() |
| 388 | resp := fasthttp.AcquireResponse() |
| 389 | url := fmt.Sprintf("%s%s", "http://127.0.0.1:50030", "/services/service1/log?tailLines=10&sinceSeconds=60") |
| 390 | req.SetRequestURI(url) |
| 391 | req.Header.SetMethod("GET") |
| 392 | err := client.Do(req, resp) |
| 393 | assert.NoError(t, err) |
| 394 | assert.Equal(t, resp.StatusCode(), 200) |
| 395 | assert.Equal(t, "hello world", string(resp.Body())) |
| 396 | |
| 397 | mockAmi.EXPECT().FetchLog("baetyl-edge", "unknown", int64(10), int64(60)).Return(nil, errors.New("error")).Times(1) |
| 398 | req2 := fasthttp.AcquireRequest() |
| 399 | resp2 := fasthttp.AcquireResponse() |
| 400 | url2 := fmt.Sprintf("%s%s", "http://127.0.0.1:50030", "/services/unknown/log?tailLines=10&sinceSeconds=60") |
| 401 | req2.SetRequestURI(url2) |
| 402 | req2.Header.SetMethod("GET") |
| 403 | err2 := client.Do(req2, resp2) |
| 404 | assert.NoError(t, err2) |
| 405 | assert.Equal(t, resp2.StatusCode(), 500) |
| 406 | |
| 407 | req3 := fasthttp.AcquireRequest() |
| 408 | resp3 := fasthttp.AcquireResponse() |
| 409 | url3 := fmt.Sprintf("%s%s", "http://127.0.0.1:50030", "/services/unknown/log?tailLines=a&sinceSeconds=12") |
| 410 | req3.SetRequestURI(url3) |
| 411 | req3.Header.SetMethod("GET") |
| 412 | err3 := client.Do(req3, resp3) |
| 413 | assert.NoError(t, err3) |
| 414 | assert.Equal(t, resp3.StatusCode(), 400) |
| 415 | |
| 416 | req4 := fasthttp.AcquireRequest() |
| 417 | resp4 := fasthttp.AcquireResponse() |
| 418 | url4 := fmt.Sprintf("%s%s", "http://127.0.0.1:50030", "/services/unknown/log?tailLines=12&sinceSeconds=a") |
| 419 | req4.SetRequestURI(url4) |
| 420 | req4.Header.SetMethod("GET") |
| 421 | err4 := client.Do(req4, resp4) |
| 422 | assert.NoError(t, err4) |
| 423 | assert.Equal(t, resp4.StatusCode(), 400) |
nothing calls this directly
no test coverage detected