2017-03-30 18:43:18 +02:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/genofire/hs_master-kss-monolith/lib/database"
|
2017-03-30 19:05:33 +02:00
|
|
|
"github.com/genofire/hs_master-kss-monolith/models"
|
2017-03-30 18:43:18 +02:00
|
|
|
|
|
|
|
"github.com/genofire/hs_master-kss-monolith/test"
|
|
|
|
)
|
|
|
|
|
2017-04-03 14:59:43 +02:00
|
|
|
func TestGood(t *testing.T) {
|
2017-03-30 18:43:18 +02:00
|
|
|
assertion, router := test.Init(t)
|
2017-03-30 19:05:33 +02:00
|
|
|
|
2017-03-30 18:43:18 +02:00
|
|
|
BindAPI(router)
|
|
|
|
session := test.NewSession(router)
|
|
|
|
|
2017-04-03 14:59:43 +02:00
|
|
|
result, w := session.JSONRequest("GET", "/api/good/a", nil)
|
2017-03-30 19:05:33 +02:00
|
|
|
assertion.Equal(http.StatusNotAcceptable, w.StatusCode)
|
|
|
|
|
2017-04-03 14:59:43 +02:00
|
|
|
result, w = session.JSONRequest("GET", "/api/good/1", nil)
|
2017-03-30 19:05:33 +02:00
|
|
|
assertion.Equal(http.StatusNotFound, w.StatusCode)
|
|
|
|
|
2017-04-03 14:59:43 +02:00
|
|
|
database.Write.Create(&models.Good{
|
|
|
|
ProductID: 3,
|
|
|
|
Comment: "blub",
|
2017-03-30 19:05:33 +02:00
|
|
|
})
|
|
|
|
|
2017-04-03 14:59:43 +02:00
|
|
|
result, w = session.JSONRequest("GET", "/api/good/3", nil)
|
2017-03-30 18:43:18 +02:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
2017-03-30 19:05:33 +02:00
|
|
|
assertion.Len(result, 1)
|
|
|
|
|
|
|
|
test.Close()
|
2017-03-30 18:43:18 +02:00
|
|
|
}
|