-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added --monkeypatch option to pact mock service start up command and … #60
Added --monkeypatch option to pact mock service start up command and … #60
Conversation
…pact provider verifier command
"when user specifies valid options fails with "1) Pact Spec Create serverFactory when user specifies valid options should return serverFactory using specified options: because the named file obviously doesn't exist. Not sure how to specify a file such that it will be found in the builds. |
Now, "when user specifies invalid log fails with
The origin version of the test,
seemed not to do what its spec said, so I tried to fix it with,
but since it does
it never fails - unless I find a name that is invalid in all possible environments. Linux only forbids '/' in file/dir names, but any '/' I use will be swallowed by path.normalize(). I propose to delete this test. Will comment it out for now. |
Yes, I think the mock just creates whatever path you give it for the log. |
Thanks for this @oliver-gramberg, it mostly looks OK to me. There's another fundamental PR in the works at the moment, this is probably best done after that. |
Can you get the PWD via a function and prepend it to the relative path of the monkeypatch file to get its absolute path? I would actually expect there to be an absolute path function in the file utils class. |
@bethesque, sorry not sure where exactly you want me to do that. I did not find the place where the CLI is being called. Different repo? |
I was suggesting a solution for that. Something like Can I make a suggestion here? You seem to be testing the functionality, not the "contract" (interface). All your test needs to do is show that the absolute path is passed correctly to "--monkeypatch", rather than prove that the behaviour is correct. Along the lines of: https://docs.pact.io/best_practices/contract_tests_not_functional_tests.html The tests that prove that the monkeypatch actually works are in the ruby codebase itself. |
I'm not actually sure how it works, as I don't maintain the js repos, sorry. |
OK, it's about the test code, not the production code. That answers my "where" question, at least partly. I was assuming the opposite, thinking you wanted me to actually get the monkeypatch parameter set. Always happy to learn! I like the argument the article you referenced makes, and I think I will actually be able to apply it my current project. For this fork/PR: I copied existing test cases and adapted them to use the monkeypatch parameter. Yes, it's testing the functionality (of the wrapper code), but so are the tests where I copied from, and I am not testing deeper than those. Or am I? If I were to test the correct implementation of the monkeypatch, then shouldn't I have coded an expectation about the non-mangling of HTTP headers? I am still not sure we're talking about the exact same pieces of code. Could we use the commenting feature of Github on the code diff tab of the PR? |
}).to.throw(Error); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CLI can really only return a couple of responses. It can return an exit code 0, or an exit code 1. The only thing you can do if you get an error response is to spit out the error message, and fail the calling code. Personally, I wouldn't have this test above, because all the "how I handle the exit error code" tests are going to be the same. All you need to test is "how should the client behave when it gets an error", not "what are all the different things that can cause an error". Theoretically, the underlying Ruby process could change its implementation to just ignore a missing monkeypatch file, and then this test would fail, so it's not actually testing something pertinent to the js codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test exercises src/server.ts:125 ff. where I check if the named file exists. If not, the CLI is never called, but an Error is thrown.
I've added a comment next to the bit of code that made me think of the "test the interface, not the behaviour" approach. |
Bump, what are we thinking on this issue folks? |
I would like it in please. We don't need to advertise the feature, but it helps us work around limitations of certain libraries (eg. Rack::Test which expects headers to always be in Dasherized-Capitalized-Format) |
I'm really not a fan of fixing this level since it is something inherently wrong with the core library, hence any language specific implementation that uses it will break. Would be more efficient to fix it at the core. |
|
Sure, I understand that, but again, all libraries that are using the core
will have this issue, so instead of fixing it only in pact-node, how about
we fix it closer to the root cause?
…On Thu, Feb 15, 2018 at 1:48 PM Beth Skurrie ***@***.***> wrote:
it is something inherently wrong with the core library - there is an
assumption in Rack::Test that all HTTP headers follow the same format.
While it is recommended and common to use capitalized words with dashes, it
is not actually mandatory, and there is at least one person out there who
can't use Pact because of this code, as they use lower case and
underscores. I am not in a position to change the behaviour of Rack::Test,
as it is the most widely used HTTP testing library in Ruby, and for 99% of
use cases, they are correct to make the assumption that they do. I can,
however, provide a way for the probably less than 1% of users to alter the
code to allow them to use our library.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#60 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAjA5LlBycyzThtCWA6QPujsMMPuX39Eks5tU5rvgaJpZM4QZcXg>
.
|
Are you suggesting that I fix the Ruby code in the standalone? As I've said, I can't fix it, and even if I could, changing the behaviour of that particular bit of code is not what we want to do for all users. I can only provide a way to load a Ruby file that can alter the behaviour for their particular use case. To do this, I have added a |
@bethesque just thinking out loud here, could this be resolved by overriding the headers with the the Down the track, supporting "request filters" as a first class citizen could also be a nice catch here. |
I spent quite a lot of time looking in to this, and this was the only solution I could come up with. |
Here's an example of why this feature is really useful. I've been trying to fix this issue. The code that needs to be altered is embedded deep in the Ruby chain. By using the monkeypatch file, I can modify the code to allow me to test potential fixes without having to repackage everything (ruby, travelling ruby, js...) every time. Fast feedback loops lead to fast bug fixes. By exposing the monkeypatch option in the js, I'll be able to experiment with fixes really easily, or allow other people to try out fixes on their local machines if it's something that I can't reproduce (which seems to happen a lot with windows!) |
Alright, fine, I'll get this done. Should we document this feature with an
extreme warning or not document it at all so people don't abuse it?
…On Thu, Feb 22, 2018 at 2:10 PM Beth Skurrie ***@***.***> wrote:
Here's an example of why this feature is really useful. I've been trying
to fix this <pact-foundation/pact-js#150>
issue. The code that needs to be altered is embedded deep in the Ruby
chain. By using the monkeypatch
<pact-foundation/pact-ruby-standalone-windows-test@0352de0>
file, I can modify the code to allow me to test potential fixes without
having to repackage everything (ruby, travelling ruby, js...) every time.
Fast feedback loops lead to fast bug fixes. By exposing the monkeypatch
option in the js, I'll be able to experiment with fixes really easily, or
allow other people to try out fixes on their local machines if it's
something that I can't reproduce (which seems to happen a lot with windows!)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#60 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAjA5Mwo3RJKn1bKUGO6XntJY8EX4WcMks5tXNqNgaJpZM4QZcXg>
.
|
Let's not document it. It'll only need to be used under "adult supervision" (ie. instructions from me!) |
cool :)
…On Mon, Feb 26, 2018 at 9:31 AM Beth Skurrie ***@***.***> wrote:
Let's not document it. It'll only need to be used under "adult
supervision" (ie. instructions from me!)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#60 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAjA5KTQ-tyo5nWulwEDbv_Si_qOiTqCks5tYd9egaJpZM4QZcXg>
.
|
I'm going to close this PR as I merged it manually because of all the major changes that had happened since and added more tests to make sure that the monkeypatch option actually works (thanks @bethesque for the mini test with the ruby file). Version 6.11.0 will be going out soon with this. |
…pact provider verifier command
Fix #54
These changes have been made blind, as I have not yet been able to set up an environment where I can compile and test (help appreciated), but they have been reviewed by our local TS expert :-)