aboutsummaryrefslogtreecommitdiff
path: root/tests/model-lint-warning-message.scm
blob: 746dccac8523f80fdfcb52abae34df47d3f779fc (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
48
49
50
51
52
53
54
55
56
57
(define-module (tests model-lint-warning-message)
  #:use-module (srfi srfi-64)
  #:use-module (ice-9 match)
  #:use-module (guix-data-service database)
  #:use-module (guix-data-service model lint-warning-message))

(test-begin "test-model-lint-warning-message")

(define data
  '(("en" . "Test message")
    ("es" . "Test message in Spanish")))

(with-postgresql-connection
 "test-model-lint-checker"
 (lambda (conn)
   (test-assert "single insert"
     (with-postgresql-transaction
      conn
      (lambda (conn)
        (match (lint-warning-message-data->lint-warning-message-ids conn data)
          (((? number? id1) (? number? id2))
           #t)))
      #:always-rollback? #t))

   (test-assert "double insert"
     (with-postgresql-transaction
      conn
      (lambda (conn)
        (match (lint-warning-message-data->lint-warning-message-ids conn data)
          (((? number? id1) (? number? id2))
           (match (lint-warning-message-data->lint-warning-message-ids conn data)
             (((? number? second-id1) (? number? second-id2))
              (and (eq? id1 second-id1)
                   (eq? id2 second-id2)))))))
      #:always-rollback? #t))

   (test-assert "single set insert"
     (with-postgresql-transaction
      conn
      (lambda (conn)
        (match (lint-warning-message-data->lint-warning-message-set-id conn data)
          ((? number? id1)
           #t)))
      #:always-rollback? #t))

   (test-assert "double set insert"
     (with-postgresql-transaction
      conn
      (lambda (conn)
        (match (lint-warning-message-data->lint-warning-message-set-id conn data)
          ((? number? id)
           (match (lint-warning-message-data->lint-warning-message-set-id conn data)
             ((? number? second-id)
              (eq? id second-id))))))
      #:always-rollback? #t))))

(test-end)