Files
nmon/internal/app/settingsform_test.go
Vibe Coder f31fb3712a
Some checks failed
ci / lint (push) Successful in 4m19s
ci / openapi (push) Successful in 29s
ci / postgres (push) Successful in 4m55s
ci / test (push) Failing after 19m48s
Add settings forms, first-install wizard, webhook presets, help and poll tools
Make nmon easier to install and run without editing YAML by hand:

- Settings: point-and-click forms over config.yaml (GET/PUT
  /api/v1/settings/form); the YAML editor moves to /settings/yaml.
- First install: with no sign-in configured nmon starts in install
  mode, serves only the setup wizard (sign-in, basics, devices,
  alerting) and closes it for good once sign-in is saved. A
  self-signed certificate is generated when no TLS source is given.
  poller.interval becomes a config setting.
- Reverse proxies: opt-in --http-listen plain-HTTP listener beside
  HTTPS; sign-in stays required.
- Webhooks: Generic, Teams Adaptive Card, Slack and Discord presets,
  template preview and test send.
- Help: the operations, coverage and profile docs served at /help.
- Polling: per-device "Poll now", a dry-run test poll returning an
  SNMP trace, and time-limited in-memory SNMP debug recording, in the
  UI and as `nmon device poll`.
- Ansible: deploys into install mode when no sign-in is set, and no
  longer overwrites the config.yaml the wizard wrote.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017TuKgyKve2XLFtrrXWMi2w
2026-10-25 06:31:12 +00:00

32 lines
1.1 KiB
Go

package app
import (
"context"
"errors"
"strings"
"testing"
"github.com/v10networks/nmon/internal/api"
"github.com/v10networks/nmon/internal/config"
)
func TestUpdateConfigEditsOneSectionThroughTheYAMLValidationPath(t *testing.T) {
a, f := startWith(t, nil, "")
ctx := context.Background()
if _, err := a.Apply(ctx, "tester", "timezone: America/Toronto\nbackup: {at: \"01:00\"}\n"); err != nil {
t.Fatal(err)
}
_, err := a.UpdateConfig(ctx, "tester", func(c *config.Config) error { c.Disk = config.Disk{AlertUsed: 0.95, AdmitUsed: 0.9}; return nil })
if !errors.Is(err, api.ErrInvalidSettings) {
t.Fatalf("an invalid section: %v, want ErrInvalidSettings", err)
}
res, err := a.UpdateConfig(ctx, "tester", func(c *config.Config) error { c.Disk = config.Disk{AlertUsed: 0.7}; return nil })
if err != nil || strings.Join(res.Applied, " ") != "disk" {
t.Fatalf("applied %v, err %v", res.Applied, err)
}
cfg, err := config.Load(f.DataDir)
if err != nil || cfg.Timezone != "America/Toronto" || cfg.Backup.At != "01:00" || cfg.Disk.AlertUsed != 0.7 {
t.Fatalf("saved config = %+v, err %v: the other sections must be untouched", cfg, err)
}
}