ci.scm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2017, 2018, 2019, 2020, 2021 Christopher Baines <mail@cbaines.net>
  4. ;;; Copyright © 2017, 2018 Clément Lassieur <clement@lassieur.org>
  5. ;;; Copyright © 2018 Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr>
  6. ;;; Copyright © 2018 Marius Bakke <mbakke@fastmail.com>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (gnu tests ci)
  23. #:use-module (gnu tests)
  24. #:use-module (gnu system)
  25. #:use-module (gnu system file-systems)
  26. #:use-module (gnu system shadow)
  27. #:use-module (gnu system vm)
  28. #:use-module (gnu services)
  29. #:use-module (gnu services ci)
  30. #:use-module (gnu services web)
  31. #:use-module (gnu services networking)
  32. #:use-module (guix gexp)
  33. #:use-module (guix store)
  34. #:export (%test-laminar))
  35. (define %laminar-os
  36. ;; Operating system under test.
  37. (simple-operating-system
  38. (service dhcp-client-service-type)
  39. (service laminar-service-type)))
  40. (define* (run-laminar-test #:optional (http-port 8080))
  41. "Run tests in %LAMINAR-OS, which has laminar running and listening on
  42. HTTP-PORT."
  43. (define os
  44. (marionette-operating-system
  45. %laminar-os
  46. #:imported-modules '((gnu services herd)
  47. (guix combinators))))
  48. (define vm
  49. (virtual-machine
  50. (operating-system os)
  51. (port-forwardings `((,http-port . 8080)))))
  52. (define test
  53. (with-imported-modules '((gnu build marionette))
  54. #~(begin
  55. (use-modules (srfi srfi-11) (srfi srfi-64)
  56. (ice-9 match)
  57. (gnu build marionette)
  58. (web uri)
  59. (web client)
  60. (web response))
  61. (define marionette
  62. ;; Forward the guest's HTTP-PORT, where laminar is listening, to
  63. ;; port 8080 in the host.
  64. (make-marionette (list #$vm)))
  65. (test-runner-current (system-test-runner #$output))
  66. (test-begin "laminar")
  67. (test-assert "service running"
  68. (marionette-eval
  69. '(begin
  70. (use-modules (gnu services herd))
  71. (start-service 'laminar))
  72. marionette))
  73. (define* (retry-on-error f #:key times delay)
  74. (let loop ((attempt 1))
  75. (match (catch
  76. #t
  77. (lambda ()
  78. (cons #t
  79. (f)))
  80. (lambda args
  81. (cons #f
  82. args)))
  83. ((#t . return-value)
  84. return-value)
  85. ((#f . error-args)
  86. (if (>= attempt times)
  87. error-args
  88. (begin
  89. (sleep delay)
  90. (loop (+ 1 attempt))))))))
  91. (test-equal "http-get"
  92. 200
  93. (retry-on-error
  94. (lambda ()
  95. (let-values (((response text)
  96. (http-get #$(format
  97. #f
  98. "http://localhost:~A/"
  99. http-port)
  100. ;; TODO: Why does decoding fail?
  101. #:decode-body? #f)))
  102. (response-code response)))
  103. #:times 10
  104. #:delay 5))
  105. (test-end))))
  106. (gexp->derivation "laminar-test" test))
  107. (define %test-laminar
  108. (system-test
  109. (name "laminar")
  110. (description "Connect to a running Laminar server.")
  111. (value (run-laminar-test))))