owut_target_1978_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // owut_target_1978_test.go - el check debe evaluar la version elegida en la
  2. // UI (#1978) y decir algo cuando no deja salida (#1977).
  3. package firmware
  4. import (
  5. "strings"
  6. "testing"
  7. )
  8. func TestOwutCheckCmdFor(t *testing.T) {
  9. cases := []struct {
  10. target string
  11. want string
  12. absent string
  13. }{
  14. {"25.12.6", "owut check -v -V '25.12.6'", ""},
  15. {" 24.10.8 ", "-V '24.10.8'", ""},
  16. {"", "owut check -v", "-V"},
  17. {"latest", "owut check -v", "-V"},
  18. {"25.12.6; reboot", "owut check -v", "-V"},
  19. }
  20. for _, c := range cases {
  21. got := OwutCheckCmdFor(c.target)
  22. if !strings.Contains(got, c.want) {
  23. t.Fatalf("OwutCheckCmdFor(%q) = %q, esperaba contener %q", c.target, got, c.want)
  24. }
  25. if c.absent != "" && strings.Contains(got, c.absent) {
  26. t.Fatalf("OwutCheckCmdFor(%q) = %q, no debia contener %q", c.target, got, c.absent)
  27. }
  28. if !strings.Contains(got, "__owut_exit__") {
  29. t.Fatalf("falta el wrapper de exit code: %q", got)
  30. }
  31. }
  32. }
  33. func TestCheckOwutTargetPassesVersion(t *testing.T) {
  34. r := &fakeRunner{rules: []fakeRule{
  35. {contains: "command -v owut", out: "/usr/bin/owut\n"},
  36. {contains: "owut check", out: checkOKOut},
  37. {contains: "attendedsysupgrade.owut.remove", out: ""},
  38. }}
  39. st := CheckOwutTarget(r, "192.168.1.50", "25.12.6")
  40. if !st.CheckRan || !st.Buildable || !st.UpgradeAvailable {
  41. t.Fatalf("status: %+v", st)
  42. }
  43. if !r.saw("owut check -v -V '25.12.6'") {
  44. t.Fatalf("el check no llevo el target: %v", r.cmds)
  45. }
  46. if st.Message != "" {
  47. t.Fatalf("sin mensaje cuando el check corre: %q", st.Message)
  48. }
  49. }
  50. func TestCheckOwutExplainsEmptyOutput(t *testing.T) {
  51. // owut presente, pero el comando no escribe nada (el caso del reporte).
  52. r := &fakeRunner{rules: []fakeRule{
  53. {contains: "command -v owut", out: "/usr/bin/owut\n"},
  54. {contains: "owut check", out: ""},
  55. }}
  56. st := CheckOwut(r, "192.168.1.50")
  57. if !st.OwutAvailable {
  58. t.Fatalf("owut deberia estar disponible: %+v", st)
  59. }
  60. if st.CheckRan {
  61. t.Fatalf("no deberia marcar el check como ejecutado: %+v", st)
  62. }
  63. if st.Message == "" {
  64. t.Fatal("sin salida debe haber un mensaje para la UI (#1977)")
  65. }
  66. }