Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/*.xcodeproj
lambda.zip
swift-shared-libs
default.profraw
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
os:
- linux
language: generic
sudo: required
dist: xenial

services:
- docker

addons:
snaps:
- name: aws-cli
confinement: classic # or devmode
channel: latest/edge

install:
- make --version
- make docker_build

script:
- docker image ls
- make package_layer
- make package_lambda
- make swift_test
- make swift_test SWIFT_EXECUTABLE=HTTPSRequest SWIFT_PROJECT_PATH=Examples/HTTPSRequest LAMBDA_FUNCTION_NAME=HTTPSRequest LAMBDA_HANDLER=HTTPSRequest.getHttps
- make swift_test SWIFT_EXECUTABLE=S3Test SWIFT_PROJECT_PATH=Examples/S3Test LAMBDA_FUNCTION_NAME=S3Test LAMBDA_HANDLER=S3Test.getObject
27 changes: 27 additions & 0 deletions Examples/HTTPSRequest/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM nio-swift:5.1

# Or your actual UID, GID on Linux if not the default 1000
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Configure apt and install packages
RUN apt-get update \
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
&& groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
# [Optional] Add sudo support for non-root user
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=
23 changes: 23 additions & 0 deletions Examples/HTTPSRequest/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Swift",
"dockerFile": "Dockerfile",

"runArgs": [
"-u", "vscode",
"--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
],

"settings": {
"lldb.adapterType": "bundled",
"lldb.executable": "/usr/bin/lldb",
"terminal.integrated.shell.linux": "/bin/bash"
},

// Uncomment the next line if you want to publish any ports.
// "appPort": [],

"extensions": [
"pvasek.sourcekit-lsp--dev-unofficial",
"vadimcn.vscode-lldb"
]
}
26 changes: 26 additions & 0 deletions Examples/HTTPSRequest/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/.build/x86_64-unknown-linux/debug/HTTPSRequest",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "build"
},
{
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/.build/x86_64-unknown-linux/debug/HTTPSRequestPackageTests.xctest",
"name": "Test",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "codecov"
}
]
}
34 changes: 34 additions & 0 deletions Examples/HTTPSRequest/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "swift build",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "test",
"type": "shell",
"command": "swift test --enable-code-coverage || true",
"group": "test"
},
{
"label": "codecov",
"type": "shell",
"command": "llvm-cov export ${workspaceFolder}/.build/x86_64-unknown-linux/debug/HTTPSRequest -instr-profile=${workspaceFolder}/.build/x86_64-unknown-linux/debug/codecov/default.profdata -format=lcov > ${workspaceFolder}/.build/x86_64-unknown-linux/debug/codecov/lcov.info",
"group": "test",
"dependsOn":["test"]
},
{
"label": "run",
"type": "shell",
"command": "swift run"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import class Foundation.Bundle
import XCTest

final class HTTPSRequestTests: XCTestCase {
func testExample() throws {
func testMissingLambdaRuntimeApi() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
Expand All @@ -26,7 +26,9 @@ final class HTTPSRequestTests: XCTestCase {
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)

XCTAssertEqual(output, "Hello, world!\n")
let isError = output?.contains("missingEnvironmentVariables(LambdaSwiftSprinter.Context.AWSEnvironmentKey.lambdaRuntimeApi)")

XCTAssertEqual(isError, true)
}

/// Returns path to the built products directory.
Expand All @@ -42,6 +44,6 @@ final class HTTPSRequestTests: XCTestCase {
}

static var allTests = [
("testExample", testExample),
("testMissingLambdaRuntimeApi", testMissingLambdaRuntimeApi),
]
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#if !canImport(ObjectiveC)
import XCTest

#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(HTTPSRequestTests.allTests),
]
}
extension HTTPSRequestTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__HTTPSRequestTests = [
("testMissingLambdaRuntimeApi", testMissingLambdaRuntimeApi),
]
}

public func __allTests() -> [XCTestCaseEntry] {
return [
testCase(HTTPSRequestTests.__allTests__HTTPSRequestTests),
]
}
#endif
3 changes: 2 additions & 1 deletion Examples/HTTPSRequest/Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import XCTest
import HTTPSRequestTests

var tests = [XCTestCaseEntry]()
tests += HTTPSRequestTests.allTests()
tests += HTTPSRequestTests.__allTests()

XCTMain(tests)
27 changes: 27 additions & 0 deletions Examples/HelloWorld/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM nio-swift:5.1

# Or your actual UID, GID on Linux if not the default 1000
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Configure apt and install packages
RUN apt-get update \
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
&& groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
# [Optional] Add sudo support for non-root user
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=
23 changes: 23 additions & 0 deletions Examples/HelloWorld/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Swift",
"dockerFile": "Dockerfile",

"runArgs": [
"-u", "vscode",
"--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
],

"settings": {
"lldb.adapterType": "bundled",
"lldb.executable": "/usr/bin/lldb",
"terminal.integrated.shell.linux": "/bin/bash"
},

// Uncomment the next line if you want to publish any ports.
// "appPort": [],

"extensions": [
"pvasek.sourcekit-lsp--dev-unofficial",
"vadimcn.vscode-lldb"
]
}
26 changes: 26 additions & 0 deletions Examples/HelloWorld/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/.build/x86_64-unknown-linux/debug/HelloWorld",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "build"
},
{
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/.build/x86_64-unknown-linux/debug/HelloWorldPackageTests.xctest",
"name": "Test",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "codecov"
}
]
}
34 changes: 34 additions & 0 deletions Examples/HelloWorld/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "swift build",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "test",
"type": "shell",
"command": "swift test --enable-code-coverage || true",
"group": "test"
},
{
"label": "codecov",
"type": "shell",
"command": "llvm-cov export ${workspaceFolder}/.build/x86_64-unknown-linux/debug/HelloWorld -instr-profile=${workspaceFolder}/.build/x86_64-unknown-linux/debug/codecov/default.profdata -format=lcov > ${workspaceFolder}/.build/x86_64-unknown-linux/debug/codecov/lcov.info",
"group": "test",
"dependsOn":["test"]
},
{
"label": "run",
"type": "shell",
"command": "swift run"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import class Foundation.Bundle
import XCTest

final class HelloWorldTests: XCTestCase {
func testExample() throws {
func testMissingLambdaRuntimeApi() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
Expand All @@ -18,15 +18,15 @@ final class HelloWorldTests: XCTestCase {
process.executableURL = fooBinary

let pipe = Pipe()
process.standardOutput = pipe
process.standardError = pipe

try process.run()
process.waitUntilExit()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)

XCTAssertEqual(output, "Hello, world!\n")
XCTAssertEqual(output, "missingEnvironmentVariables(LambdaSwiftSprinter.Context.AWSEnvironmentKey.lambdaRuntimeApi)\n")
}

/// Returns path to the built products directory.
Expand All @@ -42,6 +42,6 @@ final class HelloWorldTests: XCTestCase {
}

static var allTests = [
("testExample", testExample),
("testMissingLambdaRuntimeApi", testMissingLambdaRuntimeApi),
]
}
21 changes: 15 additions & 6 deletions Examples/HelloWorld/Tests/HelloWorldTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#if !canImport(ObjectiveC)
import XCTest

#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(HelloWorldTests.allTests),
]
}
extension HelloWorldTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__HelloWorldTests = [
("testMissingLambdaRuntimeApi", testMissingLambdaRuntimeApi),
]
}

public func __allTests() -> [XCTestCaseEntry] {
return [
testCase(HelloWorldTests.__allTests__HelloWorldTests),
]
}
#endif
3 changes: 2 additions & 1 deletion Examples/HelloWorld/Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import XCTest
import HelloWorldTests

var tests = [XCTestCaseEntry]()
tests += HelloWorldTests.allTests()
tests += HelloWorldTests.__allTests()

XCTMain(tests)
Loading