integrations_env_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package httpapi
  2. import (
  3. "testing"
  4. "github.com/gnacho/netpulse/server-go/internal/rintegration"
  5. )
  6. func TestPusherEnvWritesIntervalWithUnit(t *testing.T) {
  7. s := &server{}
  8. v, ok := rintegration.LookupVendor("routeros")
  9. if !ok {
  10. t.Fatal("routeros vendor missing")
  11. }
  12. row := rintegration.Row{Slug: "lab", Host: "10.0.0.1", Username: "u", IntervalS: 30}
  13. env := s.pusherEnv(v, row, "secret", "https://np.example", "tok")
  14. if got := env["NETPULSE_INTERVAL"]; got != "30s" {
  15. t.Fatalf("NETPULSE_INTERVAL = %q, want 30s", got)
  16. }
  17. if got := env["ROUTEROS_HOST"]; got != "10.0.0.1" {
  18. t.Fatalf("ROUTEROS_HOST = %q, want 10.0.0.1", got)
  19. }
  20. asus, ok := rintegration.LookupVendor("asuswrt")
  21. if !ok {
  22. t.Fatal("asuswrt vendor missing")
  23. }
  24. sshEnv := s.pusherEnv(asus, row, "secret", "https://np.example", "tok")
  25. if got := sshEnv["ASUSWRT_HOST"]; got != "127.0.0.1" {
  26. t.Fatalf("ASUSWRT_HOST = %q, want 127.0.0.1", got)
  27. }
  28. if got := sshEnv["NETPULSE_INTERVAL"]; got != "30s" {
  29. t.Fatalf("ssh NETPULSE_INTERVAL = %q, want 30s", got)
  30. }
  31. }