aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-08-31 12:11:58 +0100
committerChristopher Baines <mail@cbaines.net>2019-09-01 13:12:10 +0100
commit6b9977f62eef54678c7a53844ad5d26d8efeecb0 (patch)
treed76ededb17ec03e0705258bb9565782c7e16af76 /tests
parentbf469504eb4df95a3349328dc10095d172630fcd (diff)
downloaddata-service-6b9977f62eef54678c7a53844ad5d26d8efeecb0.tar
data-service-6b9977f62eef54678c7a53844ad5d26d8efeecb0.tar.gz
Store lint warnings in the database
This commit adds the relevant tables and code to store lint warnings in the database. Currently, only lint checkers which don't require access to the network will be run, as this allows the processing to happen without network access. Also, this functionality won't work in older versions of Guix which don't expose the lint warnings in a compatible way.
Diffstat (limited to 'tests')
-rw-r--r--tests/model-lint-checker.scm37
-rw-r--r--tests/model-lint-warning-message.scm57
2 files changed, 94 insertions, 0 deletions
diff --git a/tests/model-lint-checker.scm b/tests/model-lint-checker.scm
new file mode 100644
index 0000000..64088e5
--- /dev/null
+++ b/tests/model-lint-checker.scm
@@ -0,0 +1,37 @@
+(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")
+
+(define data
+ '((name-1 "description-1" #t)
+ (name-2 "description-2" #f)))
+
+(with-postgresql-connection
+ "test-model-lint-checker"
+ (lambda (conn)
+ (test-assert "single insert"
+ (with-postgresql-transaction
+ conn
+ (lambda (conn)
+ (match (lint-checkers->lint-checker-ids conn data)
+ (((? string? id1) (? string? id2))
+ #t)))
+ #:always-rollback? #t))
+
+ (test-assert "double insert"
+ (with-postgresql-transaction
+ conn
+ (lambda (conn)
+ (match (lint-checkers->lint-checker-ids conn data)
+ (((? string? id1) (? string? id2))
+ (match (lint-checkers->lint-checker-ids conn data)
+ (((? string? second-id1) (? string? second-id2))
+ (and (string=? id1 second-id1)
+ (string=? id2 second-id2)))))))
+ #:always-rollback? #t))))
+
+(test-end)
diff --git a/tests/model-lint-warning-message.scm b/tests/model-lint-warning-message.scm
new file mode 100644
index 0000000..c6fad55
--- /dev/null
+++ b/tests/model-lint-warning-message.scm
@@ -0,0 +1,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)
+ (((? string? id1) (? string? 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)
+ (((? string? id1) (? string? id2))
+ (match (lint-warning-message-data->lint-warning-message-ids conn data)
+ (((? string? second-id1) (? string? second-id2))
+ (and (string=? id1 second-id1)
+ (string=? 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)
+ ((? string? 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)
+ ((? string? id)
+ (match (lint-warning-message-data->lint-warning-message-set-id conn data)
+ ((? string? second-id)
+ (string=? id second-id))))))
+ #:always-rollback? #t))))
+
+(test-end)