Files
nmon/internal/api/ops_test.go
jleung f85c3ef781
Some checks failed
ci / lint (push) Has been cancelled
ci / test (ubuntu-24.04-arm) (push) Has been cancelled
ci / test (ubuntu-latest) (push) Has been cancelled
ci / postgres (push) Has been cancelled
ci / openapi (push) Has been cancelled
M3: Go API per UI contract, embedded UI, openapi compat check, nmon-devtools, live gate + screenshots; M4 WP1 reachability and dependency suppression
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
2026-10-22 20:34:14 +00:00

44 lines
1.4 KiB
Go

package api_test
import (
"encoding/json"
"fmt"
"net/http"
"testing"
"github.com/v10networks/nmon/internal/api"
"github.com/v10networks/nmon/internal/fixturegen"
"github.com/v10networks/nmon/internal/simagent"
"github.com/v10networks/nmon/internal/testutil"
)
func TestDiscoverEndpointReportsAndRefreshes(t *testing.T) {
a := testutil.StartAgent(t, simagent.Config{
Recording: fixturegen.Generic(fixturegen.Options{Ports: 6, SysName: "d1", HCCounters: true}), Community: community,
})
e := newEnv(t, int(a.Addr().Port()))
body := fmt.Sprintf(`{"name":"D One","addresses":["::1"],"snmp":{"version":"v2c","community":%q}}`, community)
rec := e.do("POST", "/api/v1/devices", body)
if rec.Code != http.StatusCreated {
t.Fatalf("POST: %d %s", rec.Code, rec.Body)
}
var dev api.DeviceView
_ = json.Unmarshal(rec.Body.Bytes(), &dev)
rec = e.do("POST", "/api/v1/devices/"+dev.Slug+"/discover", "")
if rec.Code != http.StatusOK {
t.Fatalf("discover: %d %s", rec.Code, rec.Body)
}
var rep api.DiscoverView
if err := json.Unmarshal(rec.Body.Bytes(), &rep); err != nil {
t.Fatal(err)
}
if rep.InterfacesMatched != 6 || rep.InterfacesNew != 0 || rep.InterfacesRetired != 0 || rep.Partial || len(rep.Tables) == 0 {
t.Errorf("report %+v", rep)
}
if e.afterID.Load() == 0 {
t.Error("AfterDiscover not called")
}
isProblem(t, e.do("POST", "/api/v1/devices/no-such-device/discover", ""), 404)
}