ci.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 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. (mkdir #$output)
  66. (chdir #$output)
  67. (test-begin "laminar")
  68. (test-assert "service running"
  69. (marionette-eval
  70. '(begin
  71. (use-modules (gnu services herd))
  72. (start-service 'laminar))
  73. marionette))
  74. (define* (retry-on-error f #:key times delay)
  75. (let loop ((attempt 1))
  76. (match (catch
  77. #t
  78. (lambda ()
  79. (cons #t
  80. (f)))
  81. (lambda args
  82. (cons #f
  83. args)))
  84. ((#t . return-value)
  85. return-value)
  86. ((#f . error-args)
  87. (if (>= attempt times)
  88. error-args
  89. (begin
  90. (sleep delay)
  91. (loop (+ 1 attempt))))))))
  92. (test-equal "http-get"
  93. 200
  94. (retry-on-error
  95. (lambda ()
  96. (let-values (((response text)
  97. (http-get #$(format
  98. #f
  99. "http://localhost:~A/"
  100. http-port)
  101. ;; TODO: Why does decoding fail?
  102. #:decode-body? #f)))
  103. (response-code response)))
  104. #:times 10
  105. #:delay 5))
  106. (test-end)
  107. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  108. (gexp->derivation "laminar-test" test))
  109. (define %test-laminar
  110. (system-test
  111. (name "laminar")
  112. (description "Connect to a running Laminar server.")
  113. (value (run-laminar-test))))