8000 testcontainer.test.ts · avdim/github-script@ef161ef · GitHub
[go: up one dir, main page]

Skip to content

Commit ef161ef

Browse files
committed
testcontainer.test.ts
1 parent b4b48d6 commit ef161ef

File tree

4 files changed

+145
-52
lines changed

4 files changed

+145
-52
lines changed

__test__/testcontainer.test.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import {DockerComposeEnvironment, StartedTestContainer} from "testcontainers";
2+
import * as path from "path";
3+
import {request, RequestOptions} from 'http';
4+
5+
const npmCliLogin = require('npm-cli-login');
6+
const migrate = require('../src/npm-migrate')
7+
const npmUtils = require('../src/npm_utils')
8+
const {GenericContainer} = require("testcontainers");
9+
const util = require('util');
10+
const got = require('got');
11+
12+
const MODULE_NAME = 'test-package'
13+
const FROM = 'http://localhost:55551'
14+
const TO = 'http://localhost:55552'
15+
const ROOT_PATH = path.resolve(__dirname, "../");
16+
17+
function performRequest(options: RequestOptions) {
18+
return new Promise<string>((resolve, reject) => {
19+
request(
20+
options,
21+
function(response) {
22+
const { statusCode } = response;
23+
// @ts-ignore
24+
if (statusCode >= 300) {
25+
reject(
26+
new Error(response.statusMessage)
27+
)
28+
}
29+
const chunks: any[] = [];
30+
response.on('data', (chunk) => {
31+
chunks.push(chunk);
32+
});
33+
response.on('end', () => {
34+
const result = Buffer.concat(chunks).toString();
35+
resolve(JSON.parse(result));
36+
});
37+
}
38+
)
39+
.end();
40+
})
41+
}
42+
43+
describe('testcontainer', () => {
44+
test('hello get', async () => {
45+
jest.setTimeout(2 * 60_000);
46+
47+
const environment = await new DockerComposeEnvironment(
48+
ROOT_PATH,
49+
"hello-compose.yml"
50+
).up();
51+
52+
// const startedContainer = await new GenericContainer("avdim/ktor_hello", "latest")
53+
// .withExposedPorts(8080)
54+
// .start()
55+
56+
57+
try {
58+
const resp = await got('http://localhost:8080')
59+
console.log("resp.body: ", resp.body)
60+
const strBody: string = resp.body
61+
expect(strBody.indexOf("Hello") >= 0).toEqual(true)
62+
// const response1: string = await performRequest({
63+
// host: "localhost",
64+
// path: "/",
65+
// port: "8080",
66+
// method: 'GET',
67+
// })
68+
// console.log("response1: ", response1)
69+
} finally {
70+
// await startedContainer.stop()
71+
// await environment.stop()
72+
await environment.down()
73+
}
74+
75+
})
76+
})

hello-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#docker-compose --file npm-registries.yml up
2+
version: '2'
3+
services:
4+
hello:
5+
container_name: npm1
6+
image: "avdim/ktor_hello:latest"
7+
ports:
8+
- "8080:8080"

package-lock.json

Lines changed: 60 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"fstream": "~1.0.11",
6565
"fstream-npm": "~1.2.0",
6666
"glob": "~7.1.1",
67+
"got": "^11.8.0",
6768
"graceful-fs": "4.2.4",
6869
"has-unicode": "~2.0.1",
6970
"hosted-git-info": "~2.4.2",

0 commit comments

Comments
 (0)
0