Fixed docker tests

This commit is contained in:
2022-04-17 20:05:36 -04:00
parent 41dab0cd30
commit 6b821d47b9
4 changed files with 42 additions and 26 deletions

View File

@@ -1,3 +1,5 @@
# Build the executable
FROM swift as build FROM swift as build
WORKDIR /build WORKDIR /build
COPY ./Package.* ./ COPY ./Package.* ./
@@ -9,5 +11,3 @@ RUN swift build --enable-test-discovery -c release -Xswiftc -g
FROM swift FROM swift
WORKDIR /run WORKDIR /run
COPY --from=build /build/.build/release /run COPY --from=build /build/.build/release /run

View File

@@ -14,15 +14,11 @@ run:
@swift run dewPoint-controller @swift run dewPoint-controller
start-mosquitto: start-mosquitto:
@docker run \ @docker compose start mosquitto
--name mosquitto \
-d \
-p 1883:1883 \
-p 8883:8883 \
-p 8080:8080 \
-p 8081:8081 \
-v "$(PWD)/mosquitto/config:/mosquitto/config" \
eclipse-mosquitto
stop-mosquitto: stop-mosquitto:
@docker rm -f mosquitto || true @docker compose rm -f mosquitto || true
test-docker:
@docker compose run -i test
@docker compose kill mosquitto-test

View File

@@ -79,8 +79,10 @@ final class ClientLiveTests: XCTestCase {
Thread.sleep(forTimeInterval: 2) Thread.sleep(forTimeInterval: 2)
XCTAssertEqual(state.sensors.returnAirSensor.temperature, .celsius(75.1234)) XCTAssertEqual(state.sensors.returnAirSensor.temperature, .celsius(75.1234))
try mqttClient.disconnect().wait()
try client.shutdown().wait() try mqttClient.syncShutdownGracefully()
// try client.shutdown().wait()
} }
func test_client2_returnSensor_publish() throws { func test_client2_returnSensor_publish() throws {
@@ -111,7 +113,10 @@ final class ClientLiveTests: XCTestCase {
try client.publishSensor(.return(state.sensors.returnAirSensor)).wait() try client.publishSensor(.return(state.sensors.returnAirSensor)).wait()
XCTAssertFalse(state.sensors.returnAirSensor.needsProcessed) XCTAssertFalse(state.sensors.returnAirSensor.needsProcessed)
try client.shutdown().wait() try mqttClient.disconnect().wait()
try mqttClient.syncShutdownGracefully()
// try client.shutdown().wait()
} }
// func test_fetch_humidity() throws { // func test_fetch_humidity() throws {

View File

@@ -3,26 +3,41 @@ version: "3"
services: services:
test: test:
#image: swift:latest image: swift:latest
build: #build:
context: ./ #context: ./
platform: linux/amd64 platform: linux/amd64
working_dir: /app working_dir: /app
networks:
- test
volumes: volumes:
- .:/app - .:/app
depends_on: depends_on:
- mosquitto - mosquitto-test
environment: environment:
- MOSQUITTO_SERVER=mosquitto - MOSQUITTO_SERVER=mosquitto-test
command: "swift package clean && swift test" command: /bin/bash -xc "swift package clean && swift test"
mosquitto-test:
image: eclipse-mosquitto
networks:
- test
volumes:
- ./mosquitto/config:/mosquitto/config
- ./mosquitto/certs:/mosquitto/certs
mosquitto: mosquitto:
image: eclipse-mosquitto image: eclipse-mosquitto
volumes: volumes:
- ./mosquitto/config:/mosquitto/config - ./mosquitto/config:/mosquitto/config
- ./mosquitto/certs:/mosquitto/certs - ./mosquitto/certs:/mosquitto/certs
#ports: ports:
#- "1883:1883" - "1883:1883"
#- "8883:8883" - "8883:8883"
#- "8080:8080" - "8080:8080"
#- "8081:8081" - "8081:8081"
networks:
test:
driver: bridge
external: false