Compare commits
9 Commits
756fd0bccf
...
0.2.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
916fcb3584
|
|||
|
d9af0b8b30
|
|||
|
aa666d799a
|
|||
|
3825517dae
|
|||
|
c21695a37e
|
|||
|
3743eefa69
|
|||
|
845d566c60
|
|||
|
99f39b91af
|
|||
|
55ea88a29f
|
68
.gitea/workflows/release.yml
Executable file
68
.gitea/workflows/release.yml
Executable file
@@ -0,0 +1,68 @@
|
|||||||
|
#
|
||||||
|
name: Create and publish a Docker image
|
||||||
|
|
||||||
|
# Configures this workflow to run every time a change is pushed to the branch called `release`.
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ['release']
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
|
||||||
|
env:
|
||||||
|
REGISTRY: git.housh.dev
|
||||||
|
IMAGE_NAME: ${{ gitea.repository }}
|
||||||
|
|
||||||
|
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
|
||||||
|
jobs:
|
||||||
|
build-and-push-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
attestations: write
|
||||||
|
id-token: write
|
||||||
|
#
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ gitea.actor }}
|
||||||
|
password: ${{ secrets.CONTAINER_TOKEN }}
|
||||||
|
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
|
||||||
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=sha
|
||||||
|
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
|
||||||
|
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
|
||||||
|
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
|
||||||
|
- name: Build and push Docker image
|
||||||
|
id: push
|
||||||
|
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: docker/Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
||||||
|
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
|
||||||
|
# - name: Generate artifact attestation
|
||||||
|
# uses: actions/attest-build-provenance@v1
|
||||||
|
# with:
|
||||||
|
# subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
|
||||||
|
# subject-digest: ${{ steps.push.outputs.digest }}
|
||||||
|
# push-to-registry: true
|
||||||
|
# github-token: ${{ secrets.CONTAINER_TOKEN }}
|
||||||
@@ -1,168 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Scheme
|
|
||||||
LastUpgradeVersion = "1610"
|
|
||||||
version = "1.7">
|
|
||||||
<BuildAction
|
|
||||||
parallelizeBuildables = "YES"
|
|
||||||
buildImplicitDependencies = "YES"
|
|
||||||
buildArchitectures = "Automatic">
|
|
||||||
<BuildActionEntries>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "CliClient"
|
|
||||||
BuildableName = "CliClient"
|
|
||||||
BlueprintName = "CliClient"
|
|
||||||
ReferencedContainer = "container:">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "MQTTConnectionService"
|
|
||||||
BuildableName = "MQTTConnectionService"
|
|
||||||
BlueprintName = "MQTTConnectionService"
|
|
||||||
ReferencedContainer = "container:">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "MQTTManager"
|
|
||||||
BuildableName = "MQTTManager"
|
|
||||||
BlueprintName = "MQTTManager"
|
|
||||||
ReferencedContainer = "container:">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "Models"
|
|
||||||
BuildableName = "Models"
|
|
||||||
BlueprintName = "Models"
|
|
||||||
ReferencedContainer = "container:">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "SensorsService"
|
|
||||||
BuildableName = "SensorsService"
|
|
||||||
BlueprintName = "SensorsService"
|
|
||||||
ReferencedContainer = "container:">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "dewpoint-controller"
|
|
||||||
BuildableName = "dewpoint-controller"
|
|
||||||
BlueprintName = "dewpoint-controller"
|
|
||||||
ReferencedContainer = "container:">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
</BuildActionEntries>
|
|
||||||
</BuildAction>
|
|
||||||
<TestAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
||||||
shouldAutocreateTestPlan = "YES">
|
|
||||||
<Testables>
|
|
||||||
<TestableReference
|
|
||||||
skipped = "NO">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "CliClientTests"
|
|
||||||
BuildableName = "CliClientTests"
|
|
||||||
BlueprintName = "CliClientTests"
|
|
||||||
ReferencedContainer = "container:">
|
|
||||||
</BuildableReference>
|
|
||||||
</TestableReference>
|
|
||||||
<TestableReference
|
|
||||||
skipped = "NO">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "IntegrationTests"
|
|
||||||
BuildableName = "IntegrationTests"
|
|
||||||
BlueprintName = "IntegrationTests"
|
|
||||||
ReferencedContainer = "container:">
|
|
||||||
</BuildableReference>
|
|
||||||
</TestableReference>
|
|
||||||
</Testables>
|
|
||||||
</TestAction>
|
|
||||||
<LaunchAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
launchStyle = "0"
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
|
||||||
debugDocumentVersioning = "YES"
|
|
||||||
debugServiceExtension = "internal"
|
|
||||||
allowLocationSimulation = "YES">
|
|
||||||
<MacroExpansion>
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "dewpoint-controller"
|
|
||||||
BuildableName = "dewpoint-controller"
|
|
||||||
BlueprintName = "dewpoint-controller"
|
|
||||||
ReferencedContainer = "container:">
|
|
||||||
</BuildableReference>
|
|
||||||
</MacroExpansion>
|
|
||||||
</LaunchAction>
|
|
||||||
<ProfileAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
||||||
savedToolIdentifier = ""
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
debugDocumentVersioning = "YES">
|
|
||||||
<MacroExpansion>
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "dewpoint-controller"
|
|
||||||
BuildableName = "dewpoint-controller"
|
|
||||||
BlueprintName = "dewpoint-controller"
|
|
||||||
ReferencedContainer = "container:">
|
|
||||||
</BuildableReference>
|
|
||||||
</MacroExpansion>
|
|
||||||
</ProfileAction>
|
|
||||||
<AnalyzeAction
|
|
||||||
buildConfiguration = "Debug">
|
|
||||||
</AnalyzeAction>
|
|
||||||
<ArchiveAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
revealArchiveInOrganizer = "YES">
|
|
||||||
</ArchiveAction>
|
|
||||||
</Scheme>
|
|
||||||
@@ -34,12 +34,23 @@ public struct CliClient {
|
|||||||
|
|
||||||
/// Represents the parameters needed to create an `MQTTClient`.
|
/// Represents the parameters needed to create an `MQTTClient`.
|
||||||
///
|
///
|
||||||
///
|
|
||||||
public struct ClientRequest: Sendable {
|
public struct ClientRequest: Sendable {
|
||||||
|
|
||||||
|
/// The environment variables used to create the client.
|
||||||
public let environment: EnvVars
|
public let environment: EnvVars
|
||||||
|
|
||||||
|
/// The event loop group for the client.
|
||||||
public let eventLoopGroup: MultiThreadedEventLoopGroup
|
public let eventLoopGroup: MultiThreadedEventLoopGroup
|
||||||
|
|
||||||
|
/// A logger to use with the client.
|
||||||
public let logger: Logger?
|
public let logger: Logger?
|
||||||
|
|
||||||
|
/// Create a new client request.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - environment: The environment variables to use.
|
||||||
|
/// - eventLoopGroup: The event loop group to use on the client.
|
||||||
|
/// - logger: An optional logger to use on the client.
|
||||||
public init(
|
public init(
|
||||||
environment: EnvVars,
|
environment: EnvVars,
|
||||||
eventLoopGroup: MultiThreadedEventLoopGroup,
|
eventLoopGroup: MultiThreadedEventLoopGroup,
|
||||||
@@ -122,11 +133,10 @@ extension EnvVars {
|
|||||||
@Dependency(\.environment) var environment
|
@Dependency(\.environment) var environment
|
||||||
|
|
||||||
let defaultEnvVars = EnvVars()
|
let defaultEnvVars = EnvVars()
|
||||||
let encoder = environment.jsonEncoder()
|
let coders = environment.coders()
|
||||||
let decoder = environment.jsonDecoder()
|
|
||||||
|
|
||||||
let defaultEnvDict = (try? encoder.encode(defaultEnvVars))
|
let defaultEnvDict = (try? coders.encode(defaultEnvVars))
|
||||||
.flatMap { try? decoder.decode([String: String].self, from: $0) }
|
.flatMap { try? coders.decode([String: String].self, from: $0) }
|
||||||
?? [:]
|
?? [:]
|
||||||
|
|
||||||
let dotEnvDict = try await environment.dotEnvDict(path: dotEnvFile)
|
let dotEnvDict = try await environment.dotEnvDict(path: dotEnvFile)
|
||||||
@@ -135,7 +145,7 @@ extension EnvVars {
|
|||||||
.merging(dotEnvDict, uniquingKeysWith: { $1 })
|
.merging(dotEnvDict, uniquingKeysWith: { $1 })
|
||||||
|
|
||||||
var envVars = (try? JSONSerialization.data(withJSONObject: envVarsDict))
|
var envVars = (try? JSONSerialization.data(withJSONObject: envVarsDict))
|
||||||
.flatMap { try? decoder.decode(EnvVars.self, from: $0) }
|
.flatMap { try? coders.decode(EnvVars.self, from: $0) }
|
||||||
?? defaultEnvVars
|
?? defaultEnvVars
|
||||||
|
|
||||||
if let version {
|
if let version {
|
||||||
@@ -162,7 +172,7 @@ public extension MQTTClient {
|
|||||||
eventLoopGroupProvider: .shared(eventLoopGroup),
|
eventLoopGroupProvider: .shared(eventLoopGroup),
|
||||||
logger: logger,
|
logger: logger,
|
||||||
configuration: .init(
|
configuration: .init(
|
||||||
version: .parseOrDefualt(string: envVars.version),
|
version: .parseOrDefault(string: envVars.version),
|
||||||
disablePing: false,
|
disablePing: false,
|
||||||
userName: envVars.userName,
|
userName: envVars.userName,
|
||||||
password: envVars.password
|
password: envVars.password
|
||||||
@@ -171,10 +181,11 @@ public extension MQTTClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension MQTTClient.Version {
|
@_spi(Internal)
|
||||||
|
public extension MQTTClient.Version {
|
||||||
static let `default` = Self.v3_1_1
|
static let `default` = Self.v3_1_1
|
||||||
|
|
||||||
static func parseOrDefualt(string: String?) -> Self {
|
static func parseOrDefault(string: String?) -> Self {
|
||||||
guard let string, let value = Self(string: string) else {
|
guard let string, let value = Self(string: string) else {
|
||||||
return .default
|
return .default
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,11 +24,7 @@ public extension DependencyValues {
|
|||||||
@DependencyClient
|
@DependencyClient
|
||||||
public struct EnvironmentDependency: Sendable {
|
public struct EnvironmentDependency: Sendable {
|
||||||
|
|
||||||
/// A json decoder to use to decode files and environment variables.
|
public var coders: @Sendable () -> any Coderable = { JSONCoders() }
|
||||||
public var jsonDecoder: @Sendable () -> JSONDecoder = { JSONDecoder() }
|
|
||||||
|
|
||||||
/// A json encoder to use to encode files and environment variables.
|
|
||||||
public var jsonEncoder: @Sendable () -> JSONEncoder = { JSONEncoder() }
|
|
||||||
|
|
||||||
/// Load the variables based on the request.
|
/// Load the variables based on the request.
|
||||||
public var load: @Sendable (FileType) async throws -> [String: String] = { _ in [:] }
|
public var load: @Sendable (FileType) async throws -> [String: String] = { _ in [:] }
|
||||||
@@ -61,6 +57,8 @@ public struct EnvironmentDependency: Sendable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct DecodeError: Error {}
|
||||||
|
|
||||||
@_spi(Internal)
|
@_spi(Internal)
|
||||||
extension EnvironmentDependency: DependencyKey {
|
extension EnvironmentDependency: DependencyKey {
|
||||||
|
|
||||||
@@ -71,8 +69,7 @@ extension EnvironmentDependency: DependencyKey {
|
|||||||
encoder: JSONEncoder = .init()
|
encoder: JSONEncoder = .init()
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self(
|
Self(
|
||||||
jsonDecoder: { decoder },
|
coders: { JSONCoders(decoder: decoder, encoder: encoder) },
|
||||||
jsonEncoder: { encoder },
|
|
||||||
load: { file in
|
load: { file in
|
||||||
switch file {
|
switch file {
|
||||||
case let .dotEnv(path: path):
|
case let .dotEnv(path: path):
|
||||||
@@ -95,6 +92,39 @@ extension EnvironmentDependency: DependencyKey {
|
|||||||
public static let liveValue: EnvironmentDependency = .live()
|
public static let liveValue: EnvironmentDependency = .live()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A type that encode and decode values.
|
||||||
|
///
|
||||||
|
/// This is really just here to override tests with coders that will throw an error,
|
||||||
|
/// instead of encoding or decoding data.
|
||||||
|
///
|
||||||
|
@_spi(Internal)
|
||||||
|
public protocol Coderable {
|
||||||
|
func encode<T: Encodable>(_ instance: T) throws -> Data
|
||||||
|
func decode<T: Decodable>(_ type: T.Type, from data: Data) throws -> T
|
||||||
|
}
|
||||||
|
|
||||||
|
struct JSONCoders: Coderable {
|
||||||
|
|
||||||
|
let decoder: JSONDecoder
|
||||||
|
let encoder: JSONEncoder
|
||||||
|
|
||||||
|
init(
|
||||||
|
decoder: JSONDecoder = .init(),
|
||||||
|
encoder: JSONEncoder = .init()
|
||||||
|
) {
|
||||||
|
self.decoder = decoder
|
||||||
|
self.encoder = encoder
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode<T>(_ instance: T) throws -> Data where T: Encodable {
|
||||||
|
try encoder.encode(instance)
|
||||||
|
}
|
||||||
|
|
||||||
|
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T: Decodable {
|
||||||
|
try decoder.decode(T.self, from: data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func url(for path: String) -> URL {
|
private func url(for path: String) -> URL {
|
||||||
#if os(Linux)
|
#if os(Linux)
|
||||||
return URL(fileURLWithPath: path)
|
return URL(fileURLWithPath: path)
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ final class CliClientTests: XCTestCase {
|
|||||||
XCTAssertEqual(cliClient.parseMqttClientVersion(string), version)
|
XCTAssertEqual(cliClient.parseMqttClientVersion(string), version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XCTAssertEqual(MQTTClient.Version.parseOrDefault(string: nil), .v3_1_1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testLogLevelFromEnvironment() {
|
func testLogLevelFromEnvironment() {
|
||||||
@@ -98,6 +100,26 @@ final class CliClientTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testMakeEnvVarsWithFailingDecoder() async throws {
|
||||||
|
try await withDependencies {
|
||||||
|
$0.environment.coders = { ThrowingDecoder() }
|
||||||
|
} operation: {
|
||||||
|
@Dependency(\.cliClient) var cliClient
|
||||||
|
let envVars = try await cliClient.makeEnvVars(.init())
|
||||||
|
XCTAssertEqual(envVars, EnvVars())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testMakeEnvVarsWithFailingEncoder() async throws {
|
||||||
|
try await withDependencies {
|
||||||
|
$0.environment.coders = { ThrowingEncoder() }
|
||||||
|
} operation: {
|
||||||
|
@Dependency(\.cliClient) var cliClient
|
||||||
|
let envVars = try await cliClient.makeEnvVars(.init())
|
||||||
|
XCTAssertEqual(envVars, EnvVars())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testFileType() {
|
func testFileType() {
|
||||||
let arguments = [
|
let arguments = [
|
||||||
(EnvironmentDependency.FileType.dotEnv(path: "test.env"), "test.env"),
|
(EnvironmentDependency.FileType.dotEnv(path: "test.env"), "test.env"),
|
||||||
@@ -139,12 +161,16 @@ final class CliClientTests: XCTestCase {
|
|||||||
// - MARK: Helper
|
// - MARK: Helper
|
||||||
|
|
||||||
private func cleanFilePath(_ path: String) -> String {
|
private func cleanFilePath(_ path: String) -> String {
|
||||||
|
#if os(Linux)
|
||||||
|
return "Tests/CliClientTests/\(path)"
|
||||||
|
#else
|
||||||
let split = path.split(separator: ".")
|
let split = path.split(separator: ".")
|
||||||
let fileName = split.first!
|
let fileName = split.first!
|
||||||
let ext = split.last!
|
let ext = split.last!
|
||||||
let url = Bundle.module.url(forResource: String(fileName), withExtension: String(ext))!.absoluteString
|
let url = Bundle.module.url(forResource: String(fileName), withExtension: String(ext))!.absoluteString
|
||||||
let cleaned = url.split(separator: "file://").last!
|
let cleaned = url.split(separator: "file://").last!
|
||||||
return String(cleaned)
|
return String(cleaned)
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extension EnvVars {
|
extension EnvVars {
|
||||||
@@ -159,3 +185,28 @@ extension EnvVars {
|
|||||||
version: "5.0"
|
version: "5.0"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ThrowingDecoder: Coderable {
|
||||||
|
|
||||||
|
func encode<T>(_ instance: T) throws -> Data where T: Encodable {
|
||||||
|
try JSONEncoder().encode(instance)
|
||||||
|
}
|
||||||
|
|
||||||
|
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T: Decodable {
|
||||||
|
throw DecodeError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ThrowingEncoder: Coderable {
|
||||||
|
|
||||||
|
func encode<T>(_ instance: T) throws -> Data where T: Encodable {
|
||||||
|
throw EncodeError()
|
||||||
|
}
|
||||||
|
|
||||||
|
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T: Decodable {
|
||||||
|
try JSONDecoder().decode(T.self, from: data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DecodeError: Error {}
|
||||||
|
struct EncodeError: Error {}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
# run this with docker-compose run test
|
# run this with docker-compose run test
|
||||||
|
name: swift-mqtt-dewpoint-test
|
||||||
|
|
||||||
services:
|
services:
|
||||||
test:
|
test:
|
||||||
build:
|
build:
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
# run this with docker-compose run dewpoint_controller
|
# run this with docker-compose run dewpoint_controller
|
||||||
|
name: swift-mqtt-dewpoint
|
||||||
|
|
||||||
services:
|
services:
|
||||||
dewpoint_controller:
|
dewpoint_controller:
|
||||||
container_name: dewpoint-controller
|
container_name: dewpoint-controller
|
||||||
|
|||||||
Reference in New Issue
Block a user