diff --git a/Dockerfile b/Dockerfile index ea0eb7e..6209864 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ + +# Build the executable FROM swift as build WORKDIR /build COPY ./Package.* ./ @@ -9,5 +11,3 @@ RUN swift build --enable-test-discovery -c release -Xswiftc -g FROM swift WORKDIR /run COPY --from=build /build/.build/release /run - - diff --git a/Makefile b/Makefile index 53d3480..88209aa 100644 --- a/Makefile +++ b/Makefile @@ -14,15 +14,11 @@ run: @swift run dewPoint-controller start-mosquitto: - @docker run \ - --name mosquitto \ - -d \ - -p 1883:1883 \ - -p 8883:8883 \ - -p 8080:8080 \ - -p 8081:8081 \ - -v "$(PWD)/mosquitto/config:/mosquitto/config" \ - eclipse-mosquitto + @docker compose start 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 diff --git a/Tests/ClientTests/ClientTests.swift b/Tests/ClientTests/ClientTests.swift index 3d13c61..e45539e 100644 --- a/Tests/ClientTests/ClientTests.swift +++ b/Tests/ClientTests/ClientTests.swift @@ -79,8 +79,10 @@ final class ClientLiveTests: XCTestCase { Thread.sleep(forTimeInterval: 2) XCTAssertEqual(state.sensors.returnAirSensor.temperature, .celsius(75.1234)) - - try client.shutdown().wait() + try mqttClient.disconnect().wait() + try mqttClient.syncShutdownGracefully() + +// try client.shutdown().wait() } func test_client2_returnSensor_publish() throws { @@ -111,7 +113,10 @@ final class ClientLiveTests: XCTestCase { try client.publishSensor(.return(state.sensors.returnAirSensor)).wait() 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 { diff --git a/docker-compose.yaml b/docker-compose.yaml index f17e16d..e6dd6f1 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,26 +3,41 @@ version: "3" services: test: - #image: swift:latest - build: - context: ./ + image: swift:latest + #build: + #context: ./ platform: linux/amd64 working_dir: /app + networks: + - test volumes: - .:/app depends_on: - - mosquitto + - mosquitto-test environment: - - MOSQUITTO_SERVER=mosquitto - command: "swift package clean && swift test" + - MOSQUITTO_SERVER=mosquitto-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: image: eclipse-mosquitto volumes: - ./mosquitto/config:/mosquitto/config - ./mosquitto/certs:/mosquitto/certs - #ports: - #- "1883:1883" - #- "8883:8883" - #- "8080:8080" - #- "8081:8081" + ports: + - "1883:1883" + - "8883:8883" + - "8080:8080" + - "8081:8081" + +networks: + test: + driver: bridge + external: false