2017-05-03 06:52:14 +02:00
|
|
|
// Package that contains all api routes of this microservice
|
2017-03-25 16:09:17 +01:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2017-04-04 07:37:39 +02:00
|
|
|
"github.com/genofire/hs_master-kss-monolith/lib/database"
|
|
|
|
"github.com/genofire/hs_master-kss-monolith/models"
|
2017-03-25 16:09:17 +01:00
|
|
|
"github.com/genofire/hs_master-kss-monolith/test"
|
|
|
|
)
|
|
|
|
|
2017-05-03 06:52:14 +02:00
|
|
|
// Function to test status()
|
2017-03-25 16:09:17 +01:00
|
|
|
func TestStatus(t *testing.T) {
|
|
|
|
assertion, router := test.Init(t)
|
2017-03-30 19:05:33 +02:00
|
|
|
|
2017-03-25 16:09:17 +01:00
|
|
|
BindAPI(router)
|
|
|
|
session := test.NewSession(router)
|
|
|
|
|
2017-04-04 07:37:39 +02:00
|
|
|
database.Write.Create(&models.Good{
|
|
|
|
ProductID: 3,
|
2017-04-04 19:28:46 +02:00
|
|
|
Position: "regal 1",
|
2017-04-04 07:37:39 +02:00
|
|
|
})
|
|
|
|
database.Write.Create(&models.Good{
|
|
|
|
ProductID: 3,
|
2017-04-04 19:28:46 +02:00
|
|
|
Position: "regal 2",
|
2017-04-04 07:37:39 +02:00
|
|
|
})
|
|
|
|
database.Write.Create(&models.Good{
|
|
|
|
ProductID: 1,
|
2017-04-04 19:28:46 +02:00
|
|
|
Position: "regal 10",
|
2017-04-04 07:37:39 +02:00
|
|
|
})
|
|
|
|
|
2017-03-30 18:43:18 +02:00
|
|
|
r, w := session.JSONRequest("GET", "/api/status", nil)
|
|
|
|
result := r.(map[string]interface{})
|
2017-03-25 16:09:17 +01:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
2017-03-30 18:43:18 +02:00
|
|
|
assertion.Equal("running", result["status"])
|
2017-04-04 07:37:39 +02:00
|
|
|
|
|
|
|
db := result["database"].(map[string]interface{})
|
|
|
|
assertion.Equal(true, db["read"])
|
|
|
|
assertion.Equal(true, db["write"])
|
|
|
|
|
2017-04-03 14:59:43 +02:00
|
|
|
good := result["good"].(map[string]interface{})
|
2017-04-04 07:37:39 +02:00
|
|
|
assertion.Equal(float64(3), good["count"])
|
|
|
|
assertion.Equal(float64(1.5), good["avg"])
|
2017-03-25 16:09:17 +01:00
|
|
|
|
2017-03-30 19:05:33 +02:00
|
|
|
test.Close()
|
2017-03-25 16:09:17 +01:00
|
|
|
}
|