S15: sm-leaf health HTTP, verae.sm.* acks, systemd unit
Loopback GET /health, nats-leaf:// rewrite, subject request-reply tests. Do not replace pfc-py-admin. NpeRequired stays on the package surface.
This commit is contained in:
parent
9eed0b1942
commit
f4da7ff446
7 changed files with 158 additions and 11 deletions
|
|
@ -1,6 +1,12 @@
|
|||
package leaf
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestStartInProcess(t *testing.T) {
|
||||
n, err := Start("")
|
||||
|
|
@ -12,3 +18,57 @@ func TestStartInProcess(t *testing.T) {
|
|||
t.Fatal("empty addr")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHubLeafScheme(t *testing.T) {
|
||||
u, err := ParseHub("nats-leaf://10.10.10.21:7422")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if u.Scheme != "nats" {
|
||||
t.Fatalf("scheme %s", u.Scheme)
|
||||
}
|
||||
if u.Host != "10.10.10.21:7422" {
|
||||
t.Fatalf("host %s", u.Host)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthHandler(t *testing.T) {
|
||||
srv := httptest.NewServer(HealthHandler())
|
||||
defer srv.Close()
|
||||
resp, err := srv.Client().Get(srv.URL + "/health")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
var m map[string]any
|
||||
if err := json.Unmarshal(body, &m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m["ok"] != true || m["service"] != "sm-leaf" {
|
||||
t.Fatalf("health %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSMSubjectsAck(t *testing.T) {
|
||||
n, err := Start("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer n.Shutdown()
|
||||
cases := map[string]string{
|
||||
"verae.sm.send": `{"accepted":true}`,
|
||||
"verae.sm.dead": `{"queued":true}`,
|
||||
"verae.sm.error": `{"emitted":true}`,
|
||||
"verae.sm.log.summary": `{"logged":true}`,
|
||||
}
|
||||
for subj, want := range cases {
|
||||
msg, err := n.nc.Request(subj, []byte(`{"lookup_id":"t"}`), time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v", subj, err)
|
||||
}
|
||||
if string(msg.Data) != want {
|
||||
t.Fatalf("%s got %s want %s", subj, msg.Data, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue