aboutsummaryrefslogtreecommitdiff
path: root/tests/model-lint-checker.scm
blob: e6740b133ba5ee3001576f9bd6e234ab25ea4bc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(define-module (tests model-lint-checker)
  #:use-module (srfi srfi-64)
  #:use-module (ice-9 match)
  #:use-module (guix-data-service database)
  #:use-module (guix-data-service model lint-checker))

(test-begin "test-model-lint-checker")

(with-postgresql-connection
 "test-model-lint-checker"
 (lambda (conn)
   (check-test-database! conn)

   (test-assert "single insert"
     (with-postgresql-transaction
      conn
      (lambda (conn)
        (define data
          `((name-1 #t ,(string->number (insert-lint-checker-description-set
                                         conn '(37))))
            (name-2 #f ,(string->number (insert-lint-checker-description-set
                                         conn '(38))))))

        (match (lint-checkers->lint-checker-ids conn data)
          (((? number? id1) (? number? id2))
           #t)))
      #:always-rollback? #t))

   (test-assert "double insert"
     (with-postgresql-transaction
      conn
      (lambda (conn)
        (define data
          `((name-1 #t ,(string->number (insert-lint-checker-description-set
                                         conn '(37))))
            (name-2 #f ,(string->number (insert-lint-checker-description-set
                                         conn '(38))))))

        (match (lint-checkers->lint-checker-ids conn data)
          (((? number? id1) (? number? id2))
           (match (lint-checkers->lint-checker-ids conn data)
             (((? number? second-id1) (? number? second-id2))
              (and (eq? id1 second-id1)
                   (eq? id2 second-id2)))))))
      #:always-rollback? #t))))

(test-end)