Skip to content

Instantly share code, notes, and snippets.

@bxcodec
Created July 7, 2017 10:07
Show Gist options
  • Save bxcodec/ddfc49d557d74a177d5f259af4bd6ae3 to your computer and use it in GitHub Desktop.
Save bxcodec/ddfc49d557d74a177d5f259af4bd6ae3 to your computer and use it in GitHub Desktop.
Delivery Test
func TestGetByID(t *testing.T) {
var mockArticle models.Article
err := faker.FakeData(&mockArticle)
assert.NoError(t, err)
mockUCase := new(mocks.ArticleUsecase)
num := int(mockArticle.ID)
mockUCase.On("GetByID", int64(num)).Return(&mockArticle, nil)
e := echo.New()
req, err := http.NewRequest(echo.GET, "/article/"+strconv.Itoa(int(num)), strings.NewReader(""))
assert.NoError(t, err)
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("article/:id")
c.SetParamNames("id")
c.SetParamValues(strconv.Itoa(num))
handler := articleHttp.ArticleHandler{AUsecase: mockUCase, Helper: httpHelper.HttpHelper{}}
handler.GetByID(c)
assert.Equal(t, http.StatusOK, rec.Code)
mockUCase.AssertCalled(t, "GetByID", int64(num))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment