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

Commit f0518df

Browse files
Merge pull request #3 from Andrea-Scuderi/feature/travis_ci
Feature/travis ci
2 parents d9597d2 + df3ebe8 commit f0518df

File tree

19 files changed

+462
-86
lines changed

19 files changed

+462
-86
lines changed

.devcontainer/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM swift:5.1.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=

.devcontainer/devcontainer.json

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+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/.build
33
/Packages
44
/*.xcodeproj
5+
default.profraw

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 swift_test_with_coverage
23+
24+
after_success:
25+
- bash <(curl -s https://codecov.io/bash) -f .build/x86_64-unknown-linux/debug/codecov/lcov.info

.vscode/launch.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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/LambdaSwiftSprinterNioPluginPackageTests.xctest",
12+
"args": [],
13+
"cwd": "${workspaceFolder}",
14+
"preLaunchTask": "build"
15+
},
16+
17+
{
18+
"type": "lldb",
19+
"request": "launch",
20+
"program": "${workspaceFolder}/.build/x86_64-unknown-linux/debug/LambdaSwiftSprinterNioPluginPackageTests.xctest",
21+
"name": "Test",
22+
"args": [],
23+
"cwd": "${workspaceFolder}",
24+
"preLaunchTask": "test"
25+
}
26+
]
27+
}

.vscode/tasks.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 test",
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": "run",
23+
"type": "shell",
24+
"command": "swift run"
25+
}
26+
]
27+
}

Makefile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
SWIFT_DOCKER_IMAGE=swift:latest
2-
SWIFT_PACKAGE=aws-lambda-swift-sprinter-nio-plugin
3-
MOUNT_ROOT="$(shell pwd)/.."
1+
SWIFT_VERSION?=5.1.1
42

5-
swift_test:
3+
DOCKER_TAG=nio-swift:$(SWIFT_VERSION)
4+
SWIFT_DOCKER_IMAGE=$(DOCKER_TAG)
5+
6+
docker_build:
7+
docker build --tag $(DOCKER_TAG) docker/$(SWIFT_VERSION)/.
8+
9+
swift_test_with_coverage:
610
docker run \
711
--rm \
8-
--volume "$(MOUNT_ROOT):/src" \
9-
--workdir "/src" \
12+
--volume "$(shell pwd)/:/src" \
13+
--workdir "/src/" \
1014
$(SWIFT_DOCKER_IMAGE) \
11-
/bin/bash -c "cd $(SWIFT_PACKAGE); swift test"
15+
/bin/bash -c "swift test --enable-code-coverage && ./export-coverage-test.sh"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# aws-lambda-swift-sprinter-nio-plugin
22

33

4-
[![Swift 5](https://img.shields.io/badge/Swift-5.0-blue.svg)](https://swift.org/download/) [![Swift 5.1](https://img.shields.io/badge/Swift-5.1-blue.svg)](https://swift.org/download/) ![](https://img.shields.io/badge/version-1.0.0--alpha.2-red)
4+
[![Swift 5](https://img.shields.io/badge/Swift-5.0-blue.svg)](https://swift.org/download/) [![Swift 5.1.1](https://img.shields.io/badge/Swift-5.1.1-blue.svg)](https://swift.org/download/) ![](https://img.shields.io/badge/version-1.0.0--alpha.2-red) [![codecov](https://codecov.io/gh/swift-sprinter/aws-lambda-swift-sprinter-nio-plugin/branch/master/graph/badge.svg)](https://codecov.io/gh/swift-sprinter/aws-lambda-swift-sprinter-nio-plugin)
55

66
The project implements an HTTPS client plugin for the [LambdaSwiftSprinter](https://github.com/swift-sprinter/aws-lambda-swift-sprinter-core) framework.
77

Sources/LambdaSwiftSprinterNioPlugin/LambdaApiNIO.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,22 @@ public var lambdaRuntimeTimeout: TimeAmount = .seconds(3600)
3232
public var timeout = HTTPClient.Configuration.Timeout(connect: lambdaRuntimeTimeout,
3333
read: lambdaRuntimeTimeout)
3434

35-
public var httpClient: HTTPClient = {
35+
public var httpClient: HTTPClientProtocol = {
3636
let configuration = HTTPClient.Configuration(timeout: timeout)
3737
return HTTPClient(eventLoopGroupProvider: .createNew, configuration: configuration)
3838
}()
3939

40+
public protocol HTTPClientProtocol: class {
41+
func get(url: String, deadline: NIODeadline?) -> EventLoopFuture<HTTPClient.Response>
42+
func post(url: String, body: HTTPClient.Body?, deadline: NIODeadline?) -> EventLoopFuture<HTTPClient.Response>
43+
func execute(request: HTTPClient.Request, deadline: NIODeadline?) -> EventLoopFuture<HTTPClient.Response>
44+
func syncShutdown() throws
45+
}
46+
47+
extension HTTPClient: HTTPClientProtocol {
48+
49+
}
50+
4051
public class LambdaApiNIO: LambdaAPI {
4152
let urlBuilder: LambdaRuntimeAPIUrlBuilder
4253

@@ -47,7 +58,8 @@ public class LambdaApiNIO: LambdaAPI {
4758
public func getNextInvocation() throws -> (event: Data, responseHeaders: [AnyHashable: Any]) {
4859
let request = try HTTPClient.Request(url: urlBuilder.nextInvocationURL(), method: .GET)
4960
let result = try httpClient.execute(
50-
request: request
61+
request: request,
62+
deadline: nil
5163
).wait()
5264

5365
let httpHeaders = result.headers
@@ -72,7 +84,8 @@ public class LambdaApiNIO: LambdaAPI {
7284
)
7385
request.body = .data(httpBody)
7486
_ = try httpClient.execute(
75-
request: request
87+
request: request,
88+
deadline: nil
7689
).wait()
7790
}
7891

@@ -87,7 +100,8 @@ public class LambdaApiNIO: LambdaAPI {
87100
request.body = .data(httpBody)
88101

89102
_ = try httpClient.execute(
90-
request: request
103+
request: request,
104+
deadline: nil
91105
).wait()
92106
}
93107

@@ -102,7 +116,8 @@ public class LambdaApiNIO: LambdaAPI {
102116
request.body = .data(httpBody)
103117

104118
_ = try httpClient.execute(
105-
request: request
119+
request: request,
120+
deadline: nil
106121
).wait()
107122
}
108123
}

Sources/LambdaSwiftSprinterNioPlugin/Utils.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@ internal extension HTTPHeaders {
3434
}
3535

3636
internal extension Data {
37-
func decode<T: Decodable>() throws -> T {
38-
let jsonDecoder = JSONDecoder()
39-
guard let input = try? jsonDecoder.decode(T.self, from: self) else {
40-
throw SprinterError.invalidJSON
41-
}
42-
return input
43-
}
4437

4538
init<T: Encodable>(from object: T) throws {
4639
let jsonEncoder = JSONEncoder()
4740
self = try jsonEncoder.encode(object)
4841
}
42+
43+
var byteBuffer: ByteBuffer {
44+
var buffer = ByteBufferAllocator().buffer(capacity: self.count)
45+
buffer.writeBytes(self)
46+
return buffer
47+
}
4948
}
5049

5150
internal extension HTTPResponseStatus {

0 commit comments

Comments
 (0)