Skip to content

Commit

Permalink
Make error testing more type safe
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Nov 22, 2024
1 parent 7a59e31 commit cb9f630
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Tests/ImperialTests/ImperialTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,20 @@ struct ImperialTests {

@Test("ImperialError & ServiceError")
func errors() {
let variable = "test"
let imperialError = ImperialError.missingEnvVar(variable)
#expect(
ImperialError.missingEnvVar("test").description == "ImperialError(errorType: missingEnvVar, missing enviroment variable: test)")
imperialError.description
== "ImperialError(errorType: \(imperialError.errorType.base.rawValue), missing enviroment variable: \(variable))"
)
#expect(ImperialError.missingEnvVar("foo") == ImperialError.missingEnvVar("bar"))

let endpoint = "test"
let serviceError = ServiceError.noServiceEndpoint(endpoint)
#expect(
ServiceError.noServiceEndpoint("test").description
== "ServiceError(errorType: noServiceEndpoint, service does not have available endpoint for key: test)")
serviceError.description
== "ServiceError(errorType: \(serviceError.errorType.base.rawValue), service does not have available endpoint for key: \(endpoint))"
)
#expect(ServiceError.noServiceEndpoint("foo") == ServiceError.noServiceEndpoint("bar"))
}
}

0 comments on commit cb9f630

Please sign in to comment.