mirror of
https://github.com/datarhei/core.git
synced 2025-10-04 15:42:57 +08:00
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/datarhei/core/http/api"
|
|
"github.com/datarhei/core/http/mock"
|
|
"github.com/datarhei/core/session"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func getDummySessionRouter() *echo.Echo {
|
|
router := mock.DummyEcho()
|
|
|
|
registry, _ := session.New(session.Config{})
|
|
registry.Register("foo", session.CollectorConfig{})
|
|
|
|
collector := registry.Collector("foo")
|
|
collector.RegisterAndActivate("foobar", "", "any", "any")
|
|
|
|
handler := NewSession(registry)
|
|
|
|
router.Add("GET", "/summary", handler.Summary)
|
|
router.Add("GET", "/active", handler.Active)
|
|
|
|
return router
|
|
}
|
|
|
|
func TestSessionSummary(t *testing.T) {
|
|
router := getDummySessionRouter()
|
|
|
|
response := mock.Request(t, http.StatusOK, router, "GET", "/summary?collectors=foo", nil)
|
|
|
|
mock.Validate(t, api.SessionsSummary{}, response.Data)
|
|
}
|
|
|
|
func TestSessionActive(t *testing.T) {
|
|
router := getDummySessionRouter()
|
|
|
|
response := mock.Request(t, http.StatusOK, router, "GET", "/active?collectors=foo", nil)
|
|
|
|
mock.Validate(t, api.SessionsActive{}, response.Data)
|
|
}
|