Files
canina/scripts/tests/test_rollout_health.cjs

12 lines
720 B
JavaScript

const {test}=require('node:test');
const assert=require('node:assert/strict');
const http=require('node:http');
const {accept}=require('../rollout-health.cjs');
for(const [name,status,body,pass] of [['bad status',503,'{}',false],['fake html',200,'<html>ok</html>',false],['wrong envelope',200,'{}',false],['valid empty catalog',200,'{"data":[],"meta":{"total":0}}',true]]) {
test(name,async()=>{
const s=http.createServer((q,r)=>{r.writeHead(status,{'content-type':'application/json'});r.end(body)});
await new Promise(r=>s.listen(0,'127.0.0.1',r));
try { const p=accept(`http://127.0.0.1:${s.address().port}`); if(pass) await p; else await assert.rejects(p); } finally {await new Promise(r=>s.close(r));}
});
}