feat: Working on cli client and tests
Some checks failed
CI / Run Tests (push) Failing after 3m7s

This commit is contained in:
2024-11-17 22:23:44 -05:00
parent 6472d3cd1e
commit ce18c44363
12 changed files with 287 additions and 73 deletions

View File

@@ -0,0 +1,99 @@
@_spi(Internal) import CliClient
import Dependencies
import Foundation
import Logging
import Models
import MQTTNIO
import Testing
@Test
func checkTesting() {
#expect(Bool(true))
}
@Test(
arguments: [
(MQTTClient.Version.v3_1_1, ["3", "3.1", "3.1.1", "00367894"]),
(MQTTClient.Version.v5_0, ["5", "5.1", "5.1.1", "00000500012"]),
(nil, ["0", "0.1", "0.1.1", "0000000001267894", "blob"])
]
)
func checkParseMQTTVersion(
version: MQTTClient.Version?,
strings: [String]
) {
withDependencies {
$0.cliClient = .liveValue
} operation: {
@Dependency(\.cliClient) var cliClient
for string in strings {
#expect(cliClient.parseMqttClientVersion(string) == version)
#expect(cliClient.parseMqttClientVersion("v\(string)") == version)
}
}
}
@Test(
arguments: [
(Logger.Level.debug, EnvVars(appEnv: .staging, logLevel: nil)),
(Logger.Level.debug, EnvVars(appEnv: .development, logLevel: nil)),
(Logger.Level.info, EnvVars(appEnv: .production, logLevel: nil)),
(Logger.Level.trace, EnvVars(appEnv: .testing, logLevel: nil)),
(Logger.Level.info, EnvVars(appEnv: .staging, logLevel: .info)),
(Logger.Level.trace, EnvVars(appEnv: .development, logLevel: .trace)),
(Logger.Level.warning, EnvVars(appEnv: .production, logLevel: .warning)),
(Logger.Level.debug, EnvVars(appEnv: .testing, logLevel: .debug))
]
)
func logLevelFromEnvVars(expectedLevel: Logger.Level, environment: EnvVars) {
withDependencies {
$0.cliClient = .liveValue
} operation: {
@Dependency(\.cliClient) var cliClient
#expect(cliClient.logLevel(environment) == expectedLevel)
}
}
@Test(
arguments: [
(
CliClient.EnvVarsRequest(envFilePath: nil, logger: nil, version: nil),
EnvVars()
),
(
CliClient.EnvVarsRequest(envFilePath: nil, logger: nil, version: "3"),
EnvVars(version: "3")
),
(
CliClient.EnvVarsRequest(
envFilePath: "Tests/CliClientTests/test.env",
logger: nil,
version: nil
),
EnvVars(
appEnv: .testing,
host: "test.mqtt",
port: "1234",
identifier: "testing-mqtt",
userName: "test-user",
password: "super-secret",
logLevel: .debug,
version: "5.0"
)
)
]
)
func checkMakeEnvVars(
request: CliClient.EnvVarsRequest,
expectedEnvVars: EnvVars
) async throws {
try await withDependencies {
$0.cliClient = .liveValue
$0.environment = .liveValue
$0.environment.processInfo = { [:] }
} operation: {
@Dependency(\.cliClient) var cliClient
let result = try await cliClient.makeEnvVars(request)
#expect(result == expectedEnvVars)
}
}

View File

@@ -0,0 +1,8 @@
APP_ENV="testing"
MQTT_HOST="test.mqtt"
MQTT_PORT="1234"
MQTT_IDENTIFIER="testing-mqtt"
MQTT_USERNAME="test-user"
MQTT_PASSWORD="super-secret"
LOG_LEVEL="debug"
MQTT_VERSION="5.0"