27 lines
1.6 KiB
Bash
Executable File
27 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
cd "$(dirname "$0")"
|
|
helm lint --strict chart/scanservjs -f values.example.yaml
|
|
helm template scanner chart/scanservjs -n example -f values.example.yaml | python3 -c '
|
|
import os, pathlib, subprocess, sys, tempfile, yaml
|
|
objects=[x for x in yaml.safe_load_all(sys.stdin) if x]
|
|
one=lambda kind,name: next(x for x in objects if x["kind"]==kind and x["metadata"]["name"]==name)
|
|
d=one("Deployment","scanner")
|
|
s=one("Service","scanner")
|
|
assert d["spec"]["selector"]["matchLabels"]==s["spec"]["selector"]
|
|
assert d["spec"]["template"]["spec"]["volumes"][0]["persistentVolumeClaim"]["claimName"]=="document-storage"
|
|
assert all(k in d["spec"]["template"]["spec"]["containers"][0] for k in ("startupProbe","readinessProbe","livenessProbe"))
|
|
code=one("ConfigMap","scanner-config")["data"]["config.local.js"]
|
|
with tempfile.TemporaryDirectory() as temp:
|
|
root=pathlib.Path(temp); script=root/"config.local.js"; script.write_text(code)
|
|
output=root/"staged"; output.mkdir(); consume=root/"consume"; consume.mkdir()
|
|
env={**os.environ,"SCAN_OUTPUT_DIR":str(output),"PAPERLESS_CONSUME_DIR":str(consume)}
|
|
subprocess.run(["node","--check",str(script)],check=True)
|
|
for name,contents in (("test.pdf",b"%PDF-1.4\nscan\n"),("test.jpg",b"\xff\xd8\xffscan\xff\xd9")):
|
|
source=output/name; source.write_bytes(contents)
|
|
subprocess.run(["node","-e","require(process.argv[1]).actions[0].execute({fullname:process.argv[2]}).catch(e=>{console.error(e);process.exit(1)})",str(script),str(source)],check=True,env=env)
|
|
delivered=list(consume.glob("*"+name))
|
|
assert len(delivered)==1 and delivered[0].read_bytes()==contents
|
|
assert not source.exists() and not list(consume.glob("*.part"))
|
|
'
|