4
0

integrations_env_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package httpapi
  2. import (
  3. "testing"
  4. "github.com/gnacho/netpulse/server-go/internal/rintegration"
  5. )
  6. // seedVendor devuelve un vendor de la semilla embebida del catálogo (#1697).
  7. func seedVendor(t *testing.T, id string) rintegration.Vendor {
  8. t.Helper()
  9. v, ok := rintegration.NewCatalog(nil).Lookup(id)
  10. if !ok {
  11. t.Fatalf("vendor %q missing from the embedded seed", id)
  12. }
  13. return v
  14. }
  15. func TestPusherEnvWritesIntervalWithUnit(t *testing.T) {
  16. s := &server{}
  17. v := seedVendor(t, "routeros")
  18. row := rintegration.Row{Slug: "lab", Host: "10.0.0.1", Username: "u", IntervalS: 30}
  19. env := s.pusherEnv(v, row, "secret", "https://np.example", "tok")
  20. if got := env["NETPULSE_INTERVAL"]; got != "30s" {
  21. t.Fatalf("NETPULSE_INTERVAL = %q, want 30s", got)
  22. }
  23. if got := env["ROUTEROS_HOST"]; got != "10.0.0.1" {
  24. t.Fatalf("ROUTEROS_HOST = %q, want 10.0.0.1", got)
  25. }
  26. asus := seedVendor(t, "asuswrt")
  27. sshEnv := s.pusherEnv(asus, row, "secret", "https://np.example", "tok")
  28. if got := sshEnv["ASUSWRT_HOST"]; got != "127.0.0.1" {
  29. t.Fatalf("ASUSWRT_HOST = %q, want 127.0.0.1", got)
  30. }
  31. if got := sshEnv["NETPULSE_INTERVAL"]; got != "30s" {
  32. t.Fatalf("ssh NETPULSE_INTERVAL = %q, want 30s", got)
  33. }
  34. }