Skip to content

Commit

Permalink
test: use ava macros
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Nov 15, 2019
1 parent d64a2d6 commit 0d759d7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 84 deletions.
99 changes: 99 additions & 0 deletions tests/create-configure-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import test from "ava";
import address from "network-address";

import { StandaloneServiceProvider } from "@kronos-integration/service";
import { ServiceKOA } from "../src/service-koa.mjs";

async function skt(t, config, ...args) {
let expected = args.pop() || {};
const updates = args.pop() || [];

expected = { timeout: { server: 120 }, ...expected };
const sp = new StandaloneServiceProvider();
const ks = new ServiceKOA(config, sp);

for (const u of updates) {
await ks.configure(u);
}

["name", "isSecure", "socket", "url", "address"].forEach(a => {
if (expected[a] !== undefined) {
t.is(ks[a], expected[a], a);
}
});

for (const name of Object.keys(expected.timeout)) {
t.is(ks.timeout[name], expected.timeout[name], `timeout ${name}`);
}

await ks.stop();
}

skt.title = (providedTitle = "", config, updates) => {
return `koa ${providedTitle} ${JSON.stringify(config)}${
Array.isArray(updates) ? " with " + JSON.stringify(updates) : ""
}`.trim();
};

test(
skt,
{
name: "my-name",
listen: {
socket: 1234,
address: address()
}
},
{
name: "my-name",
adrress: address(),
socket: 1234,
url: `http://${address()}:1234`,
isSecure: false
}
);

test(
skt,
{
listen: {
url: `http://${address()}:1234`
}
},
{
adrress: address(),
socket: 1234,
url: `http://${address()}:1234`,
isSecure: false
}
);

test(
skt,
{
listen: {
url: `http://${address()}:1234`
}
},
[
{
listen: {
socket: 1235
}
},
{
timeout: {
server: 123.45
}
}
],
{
adrress: address(),
socket: 1235,
// url: `http://${address()}:1235`,
isSecure: false,
timeout: {
server: 123.45
}
}
);
84 changes: 0 additions & 84 deletions tests/simple-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,11 @@ import got from "got";
import { readFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
import address from "network-address";
import route from "koa-route";

import { StandaloneServiceProvider } from "@kronos-integration/service";
import { ServiceKOA } from "../src/service-koa.mjs";


test("service-koa plain http", async t => {
const sp = new StandaloneServiceProvider();
const ks = new ServiceKOA(
{
type: "xxx",
name: "my-name",
listen: {
socket: 1234,
address: address()
}
},
sp
);

t.is(ks.name, "my-name");
t.is(ks.isSecure, false);

t.is(ks.socket, 1234);

t.is(ks.address, address());
t.is(ks.url, `http://${address()}:1234`);

t.is(ks.timeout.server, 120);
await ks.stop();
});

test("service-koa utl", async t => {
const sp = new StandaloneServiceProvider();
const ks = new ServiceKOA(
{
type: "xxx",
name: "my-name",
listen: {
url: `http://${address()}:1234`
}
},
sp
);

t.is(ks.name, "my-name");
t.is(ks.isSecure, false);

t.is(ks.socket, 1234);
t.is(ks.address, address());
t.is(ks.url, `http://${address()}:1234`);

t.is(ks.timeout.server, 120);
await ks.stop();
});

test("service-koa plain http change port", async t => {
const sp = new StandaloneServiceProvider();
const ks = new ServiceKOA(
{
type: "xxx",
name: "my-name",
listen: {
socket: 1234,
address: address()
}
},
sp
);

await ks.configure({
listen: {
socket: 1235
}
});

t.is(ks.listen.socket, 1235);

await ks.configure({
timeout: {
server: 123.45
}
});

t.is(ks.timeout.server, 123.45);
await ks.stop();
});

test("service-koa plain http get /", async t => {
const sp = new StandaloneServiceProvider();
const ks = new ServiceKOA(
Expand Down

0 comments on commit 0d759d7

Please sign in to comment.