2017-10-01 15:29:25 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/httptest"
|
2017-10-01 15:29:25 +02:00
|
|
|
)
|
|
|
|
|
2017-10-22 15:04:11 +02:00
|
|
|
// go test -v
|
2017-10-01 15:29:25 +02:00
|
|
|
func TestApp(t *testing.T) {
|
2017-11-23 11:30:13 +01:00
|
|
|
app := newApp()
|
2017-10-01 15:29:25 +02:00
|
|
|
e := httptest.New(t, app.Application)
|
|
|
|
|
|
|
|
// test our routes
|
|
|
|
e.GET("/").Expect().Status(httptest.StatusOK)
|
|
|
|
e.GET("/follower/42").Expect().Status(httptest.StatusOK).
|
2020-06-07 14:26:06 +02:00
|
|
|
Body().Equal("from /follower/{id:int64} with ID: 42")
|
2017-10-01 15:29:25 +02:00
|
|
|
e.GET("/following/52").Expect().Status(httptest.StatusOK).
|
2020-06-07 14:26:06 +02:00
|
|
|
Body().Equal("from /following/{id:int64} with ID: 52")
|
2017-10-01 15:29:25 +02:00
|
|
|
e.GET("/like/64").Expect().Status(httptest.StatusOK).
|
2020-06-07 14:26:06 +02:00
|
|
|
Body().Equal("from /like/{id:int64} with ID: 64")
|
2017-10-01 15:29:25 +02:00
|
|
|
|
|
|
|
// test not found
|
|
|
|
e.GET("/notfound").Expect().Status(httptest.StatusNotFound)
|
|
|
|
expectedErr := map[string]interface{}{
|
|
|
|
"app": app.AppName,
|
|
|
|
"status": httptest.StatusNotFound,
|
|
|
|
"message": "",
|
|
|
|
}
|
|
|
|
e.GET("/anotfoundwithjson").WithQuery("json", nil).
|
|
|
|
Expect().Status(httptest.StatusNotFound).JSON().Equal(expectedErr)
|
|
|
|
}
|