Skip to content

Commit

Permalink
test: add more docker tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DorianMazur committed Apr 24, 2024
1 parent d6b155e commit 999fa8f
Show file tree
Hide file tree
Showing 30 changed files with 599 additions and 211 deletions.
2 changes: 1 addition & 1 deletion .mocharc.cjs
Expand Up @@ -17,7 +17,7 @@ if (env.TEST === "unit") {
}

if (env.TEST === "docker") {
spec = ["tests/integration/docker/**/*.test.js"]
spec = ["tests/integration/docker/python/**/*.test.js"]
}

if (env.TEST === "node") {
Expand Down
7 changes: 2 additions & 5 deletions src/config/supportedRuntimes.js
Expand Up @@ -11,7 +11,6 @@ const X86_64 = "x86_64"
const ARM64 = "arm64"

export const supportedRuntimesArchitecture = {
"nodejs12.x": [ARM64, X86_64],
"nodejs14.x": [ARM64, X86_64],
"nodejs16.x": [ARM64, X86_64],
"nodejs18.x": [ARM64, X86_64],
Expand All @@ -21,7 +20,6 @@ export const supportedRuntimesArchitecture = {
"python3.9": [ARM64, X86_64],
"python3.10": [ARM64, X86_64],
"python3.11": [ARM64, X86_64],
"python3.12": [ARM64, X86_64],
"ruby2.7": [ARM64, X86_64],
"ruby3.2": [ARM64, X86_64],
java8: [X86_64],
Expand Down Expand Up @@ -59,14 +57,11 @@ export const supportedPython = new Set([
"python3.9",
"python3.10",
"python3.11",
"python3.12",
])

// RUBY
export const supportedRuby = new Set(["ruby2.7", "ruby3.2"])

// deprecated runtimes
// https://docs.aws.amazon.com/lambda/latest/dg/runtime-support-policy.html
export const supportedRuntimes = new Set([
// ...supportedDotnetcore,
...supportedGo,
Expand All @@ -77,4 +72,6 @@ export const supportedRuntimes = new Set([
...supportedRuby,
])

// deprecated runtimes
// https://docs.aws.amazon.com/lambda/latest/dg/runtime-support-policy.html
export const unsupportedDockerRuntimes = new Set([])
Binary file added tests/integration/docker/.DS_Store
Binary file not shown.
101 changes: 49 additions & 52 deletions tests/integration/docker/access-host/accessHost.test.js
@@ -1,55 +1,52 @@
// import assert from 'node:assert'
// import { env } from 'node:process'
// import { Server } from '@hapi/hapi'
// import { join } from 'desm'
// import { setup, teardown } from '../../../_testHelpers/index.js'
// import installNpmModules from '../../../installNpmModules.js'
// import { BASE_URL } from '../../../config.js'
import assert from "node:assert"
import { env } from "node:process"
import { Server } from "@hapi/hapi"
import { join } from "desm"
import { setup, teardown } from "../../../_testHelpers/index.js"
import installNpmModules from "../../../installNpmModules.js"
import { BASE_URL } from "../../../config.js"

describe("Access host with Docker tests", function desc() {
it("placeholder, node.js v12 not supported anymore", () => true)

// let server
// beforeEach(async () => {
// await installNpmModules(join(import.meta.url, 'src'))
// })
// beforeEach(async () => {
// server = new Server({ port: 8080 })
// server.route({
// handler() {
// return 'Hello Node.js!'
// },
// method: 'GET',
// path: '/hello',
// })
// await server.start()
// await setup({
// servicePath: join(import.meta.url),
// })
// })
// afterEach(async () => {
// await server.stop()
// await teardown()
// })
// //
// ;[
// {
// description: 'should access host in docker container',
// expected: {
// message: 'Hello Node.js!',
// },
// path: '/dev/hello',
// },
// ].forEach(({ description, expected, path }) => {
// it(description, async function it() {
// // "Could not find 'Docker', skipping tests."
// if (!env.DOCKER_DETECTED) {
// this.skip()
// }
// const url = new URL(path, BASE_URL)
// const response = await fetch(url)
// const json = await response.json()
// assert.deepEqual(json, expected)
// })
// })
let server
beforeEach(async () => {
await installNpmModules(join(import.meta.url, "src"))
})
beforeEach(async () => {
server = new Server({ port: 8080 })
server.route({
handler() {
return "Hello Node.js!"
},
method: "GET",
path: "/hello",
})
await server.start()
await setup({
servicePath: join(import.meta.url),
})
})
afterEach(async () => {
await server.stop()
await teardown()
})
;[
{
description: "should access host in docker container",
expected: {
message: "Hello Node.js!",
},
path: "/dev/hello",
},
].forEach(({ description, expected, path }) => {
it(description, async function it() {
// "Could not find 'Docker', skipping tests."
if (!env.DOCKER_DETECTED) {
this.skip()
}
const url = new URL(path, BASE_URL)
const response = await fetch(url)
const json = await response.json()
assert.deepEqual(json, expected)
})
})
})
2 changes: 1 addition & 1 deletion tests/integration/docker/access-host/serverless.yml
Expand Up @@ -12,7 +12,7 @@ provider:
memorySize: 1024
name: aws
region: us-east-1
runtime: nodejs12.x
runtime: nodejs18.x
stage: dev
versionFunctions: false

Expand Down
80 changes: 38 additions & 42 deletions tests/integration/docker/artifact/artifact.test.js
@@ -1,48 +1,44 @@
// import assert from 'node:assert'
// import { env } from 'node:process'
// import { join } from 'desm'
// import {
// compressArtifact,
// setup,
// teardown,
// } from '../../../_testHelpers/index.js'
// import { BASE_URL } from '../../../config.js'
import assert from "node:assert"
import { env } from "node:process"
import { join } from "desm"
import {
compressArtifact,
setup,
teardown,
} from "../../../_testHelpers/index.js"
import { BASE_URL } from "../../../config.js"

describe("Artifact with docker tests", function desc() {
it("placeholder, node.js v12 not supported anymore", () => true)
beforeEach(async () => {
await compressArtifact(join(import.meta.url), "artifacts/hello.zip", [
"handler.js",
])
return setup({
servicePath: join(import.meta.url),
})
})

// beforeEach(async () => {
// await compressArtifact(join(import.meta.url), 'artifacts/hello.zip', [
// 'handler.js',
// ])
// return setup({
// servicePath: join(import.meta.url),
// })
// })
afterEach(() => teardown())
;[
{
description: "should work with artifact in docker container",
expected: {
message: "Hello Node.js!",
},
path: "/dev/hello",
},
].forEach(({ description, expected, path }) => {
it(description, async function it() {
// "Could not find 'Docker', skipping tests."
if (!env.DOCKER_DETECTED) {
this.skip()
}

// afterEach(() => teardown())
const url = new URL(path, BASE_URL)
const response = await fetch(url)
const json = await response.json()

// //
// ;[
// {
// description: 'should work with artifact in docker container',
// expected: {
// message: 'Hello Node.js!',
// },
// path: '/dev/hello',
// },
// ].forEach(({ description, expected, path }) => {
// it(description, async function it() {
// // "Could not find 'Docker', skipping tests."
// if (!env.DOCKER_DETECTED) {
// this.skip()
// }

// const url = new URL(path, BASE_URL)
// const response = await fetch(url)
// const json = await response.json()

// assert.deepEqual(json, expected)
// })
// })
assert.deepEqual(json, expected)
})
})
})
2 changes: 1 addition & 1 deletion tests/integration/docker/artifact/serverless.yml
Expand Up @@ -12,7 +12,7 @@ provider:
memorySize: 1024
name: aws
region: us-east-1
runtime: nodejs12.x
runtime: nodejs18.x
stage: dev
versionFunctions: false

Expand Down
120 changes: 58 additions & 62 deletions tests/integration/docker/multiple/dockerMultiple.test.js
@@ -1,65 +1,61 @@
// import assert from 'node:assert'
// import { env } from 'node:process'
// import { join } from 'desm'
// import { setup, teardown } from '../../../_testHelpers/index.js'
// import { BASE_URL } from '../../../config.js'
import assert from "node:assert"
import { env } from "node:process"
import { join } from "desm"
import { setup, teardown } from "../../../_testHelpers/index.js"
import { BASE_URL } from "../../../config.js"

describe("Multiple docker containers", function desc() {
it("placeholder, node.js v12 not supported anymore", () => true)

// beforeEach(() =>
// setup({
// servicePath: join(import.meta.url),
// }),
// )

// afterEach(() => teardown())

// //
// ;[
// {
// description: 'should work with multiple mixed docker containers',
// expected1: {
// message: 'Hello Node.js!',
// },
// expected2: {
// message: 'Hello Node.js!',
// },
// expected3: {
// message: 'Hello Python!',
// },
// path1: '/dev/hello1',
// path2: '/dev/hello2',
// path3: '/dev/hello3',
// },
// ].forEach(
// ({ description, expected1, expected2, expected3, path1, path2, path3 }) => {
// it(description, async function it() {
// // "Could not find 'Docker', skipping tests."
// if (!env.DOCKER_DETECTED) {
// this.skip()
// }

// const url1 = new URL(path1, BASE_URL)
// const url2 = new URL(path2, BASE_URL)
// const url3 = new URL(path3, BASE_URL)

// const [response1, response2, response3] = await Promise.all([
// fetch(url1),
// fetch(url2),
// fetch(url3),
// ])

// const [json1, json2, json3] = await Promise.all([
// response1.json(),
// response2.json(),
// response3.json(),
// ])

// assert.equal(json1.message, expected1.message)
// assert.equal(json2.message, expected2.message)
// assert.equal(json3.message, expected3.message)
// })
// },
// )
beforeEach(() =>
setup({
servicePath: join(import.meta.url),
}),
)

afterEach(() => teardown())
;[
{
description: "should work with multiple mixed docker containers",
expected1: {
message: "Hello Node.js!",
},
expected2: {
message: "Hello Node.js!",
},
expected3: {
message: "Hello Python!",
},
path1: "/dev/hello1",
path2: "/dev/hello2",
path3: "/dev/hello3",
},
].forEach(
({ description, expected1, expected2, expected3, path1, path2, path3 }) => {
it(description, async function it() {
// "Could not find 'Docker', skipping tests."
if (!env.DOCKER_DETECTED) {
this.skip()
}

const url1 = new URL(path1, BASE_URL)
const url2 = new URL(path2, BASE_URL)
const url3 = new URL(path3, BASE_URL)

const [response1, response2, response3] = await Promise.all([
fetch(url1),
fetch(url2),
fetch(url3),
])

const [json1, json2, json3] = await Promise.all([
response1.json(),
response2.json(),
response3.json(),
])

assert.equal(json1.message, expected1.message)
assert.equal(json2.message, expected2.message)
assert.equal(json3.message, expected3.message)
})
},
)
})

0 comments on commit 999fa8f

Please sign in to comment.