all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Romain GARBAGE <romain.garbage@inria.fr>
To: guix-devel@gnu.org
Cc: ludovic.courtes@inria.fr, Romain GARBAGE <romain.garbage@inria.fr>
Subject: [PATCH Cuirass 4/4] http: Add tests for Gitlab API.
Date: Thu, 13 Jun 2024 13:03:09 +0200	[thread overview]
Message-ID: <20240613110311.12126-4-romain.garbage@inria.fr> (raw)
In-Reply-To: <20240613110311.12126-1-romain.garbage@inria.fr>

* tests/http.scm (http-post-json, mr-json-open, mr-json-close mr-spec): New
variables.
New tests for Gitlab API.
---
 tests/http.scm | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/tests/http.scm b/tests/http.scm
index a124761..3281bcc 100644
--- a/tests/http.scm
+++ b/tests/http.scm
@@ -21,6 +21,7 @@
 
 (use-modules (cuirass http)
              (cuirass database)
+             (cuirass gitlab)
              (cuirass specification)
              (cuirass utils)
              (tests common)
@@ -41,6 +42,9 @@
   (call-with-values (lambda () (http-get uri))
     (lambda (response body) body)))
 
+(define (http-post-json uri body)
+  (http-post uri #:body body #:headers '((content-type application/json))))
+
 (define (wait-until-ready port)
   ;; Wait until the server is accepting connections.
   (let ((conn (socket PF_INET SOCK_STREAM 0)))
@@ -85,6 +89,17 @@
                      (channel . "packages")
                      (directory . "dir2")))))))
 
+(define mr-json-open
+  "{\"event_type\":\"merge_request\",\"object_attributes\":{\"action\":\"open\",\"merge_status\":\"can_be_merged\",\"source_branch\":\"test-branch\",\"source\":{\"git_http_url\":\"https://gitlab.instance.test/source-repo/fork-name.git\",\"name\":\"test-project\"}}}")
+
+(define mr-json-close
+  "{\"event_type\":\"merge_request\",\"object_attributes\":{\"action\":\"close\",\"merge_status\":\"can_be_merged\",\"source_branch\":\"test-branch\",\"source\":{\"git_http_url\":\"https://gitlab.instance.test/source-repo/fork-name.git\",\"name\":\"test-project\"}}}")
+
+(define mr-spec
+  (gitlab-merge-request->specification
+   (gitlab-event-value
+    (pk 'json (json->gitlab-event mr-json-open)))))
+
 (test-group-with-cleanup "http"
   (test-assert "db-init"
     (begin
@@ -323,6 +338,25 @@
         (http-get-body
          (test-cuirass-uri "/api/jobs/history?spec=guix&names=fake-job&nr=10"))))))
 
+  (test-equal "/admin/gitlab/event creates a spec from a new merge request"
+    (specification-name mr-spec)
+    (begin
+      (http-post-json (test-cuirass-uri "/admin/gitlab/event") mr-json-open)
+      (specification-name (db-get-specification (specification-name mr-spec)))))
+
+  (test-equal "/admin/gitlab/event error when a merge request has already been created"
+    400
+    (response-code (http-post-json (test-cuirass-uri "/admin/gitlab/event") mr-json-open)))
+
+  (test-assert "/admin/gitlab/event removes a spec from a closed merge request"
+    (begin
+      (http-post-json (test-cuirass-uri "/admin/gitlab/event") mr-json-close)
+      (not (db-get-specification (specification-name mr-spec)))))
+
+  (test-equal "/admin/gitlab/event error when a merge request has already been closed"
+    404
+    (response-code (http-post-json (test-cuirass-uri "/admin/gitlab/event") mr-json-close)))
+
   (test-assert "db-close"
     (begin
       (db-close (%db))
-- 
2.45.1



  parent reply	other threads:[~2024-06-14 16:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-13 11:03 [PATCH Cuirass 1/4] specification: Ensure name is a symbol Romain GARBAGE
2024-06-13 11:03 ` [PATCH Cuirass 2/4] gitlab: Add module for Gitlab JSON objects definition Romain GARBAGE
2024-06-13 11:03 ` [PATCH Cuirass 3/4] http: Add /admin/gitlab/event Romain GARBAGE
2024-06-13 11:03 ` Romain GARBAGE [this message]
2024-06-14 14:08 ` [PATCH Cuirass 1/4] specification: Ensure name is a symbol Ludovic Courtès
2024-06-17 13:16   ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240613110311.12126-4-romain.garbage@inria.fr \
    --to=romain.garbage@inria.fr \
    --cc=guix-devel@gnu.org \
    --cc=ludovic.courtes@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.