Add tests

This commit is contained in:
TakeV 2023-07-23 17:23:46 -07:00
parent e6ae17fe1d
commit 0ba79f37af
Signed by: TakeV
GPG Key ID: A64F41345C7400AF
3 changed files with 48 additions and 7 deletions

View File

@ -1,5 +1,6 @@
(define-module (kulupu services activity-pub)
(define-module (kulupu services gotosocial)
#:use-module (guix gexp)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix records)
#:use-module (guix packages)
#:use-module (gnu services)
@ -12,6 +13,7 @@
#:use-module (gnu system shadow)
#:use-module (gnu packages admin)
#:use-module (gnu packages bash)
#:use-module (gnu packages base)
#:use-module (kulupu packages gotosocial)
#:use-module (ice-9 match)
#:export (gotosocial-service-type
@ -41,9 +43,9 @@
(run-dir
(string "/var/run/gotosocial")
"GTS runtime directory")
(database-type
(string "sqlite")
"Database type to use, default to sqlite")
(postgres?
(boolean #t)
"Set up postgres DB, use sqlite if false")
(database-address
(string "/var/run/gotosocial/gts.db")
"Address of the database, default /var/run/gotosocial/gts.db")
@ -51,7 +53,7 @@
(define (gotosocial-shepherd-service config)
(match-record config <gotosocial-configuration>
(gotosocial frontend config-file port work-dir run-dir host database-type database-address)
(gotosocial frontend config-file port work-dir run-dir host postgres? database-address)
(let* ((gts (file-append gotosocial "/bin/gotosocial")))
(list (shepherd-service
(documentation "Run GoToSocial")
@ -62,7 +64,7 @@
(#$(file-append gotosocial "/bin/gotosocial")
"server" "start" "--syslog-enabled"
"--port=" (number->string #$port)
"--db-type=" #$database-type
$#(when (not postgres?) "--db-type=sqlite")
"--db-address=" #$database-address
"--letsencrypt-cert-dir=" #$work-dir "/storage/certs"
"--storage-local-base-path=" #$work-dir "/storage"
@ -74,6 +76,13 @@
#:directory #$work-dir))
(stop #~(make-kill-destructor)))))))
(define (gotosocial-postgres-roles config)
(match-record config <gotosocial-configuration>
(postgres?)
(if postgres? (list (postgresql-role
(name "gotosocial")
(create-database? #t)))
'())))
(define (gotosocial-accounts config)
(match-record config <gotosocial-configuration>
@ -94,6 +103,7 @@
(name 'gotosocial)
(extensions
(list (service-extension shepherd-root-service-type gotosocial-shepherd-service)
(service-extension account-service-type gotosocial-accounts)))
(service-extension account-service-type gotosocial-accounts)
(service-extension postgresql-role-service-type gitea-postgresql-roles)))
(description "Runs GoToSocial")
(default-value (gotosocial-configuration))))

3
run-repl.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
guix repl -L . --listen=tcp:37146

28
tests/utils.scm Normal file
View File

@ -0,0 +1,28 @@
(define-module (tests utils)
#:use-module (gnu)
#:use-module (gnu services networking)
#:use-module (gnu services ssh)
#:use-module (gnu packages ssh)
#:use-module (kulupu services gotosocial))
(define-public %container-system
(operating-system
(host-name "localhost")
(bootloader (bootloader-configuration
(bootloader grub-bootloader)
(targets '("/dev/sdX"))))
;; It's fitting to support the equally bare bones -nographic
;; QEMU option, which also nicely sidesteps forcing QWERTY.
(kernel-arguments (list "console=ttyS0,115200"))
(file-systems (cons (file-system
(device (file-system-label "my-root"))
(mount-point "/")
(type "ext4"))
%base-file-systems))))
(define-public %gotosocial-container
(operating-system
(inherit %container-system)
(services (list (service gotosocial-service-type)))))
%gotosocial-container