genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
hs_monolith/http/status_test.go

48 lines
1.1 KiB
Go
Raw Permalink Normal View History

// Package that contains all api routes of this microservice
2017-03-25 16:09:17 +01:00
package http
import (
"net/http"
"testing"
"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"
)
// 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)
database.Write.Create(&models.Good{
ProductID: 3,
Position: "regal 1",
})
database.Write.Create(&models.Good{
ProductID: 3,
Position: "regal 2",
})
database.Write.Create(&models.Good{
ProductID: 1,
Position: "regal 10",
})
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)
assertion.Equal("running", result["status"])
db := result["database"].(map[string]interface{})
assertion.Equal(true, db["read"])
assertion.Equal(true, db["write"])
good := result["good"].(map[string]interface{})
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
}