-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from finestructure/develop
release-0.4.0
- Loading branch information
Showing
31 changed files
with
384 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM finestructure/swift:5.0 | ||
FROM swift:5.0 | ||
|
||
WORKDIR /package | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,3 @@ | ||
import Commander | ||
import Foundation | ||
import LegibleError | ||
import Path | ||
import PromiseKit | ||
import Rainbow | ||
import ResterCore | ||
import Yams | ||
|
||
|
||
extension Console { | ||
func display(variables: [Key: Value]) { | ||
guard variables.count > 0 else { return } | ||
Current.console.display(verbose: "Defined variables:") | ||
for v in variables.keys { | ||
Current.console.display(verbose: " - \(v)") | ||
} | ||
Current.console.display(verbose: "") | ||
} | ||
} | ||
|
||
|
||
func before(name: Request.Name) { | ||
Current.console.display("🎬 \(name.blue) started ...\n") | ||
} | ||
|
||
|
||
func after(name: Request.Name, response: Response, result: ValidationResult) -> Bool { | ||
switch result { | ||
case .valid: | ||
let duration = format(response.elapsed).map { " (\($0)s)" } ?? "" | ||
Current.console.display("✅ \(name.blue) \("PASSED".green.bold)\(duration)\n") | ||
return true | ||
case let .invalid(message): | ||
Current.console.display(verbose: "Response:".bold) | ||
Current.console.display(verbose: "\(response)\n") | ||
Current.console.display("❌ \(name.blue) \("FAILED".red.bold) : \(message.red)\n") | ||
return false | ||
} | ||
} | ||
|
||
|
||
let main = command( | ||
Flag("verbose", flag: "v", description: "Verbose output"), | ||
Option<String>("workdir", default: "", flag: "w", description: "Working directory (for the purpose of resolving relative paths in Restfiles)"), | ||
Option<TimeInterval>("timeout", default: 10, flag: "t", description: "Request timeout"), | ||
Flag("insecure", default: false, description: "do not validate SSL certificate (macOS only)"), | ||
Argument<String>("filename", description: "A Restfile") | ||
) { verbose, wdir, timeout, insecure, filename in | ||
|
||
#if !os(macOS) | ||
if insecure { | ||
Current.console.display("--insecure flag currently only supported on macOS") | ||
exit(1) | ||
} | ||
#endif | ||
|
||
Current.console.display("🚀 Resting \(filename.bold) ...\n") | ||
|
||
let restfilePath = Path(filename) ?? Path.cwd/filename | ||
Current.workDir = getWorkDir(input: wdir) ?? (restfilePath).parent | ||
|
||
if verbose { | ||
Current.console.display(verbose: "Restfile path: \(restfilePath)") | ||
Current.console.display(verbose: "Working directory: \(Current.workDir)\n") | ||
} | ||
|
||
if timeout != Request.defaultTimeout { | ||
Current.console.display(verbose: "Request timeout: \(timeout)s\n") | ||
} | ||
|
||
let rester: Rester | ||
do { | ||
rester = try Rester(path: restfilePath, workDir: Current.workDir) | ||
} catch { | ||
Current.console.display(error) | ||
exit(1) | ||
} | ||
|
||
if verbose { | ||
Current.console.display(variables: rester.allVariables) | ||
} | ||
|
||
guard rester.requestCount > 0 else { | ||
Current.console.display("⚠️ no requests defined in \(filename.bold)!") | ||
exit(0) | ||
} | ||
|
||
rester.test(before: before, after: after, timeout: timeout, validateCertificate: !insecure) | ||
.done { results in | ||
let failureCount = results.filter { !$0 }.count | ||
let failureMsg = failureCount == 0 ? "0".green.bold : failureCount.description.red.bold | ||
Current.console.display("Executed \(results.count.description.bold) tests, with \(failureMsg) failures") | ||
if failureCount > 0 { | ||
exit(1) | ||
} else { | ||
exit(0) | ||
} | ||
}.catch { error in | ||
Current.console.display(error) | ||
exit(1) | ||
} | ||
|
||
RunLoop.main.run() | ||
|
||
} | ||
|
||
|
||
main.run(ResterVersion) | ||
app.run(ResterVersion) |
Oops, something went wrong.