Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 7554075

Browse files
Merge pull request #15 from Andrea-Scuderi/feature/VisualStudioCodeDebug
Add minimal support for Travis CI and Visual Studio Code
2 parents 0a8edbf + d5f53a7 commit 7554075

File tree

24 files changed

+425
-33
lines changed

24 files changed

+425
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/*.xcodeproj
55
lambda.zip
66
swift-shared-libs
7+
default.profraw

.travis.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
os:
2+
- linux
3+
language: generic
4+
sudo: required
5+
dist: xenial
6+
7+
services:
8+
- docker
9+
10+
addons:
11+
snaps:
12+
- name: aws-cli
13+
confinement: classic # or devmode
14+
channel: latest/edge
15+
16+
install:
17+
- make --version
18+
- make docker_build
19+
20+
script:
21+
- docker image ls
22+
- make package_layer
23+
- make package_lambda
24+
- make swift_test
25+
- make swift_test SWIFT_EXECUTABLE=HTTPSRequest SWIFT_PROJECT_PATH=Examples/HTTPSRequest LAMBDA_FUNCTION_NAME=HTTPSRequest LAMBDA_HANDLER=HTTPSRequest.getHttps
26+
- make swift_test SWIFT_EXECUTABLE=S3Test SWIFT_PROJECT_PATH=Examples/S3Test LAMBDA_FUNCTION_NAME=S3Test LAMBDA_HANDLER=S3Test.getObject
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM nio-swift:5.1
2+
3+
# Or your actual UID, GID on Linux if not the default 1000
4+
ARG USERNAME=vscode
5+
ARG USER_UID=1000
6+
ARG USER_GID=$USER_UID
7+
8+
# Avoid warnings by switching to noninteractive
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
11+
# Configure apt and install packages
12+
RUN apt-get update \
13+
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
14+
&& groupadd --gid $USER_GID $USERNAME \
15+
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
16+
# [Optional] Add sudo support for non-root user
17+
&& apt-get install -y sudo \
18+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
19+
&& chmod 0440 /etc/sudoers.d/$USERNAME \
20+
#
21+
# Clean up
22+
&& apt-get autoremove -y \
23+
&& apt-get clean -y \
24+
&& rm -rf /var/lib/apt/lists/*
25+
26+
# Switch back to dialog for any ad-hoc use of apt-get
27+
ENV DEBIAN_FRONTEND=
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "Swift",
3+
"dockerFile": "Dockerfile",
4+
5+
"runArgs": [
6+
"-u", "vscode",
7+
"--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
8+
],
9+
10+
"settings": {
11+
"lldb.adapterType": "bundled",
12+
"lldb.executable": "/usr/bin/lldb",
13+
"terminal.integrated.shell.linux": "/bin/bash"
14+
},
15+
16+
// Uncomment the next line if you want to publish any ports.
17+
// "appPort": [],
18+
19+
"extensions": [
20+
"pvasek.sourcekit-lsp--dev-unofficial",
21+
"vadimcn.vscode-lldb"
22+
]
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug",
11+
"program": "${workspaceFolder}/.build/x86_64-unknown-linux/debug/HTTPSRequest",
12+
"args": [],
13+
"cwd": "${workspaceFolder}",
14+
"preLaunchTask": "build"
15+
},
16+
{
17+
"type": "lldb",
18+
"request": "launch",
19+
"program": "${workspaceFolder}/.build/x86_64-unknown-linux/debug/HTTPSRequestPackageTests.xctest",
20+
"name": "Test",
21+
"args": [],
22+
"cwd": "${workspaceFolder}",
23+
"preLaunchTask": "codecov"
24+
}
25+
]
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "build",
8+
"type": "shell",
9+
"command": "swift build",
10+
"group": {
11+
"kind": "build",
12+
"isDefault": true
13+
}
14+
},
15+
{
16+
"label": "test",
17+
"type": "shell",
18+
"command": "swift test --enable-code-coverage || true",
19+
"group": "test"
20+
},
21+
{
22+
"label": "codecov",
23+
"type": "shell",
24+
"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",
25+
"group": "test",
26+
"dependsOn":["test"]
27+
},
28+
{
29+
"label": "run",
30+
"type": "shell",
31+
"command": "swift run"
32+
}
33+
]
34+
}

Examples/HTTPSRequest/Tests/HTTPSRequestTests/HTTPSRequestTests.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import class Foundation.Bundle
22
import XCTest
33

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

29-
XCTAssertEqual(output, "Hello, world!\n")
29+
let isError = output?.contains("missingEnvironmentVariables(LambdaSwiftSprinter.Context.AWSEnvironmentKey.lambdaRuntimeApi)")
30+
31+
XCTAssertEqual(isError, true)
3032
}
3133

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

4446
static var allTests = [
45-
("testExample", testExample),
47+
("testMissingLambdaRuntimeApi", testMissingLambdaRuntimeApi),
4648
]
4749
}
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
#if !canImport(ObjectiveC)
12
import XCTest
23

3-
#if !canImport(ObjectiveC)
4-
public func allTests() -> [XCTestCaseEntry] {
5-
return [
6-
testCase(HTTPSRequestTests.allTests),
7-
]
8-
}
4+
extension HTTPSRequestTests {
5+
// DO NOT MODIFY: This is autogenerated, use:
6+
// `swift test --generate-linuxmain`
7+
// to regenerate.
8+
static let __allTests__HTTPSRequestTests = [
9+
("testMissingLambdaRuntimeApi", testMissingLambdaRuntimeApi),
10+
]
11+
}
12+
13+
public func __allTests() -> [XCTestCaseEntry] {
14+
return [
15+
testCase(HTTPSRequestTests.__allTests__HTTPSRequestTests),
16+
]
17+
}
918
#endif

Examples/HTTPSRequest/Tests/LinuxMain.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import XCTest
33
import HTTPSRequestTests
44

55
var tests = [XCTestCaseEntry]()
6-
tests += HTTPSRequestTests.allTests()
6+
tests += HTTPSRequestTests.__allTests()
7+
78
XCTMain(tests)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM nio-swift:5.1
2+
3+
# Or your actual UID, GID on Linux if not the default 1000
4+
ARG USERNAME=vscode
5+
ARG USER_UID=1000
6+
ARG USER_GID=$USER_UID
7+
8+
# Avoid warnings by switching to noninteractive
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
11+
# Configure apt and install packages
12+
RUN apt-get update \
13+
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
14+
&& groupadd --gid $USER_GID $USERNAME \
15+
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
16+
# [Optional] Add sudo support for non-root user
17+
&& apt-get install -y sudo \
18+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
19+
&& chmod 0440 /etc/sudoers.d/$USERNAME \
20+
#
21+
# Clean up
22+
&& apt-get autoremove -y \
23+
&& apt-get clean -y \
24+
&& rm -rf /var/lib/apt/lists/*
25+
26+
# Switch back to dialog for any ad-hoc use of apt-get
27+
ENV DEBIAN_FRONTEND=

0 commit comments

Comments
 (0)