2022-11-23 20:21:49 +01:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWebserver(t *testing.T) {
|
2022-11-24 12:53:27 +01:00
|
|
|
ws, stop := NewSimpleWebserver()
|
|
|
|
defer stop()
|
2022-11-23 20:21:49 +01:00
|
|
|
go func() { ws.Run() }()
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPing(t *testing.T) {
|
2022-11-24 12:53:27 +01:00
|
|
|
ws, stop := NewSimpleWebserver()
|
|
|
|
defer stop()
|
2022-11-23 20:21:49 +01:00
|
|
|
go func() { ws.Run() }()
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
baseUrl := "http://127.0.0.1:" + ws.Port
|
|
|
|
|
2022-11-24 12:53:27 +01:00
|
|
|
_ = requestGet[Void](baseUrl, "/api/ping")
|
|
|
|
_ = requestPut[Void](baseUrl, "/api/ping", nil)
|
|
|
|
_ = requestPost[Void](baseUrl, "/api/ping", nil)
|
|
|
|
_ = requestPatch[Void](baseUrl, "/api/ping", nil)
|
|
|
|
_ = requestDelete[Void](baseUrl, "/api/ping", nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMongo(t *testing.T) {
|
|
|
|
ws, stop := NewSimpleWebserver()
|
|
|
|
defer stop()
|
|
|
|
go func() { ws.Run() }()
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
baseUrl := "http://127.0.0.1:" + ws.Port
|
|
|
|
|
|
|
|
_ = requestPost[Void](baseUrl, "/api/db-test", nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHealth(t *testing.T) {
|
|
|
|
ws, stop := NewSimpleWebserver()
|
|
|
|
defer stop()
|
|
|
|
go func() { ws.Run() }()
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
|
|
|
|
baseUrl := "http://127.0.0.1:" + ws.Port
|
2022-11-23 20:21:49 +01:00
|
|
|
|
2022-11-24 12:53:27 +01:00
|
|
|
_ = requestGet[Void](baseUrl, "/api/health")
|
2022-11-23 20:21:49 +01:00
|
|
|
}
|