reinstall_progress_1894_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // reinstall_progress_1894_test.go — el install cuenta lo que hace por stdout.
  2. // Sin esas líneas una instalación correcta no dejaba ni un renglón en el
  3. // journal (todo iba por stderr y el pool solo devolvía stdout).
  4. package reinstall_test
  5. import (
  6. "strings"
  7. "testing"
  8. )
  9. func TestScriptProgress_1894(t *testing.T) {
  10. s := scriptForTest()
  11. for _, want := range []string{
  12. `say() { echo "netpulse-agent: $*"; }`,
  13. `say "architecture $ARCH ($GOARCH)"`,
  14. `say "binary downloaded and verified"`,
  15. `say "agent started"`,
  16. } {
  17. if !strings.Contains(s, want) {
  18. t.Fatalf("el script no lleva %q", want)
  19. }
  20. }
  21. }
  22. // El aviso de fallo sigue yendo a stderr: no se mezcla con el progreso.
  23. func TestScriptWarnStillOnStderr_1894(t *testing.T) {
  24. s := scriptForTest()
  25. if !strings.Contains(s, `warn() { echo "netpulse-agent: $*" >&2; }`) {
  26. t.Fatal("warn() debe seguir escribiendo a stderr")
  27. }
  28. }
  29. // #1894: say() estaba definido en el bloque de config, detrás de la primera
  30. // llamada. El script moría con "say: not found" y el reinstall no llegaba ni a
  31. // instalar el binario.
  32. func TestScriptDefinesSayBeforeUse_1894(t *testing.T) {
  33. s := scriptForTest()
  34. def := strings.Index(s, `say() { echo "netpulse-agent: $*"; }`)
  35. if def < 0 {
  36. t.Fatal("falta la definición de say()")
  37. }
  38. use := strings.Index(s, `say "`)
  39. if use < 0 {
  40. t.Fatal("el script no usa say()")
  41. }
  42. if def > use {
  43. t.Fatalf("say() se define en %d y se usa en %d", def, use)
  44. }
  45. }