Skip to content

Commit

Permalink
update config parser tests to support unix sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
sdumetz committed Oct 18, 2024
1 parent d18b883 commit c7b0141
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions source/server/utils/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ describe("config", function(){
});

describe("parse()", function(){
it("reports error for misformated environment variables", function(){
["bar", "-1"].forEach(v=>{
expect(()=> parse({"PORT": v as any}), `${v} should not be valid`).to.throw("PORT expect a valid positive integer");
});
});
it("parse integers", function(){
expect(parse({PORT:"3000"})).to.have.property("port", 3000);
})

it("parse ports or unix socket paths", function(){
expect(parse({PORT:"3000"})).to.have.property("port", 3000);
expect(parse({PORT:"/var/run/socket.sock"})).to.have.property("port", "/var/run/socket.sock");
});

it("parse booleans", function(){
expect(parse({PUBLIC:"false"})).to.have.property("public", false);
Expand Down
2 changes: 1 addition & 1 deletion source/server/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function toPath(s:string):string{

function toUInt(s:string):number{
let n = parseInt(s, 10);
if(Number.isNaN(n) || !Number.isSafeInteger(n) || n < 0) throw new Error("PORT expect a valid positive integer");
if(Number.isNaN(n) || !Number.isSafeInteger(n) || n < 0) throw new Error("expected a valid positive integer");
return n;
}

Expand Down

0 comments on commit c7b0141

Please sign in to comment.