Feature/native wrapper pr#50
Feature/native wrapper pr#50nonec wants to merge 183 commits intoDiUS:feature/nativeWrapperfrom nonec:feature/nativeWrapperPR
Conversation
Improves travisCI steps
…nt race condition
Update BrightFutures
Wait on verify to complete before allowing tests to continue
Updates README to encourage usage of pact-ruby-standalone
Update project and dependencies for Swift 4.2
I just realised I maybe even tried git-lfs before, but it's not possible to push with git-lfs to a fork. |
| @@ -0,0 +1,4 @@ | |||
| tap 'pact-foundation/pact-ruby-standalone' | |||
There was a problem hiding this comment.
To avoid having these changes that were not made by you in the PR I would encourage you to rebase origin:master onto your fork:branchPR, then force push (onto your fork:branchPR!!!) the new history.
That way any of the changes made to origin will not show up in your PR.
There was a problem hiding this comment.
TODO: (for me)
yes, I agree. I'll have to see when I have time for this. Since I think this is what I did the last time.
| @@ -1,5 +1,74 @@ | |||
| # 0.7.1 - Bugfix Release | |||
There was a problem hiding this comment.
Same applies here regarding rebasing on your PR branch. You haven't made this changes, have you? Therefore they should not be part of your PR. 🤷
| github "SwiftyJSON/SwiftyJSON" ~> 4.0 | ||
| github "Thomvis/BrightFutures" ~> 8.0 | ||
| github "Quick/Nimble" ~> 8.0 | ||
| github "SwiftyJSON/SwiftyJSON" ~> 5.0.0 No newline at end of file |
There was a problem hiding this comment.
After having Codable available to us since Swift 4, I'd encourage you to avoid bringing in more dependencies for things that Swift can do for by just using what Foundation provides.
There was a problem hiding this comment.
Also something I agree on. Original the branch was done by @andrewspinks . When I first started working on this my goal was to get it to a point that it can be merged back.
Since Codable came up I thought about this, but the top priority was to get everything else working right first.
| @@ -1 +1,2 @@ | |||
| github "Quick/Quick" ~> 1.1 | |||
| github "Quick/Quick" ~> 2.0 | |||
| github "AliSoftware/OHHTTPStubs" | |||
There was a problem hiding this comment.
I know this is not you @nonec but if you run carthage update now it will pull version 9.0.0 and it will break current implementation of tests as this dependency dropped OH prefix from all its class names. All it will bring is a headache. :|
| var newDictionary: [Key: Value] = self | ||
| for (key, value) in dictionary { | ||
| newDictionary[key] = value | ||
| for (dictKey, value) in dictionary { |
There was a problem hiding this comment.
Nitpicking here... The newDictionary already defines it as [Key: Value], following the convention would make sense.
There was a problem hiding this comment.
Are you talking about the type [Key: Value] or the naming (dictKey, value)?
| import SwiftPactServer | ||
| #endif | ||
|
|
||
| public class NativeMockServerWrapper: MockServer { |
There was a problem hiding this comment.
It is really hard to read through this class where public and private declarations are all over the place. It is hard to read and learn about interface the caller needs to interact with.
There was a problem hiding this comment.
I think it's mostly private except the MockServer protocol implementations.
What would you do to improve it?
|
|
||
| public class NativeMockServerWrapper: MockServer { | ||
| private lazy var port: Int32 = { | ||
| return findUnusedPort() |
There was a problem hiding this comment.
If this findUnusedPort() is only called here, why not have the logic encapsulated here? it's a private var too.
There was a problem hiding this comment.
TODO:
yes. I think this grew and probably was used somewhere else before.
| private let pactDir: String = ProcessInfo.processInfo.environment["pact_dir"] ?? "/tmp/pacts" | ||
| private let shouldWritePacts: Bool | ||
|
|
||
| public init(shouldWritePacts: Bool = false) { |
There was a problem hiding this comment.
is shouldWritePacts used to have a dry run on tests when it's set to false? Or does it have something to do with Filesystem?
There was a problem hiding this comment.
If I remember it correctly this was needed for the setup I'm using.
I think part of the problem was this is failing on devices and it only worked for simulators. So I had to control a bit when to write for being able to automate this in our building pipeline.
|
|
||
| // iOS json generation adds extra backslashes to "application/json" --> "application\\/json" | ||
| // causing the MockServer to fail to parse the file. | ||
| let sanitizedString = jsonString!.replacingOccurrences(of: "\\/", with: "/") |
There was a problem hiding this comment.
This sanitisation is occurring in a few places, could pull it out into a reusable method or a String extension.
| case write([String: [String: String]]) | ||
|
|
||
| var method: HTTPMethod { | ||
| var method: String { |
There was a problem hiding this comment.
HTTPMethod.rawValue should be the only place where the mapping of these should occur.
There was a problem hiding this comment.
I think HTTPMethod was from Alamofire which I removed as a dependency here.
So what would be the todo here?
| // MARK: URLRequestConvertible | ||
| func asURLRequest() throws -> URLRequest { | ||
| let url = try Router.baseURLString.asURL() | ||
| guard let url = URL(string: Router.baseURLString) else { throw NSError(domain: "", code: 1, userInfo: nil) } |
There was a problem hiding this comment.
A new merge on the origin:master made Router method to throw. This is kind of out of date now. :|
There was a problem hiding this comment.
TODO:
Yeah, I'll have to see about that
| .package(url: "https://github.com/Quick/Quick.git", from: "2.1.0"), | ||
| .package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", from: "5.0.0"), | ||
| .package(url: "https://github.com/Thomvis/BrightFutures.git", from: "8.0.0"), | ||
| .package(url: "https://github.com/nonec/SwiftPactServer.git", from: "1.0.0"), |
There was a problem hiding this comment.
Instead of having yet another git repo you rely on due to SPM, you could have it as part of the current project and define dependency as .package(path: "path/to/folder/containing/SwiftPactServer")
There was a problem hiding this comment.
I remember thinking about that. I think part of the problem was having big files in that and I couldn't use git-lfs on a fork because that would count into the space of the origin.
I'm not a 100% sure, but I think this would be something to resolve if we ever get this to a mergeable state.
|
Great job in doing this @nonec ! 👍 I see it still supports pact spect v2? Have you looked into implementing v3 to match the rust pact_mock_server? I had a scroll through but there is so much of it and there are so many changed files I know are not files you changed. It is very very hard to provide feedback because of that. I did leave a few comments that I think you made and I hope you can take it onboard (or take with you and apply on other projects). If you do manage to merge/rebase and align your PR with current |
| } | ||
| } | ||
|
|
||
| public func verify(_ pact: Pact) -> Future<String, PactError> { |
There was a problem hiding this comment.
You're passing Pact into verify() yet it is not used in the method.
There was a problem hiding this comment.
That is true. It's part of the protocol (and the ruby implementation uses it). I could just ignore it here (or move away from the ruby alternative and change the protocol)
TODO:
|
|
||
| private func writeFile() -> Int32 { | ||
| guard shouldWritePacts, checkForPath() else { | ||
| return 4 |
There was a problem hiding this comment.
It's really hard to understand what this error would be. I'd suggest you use an enum for these. Something like:
enum VerifyResult {
case failToWrite
case failToConnect
case successWrite
case successVerifyOnly
case unknown(String?)
}
Naming could be much better for this example, but you get an idea.
That way when you switch through the case you can read it and understand what is happening (case .successVerifyOnly rather than dealing with 4.
There was a problem hiding this comment.
TODO:
agreed. same is valid for the error handling in setup(_ pact: Pact). I think there was a comment on that before as well.
There was a problem hiding this comment.
Great job in doing this @nonec ! 👍 I see it still supports pact spect v2? Have you looked into implementing v3 to match the rust pact_mock_server?
I had a scroll through but there is so much of it and there are so many changed files I know are not files you changed. It is very very hard to provide feedback because of that. I did leave a few comments that I think you made and I hope you can take it onboard (or take with you and apply on other projects).
If you do manage to merge/rebase and align your PR with current
DiUS/pact-consumer-swift:masterso we can see only your changes, I'm happy to provide more constructive and in-depth feedback.
Thanks for taking the time looking at this. I'm sorry this got outdated, again.
At the moment the biggest work to get this started was done by @andrewspinks . I only picked this up (twice), updated it and get it to run.
So yes, atm it supports v2, yes. I'd really like for it to support v3.
Tbh I'm not sure if I'll do this dance once more or I'll just pick up my learnings and start over with something that only uses the native wrapper and implements v3.
Not sure when I'll have time to get into this, either way :|
So for now I tried to answer your comments and added TODOs for myself to go through, when there's time on my side.
|
Most of the learnings from this PR / branch have been taken and used in a new project here: https://github.com/surpher/PactSwift The idea is to eventually move that to the pact-foundation once it has stabilized. @nonec it would be awesome if you could take a look at that new project when if you get some spare time. I'm going to close this PR to save it getting even more out of date. |
Oh, that looks great! I hope I'll have some time to look into it soon. Thanks for the heads up! |
I wanted to try the native wrapper for a project. So I updated dependencies and made adjustments to make it work for me. It's also using Swift 5 now.
In the end I tried to clean it up but there might be some more necessary.
Made it run on Travis CI and adjusted the tests to pass.
I would be happy to receive feedback :-)