forked from mirrors/nixpkgs
cups-pdf: add vm test
This commit is contained in:
parent
49a129ab40
commit
85aeeac28d
|
@ -151,6 +151,7 @@ in {
|
|||
coturn = handleTest ./coturn.nix {};
|
||||
couchdb = handleTest ./couchdb.nix {};
|
||||
cri-o = handleTestOn ["aarch64-linux" "x86_64-linux"] ./cri-o.nix {};
|
||||
cups-pdf = handleTest ./cups-pdf.nix {};
|
||||
custom-ca = handleTest ./custom-ca.nix {};
|
||||
croc = handleTest ./croc.nix {};
|
||||
deluge = handleTest ./deluge.nix {};
|
||||
|
|
40
nixos/tests/cups-pdf.nix
Normal file
40
nixos/tests/cups-pdf.nix
Normal file
|
@ -0,0 +1,40 @@
|
|||
import ./make-test-python.nix ({ lib, pkgs, ... }: {
|
||||
name = "cups-pdf";
|
||||
|
||||
nodes.machine = { pkgs, ... }: {
|
||||
imports = [ ./common/user-account.nix ];
|
||||
environment.systemPackages = [ pkgs.poppler_utils ];
|
||||
fonts.fonts = [ pkgs.dejavu_fonts ]; # yields more OCR-able pdf
|
||||
services.printing.cups-pdf.enable = true;
|
||||
services.printing.cups-pdf.instances = {
|
||||
opt = {};
|
||||
noopt.installPrinter = false;
|
||||
};
|
||||
hardware.printers.ensurePrinters = [{
|
||||
name = "noopt";
|
||||
model = "CUPS-PDF_noopt.ppd";
|
||||
deviceUri = "cups-pdf:/noopt";
|
||||
}];
|
||||
};
|
||||
|
||||
# we cannot check the files with pdftotext, due to
|
||||
# https://github.com/alexivkin/CUPS-PDF-to-PDF/issues/7
|
||||
# we need `imagemagickBig` as it has ghostscript support
|
||||
|
||||
testScript = ''
|
||||
from subprocess import run
|
||||
machine.wait_for_unit("cups.service")
|
||||
for name in ("opt", "noopt"):
|
||||
text = f"test text {name}".upper()
|
||||
machine.wait_until_succeeds(f"lpstat -v {name}")
|
||||
machine.succeed(f"su - alice -c 'echo -e \"\n {text}\" | lp -d {name}'")
|
||||
# wait until the pdf files are completely produced and readable by alice
|
||||
machine.wait_until_succeeds(f"su - alice -c 'pdfinfo /var/spool/cups-pdf-{name}/users/alice/*.pdf'")
|
||||
machine.succeed(f"cp /var/spool/cups-pdf-{name}/users/alice/*.pdf /tmp/{name}.pdf")
|
||||
machine.copy_from_vm(f"/tmp/{name}.pdf", "")
|
||||
run(f"${pkgs.imagemagickBig}/bin/convert -density 300 $out/{name}.pdf $out/{name}.jpeg", shell=True, check=True)
|
||||
assert text.encode() in run(f"${lib.getExe pkgs.tesseract} $out/{name}.jpeg stdout", shell=True, check=True, capture_output=True).stdout
|
||||
'';
|
||||
|
||||
meta.maintainers = [ lib.maintainers.yarny ];
|
||||
})
|
|
@ -3,6 +3,7 @@
|
|||
, fetchFromGitHub
|
||||
, cups
|
||||
, coreutils
|
||||
, nixosTests
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
|
@ -40,6 +41,8 @@ stdenv.mkDerivation rec {
|
|||
runHook postInstall
|
||||
'';
|
||||
|
||||
passthru.tests.vmtest = nixosTests.cups-pdf;
|
||||
|
||||
meta = with lib; {
|
||||
description = "A CUPS backend that turns print jobs into searchable PDF files";
|
||||
homepage = "https://github.com/alexivkin/CUPS-PDF-to-PDF";
|
||||
|
|
Loading…
Reference in a new issue