interval_1476_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package reinstall_test
  2. import (
  3. "os/exec"
  4. "strings"
  5. "testing"
  6. "github.com/gnacho/netpulse/server-go/internal/reinstall"
  7. )
  8. // #1476: el intervalo del agente es un ajuste por router y el script lo
  9. // escribe en la config UCI del paquete, que es el conffile que sobrevive a
  10. // un sysupgrade. Con 0 se borra la clave y el agente vuelve a su default.
  11. func TestScriptSyncsAgentInterval(t *testing.T) {
  12. token := strings.Repeat("a1", 32)
  13. s := reinstall.ScriptWithTargets(
  14. "test-router", token, "https://192.168.1.226:3000", "sha256//AAAA",
  15. map[string]string{"arm64": "cafebabe"},
  16. reinstall.WanTargets{Interval: 90},
  17. )
  18. if !strings.Contains(s, `uci -q set netpulse-agent.main.interval="90"`) {
  19. t.Error("el script no escribe el intervalo configurado")
  20. }
  21. if err := exec.Command("sh", "-n", "-c", s).Run(); err != nil {
  22. t.Fatalf("script inválido con intervalo: %v", err)
  23. }
  24. zero := reinstall.ScriptWithTargets(
  25. "test-router", token, "https://192.168.1.226:3000", "sha256//AAAA",
  26. map[string]string{"arm64": "cafebabe"},
  27. reinstall.WanTargets{},
  28. )
  29. if !strings.Contains(zero, "uci -q delete netpulse-agent.main.interval") {
  30. t.Error("con intervalo 0 el script debe borrar la clave")
  31. }
  32. if strings.Contains(zero, `uci -q set netpulse-agent.main.interval=""`) {
  33. t.Error("no debe escribir un intervalo vacío")
  34. }
  35. }