pact-foundation / pact-mock_service

Provides a mock service for use with Pact
https://pact.io
MIT License
72 stars 68 forks source link

feat: pact-stub-service log level cli opt #109

Closed YOU54F closed 5 years ago

YOU54F commented 5 years ago

Easy one, fixes #100

➜  pact-mock_service git:(feat/stubservicelog) ✗ pact-stub-service --help
Usage:
  pact-stub-service PACT_URI ...

Options:
  -p, [--port=PORT]            # Port on which to run the service
  -h, [--host=HOST]            # Host on which to bind the service
                               # Default: localhost
  -l, [--log=LOG]              # File to which to log output
      [--log-level=LOG_LEVEL]  # Log level. Options are DEBUG INFO WARN ERROR
                               # Default: DEBUG
  -o, [--cors=CORS]            # Support browser security in tests by responding to OPTIONS requests and adding CORS headers to mocked responses
      [--ssl], [--no-ssl]      # Use a self-signed SSL cert to run the service over HTTPS
      [--sslcert=SSLCERT]      # Specify the path to the SSL cert to use when running the service over HTTPS
      [--sslkey=SSLKEY]        # Specify the path to the SSL key to use when running the service over HTTPS

Showing info level only, still shows registered expectations, matches and mis-matches, but doesn't log full bodies (ideal for our CI server as the log buffer gets filled up)

➜  pact-mock_service git:(feat/stubservicelog) ✗ pact-stub-service https://you54f.co.uk/pacts/provider/file-upload-service/consumer/test-consumer/latest --port=8080 --log-level=INFO
INFO: Loading interactions from https://you54f.co.uk/pacts/provider/file-upload-service/consumer/test-consumer/latest
I, [2019-05-01T00:55:27.366550 #92064]  INFO -- : Registered expected interaction POST /upload
I, [2019-05-01T00:55:27.366980 #92064]  INFO -- : Registered expected interaction POST /upload
INFO  WEBrick 1.3.1
INFO  ruby 2.2.6 (2016-11-15) [x86_64-darwin18]
INFO  WEBrick::HTTPServer#start: pid=92064 port=8080
I, [2019-05-01T00:55:30.282591 #92064]  INFO -- : Received request POST /upload
I, [2019-05-01T00:55:30.283843 #92064]  INFO -- : Found matching response for POST /upload
I, [2019-05-01T00:55:37.018832 #92064]  INFO -- : Received request POST /upload
E, [2019-05-01T00:55:37.019241 #92064] ERROR -- : No matching interaction found for POST /upload
E, [2019-05-01T00:55:37.019266 #92064] ERROR -- : Interaction diffs for that route:
E, [2019-05-01T00:55:37.019945 #92064] ERROR -- : Diff with interaction: "a well formed request with a base 64 encoded pdf to upload" given "Service is up and healthy"

Description of differences
--------------------------------------

@@ -1,7 +1,7 @@
 ----------------------------713166514119664968500586
 Content-Disposition: form-data; name="test"

-testd
+test
 ----------------------------713166514119664968500586
 Content-Disposition: form-data; name="document"; filename="test-base64.pdf"
 Content-Type: application/pdf

Diff with interaction: "a well formed request with a binary encoded pdf to upload" given "Service is up and healthy"

Description of differences
--------------------------------------

@@ -1,11 +1,22 @@
 ----------------------------713166514119664968500586
 Content-Disposition: form-data; name="test"

-testd
+test
 ----------------------------713166514119664968500586
-Content-Disposition: form-data; name="document"; filename="test-base64.pdf"
+Content-Disposition: form-data; name="document"; filename="test.pdf"
 Content-Type: application/pdf

-JVBERi0xLjIgCjkgMCBvYmoKPDwKPj4Kc3RyZWFtCkJULyA5IFRmKFRlc3QpJyBFVAplbmRzdHJlYW0KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCA1IDAgUgovQ29udGVudHMgOSAwIFIKPj4KZW5kb2JqCjUgMCBvYmoKPDwKL0tpZHMgWzQgMCBSIF0KL0NvdW50IDEKL1R5cGUgL1BhZ2VzCi9NZWRpYUJveCBbIDAgMCA5OSA5IF0KPj4KZW5kb2JqCjMgMCBvYmoKPDwKL1BhZ2VzIDUgMCBSCi9UeXBlIC9DYXRhbG9nCj4+CmVuZG9iagp0cmFpbGVyCjw8Ci9Sb290IDMgMCBSCj4+CiUlRU9G
+%PDF-1.0
+1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj 3 0 obj<</Type/Page/MediaBox[0 0 3 3]>>endobj
+xref
+0 4
+0000000000 65535 f
+0000000010 00000 n
+0000000053 00000 n
+0000000102 00000 n
+trailer<</Size 4/Root 1 0 R>>
+startxref
+149
+%EOF
 ----------------------------713166514119664968500586--
YOU54F commented 5 years ago

Also note, there is a change in tasks/package.rake, I couldn't run bundle exec rake package as per the packaging docs, and had to update line 82 in the aforementioned package file.

I noted a change to the filename further up the script in the history

https://github.com/pact-foundation/pact-mock_service/commit/36ea23fef8f82b1062e0a63a45690fd7359b7736

much confuse! :)

This was out the box with bundle exec rake package and ruby 2.2.6 rebuilt with openssl (installed with rvm)

➜  pact-mock_service git:(feat/stubservicelog) ✗ bundle exec rake package
rm -rf build/tmp
mkdir -p build/tmp
cp pact-mock_service.gemspec  Gemfile Gemfile.lock build/tmp/
mkdir -p build/tmp/lib/pact/mock_service
cp lib/pact/mock_service/version.rb build/tmp/lib/pact/mock_service/version.rb
cd build/tmp && env BUNDLE_IGNORE_CONFIG=1 bundle install --path ../vendor --without development
Using awesome_print 1.8.0
Using bundler 1.16.6
Using diff-lcs 1.3
Using filelock 1.1.1
Using find_a_port 1.0.1
Using json 2.2.0
Using randexp 0.1.7
Using rspec-support 3.8.0
Using rspec-core 3.8.0
Using rspec-expectations 3.8.3
Using rspec-mocks 3.8.0
Using rspec 3.8.0
Using tins 1.20.2
Using term-ansicolor 1.7.1
Using thor 0.20.3
Using pact-support 1.10.1
Using rack 2.0.7
Using webrick 1.3.1
Using pact-mock_service 3.0.1 from source at `.`
Bundle complete! 12 Gemfile dependencies, 19 gems now installed.
Gems in the group development were not installed.
Bundled gems are installed into `/Users/you54f/dev/saftest/githubrepos/forks/pact-mock_service/build/vendor`
rm -rf build/tmp
rm -f build/vendor/*/*/cache/*
rm -rf pact-mock-service-3.0.1-1-linux-x86
mkdir pact-mock-service-3.0.1-1-linux-x86
mkdir -p pact-mock-service-3.0.1-1-linux-x86/lib/app
mkdir -p pact-mock-service-3.0.1-1-linux-x86/bin
cp packaging/pact-mock-service.rb pact-mock-service-3.0.1-1-linux-x86/lib/app/pact-mock-service.rb
cp -pR lib pact-mock-service-3.0.1-1-linux-x86/lib/app
mkdir pact-mock-service-3.0.1-1-linux-x86/lib/ruby
tar -xzf build/traveling-ruby-20150715-2.2.2-linux-x86.tar.gz -C pact-mock-service-3.0.1-1-linux-x86/lib/ruby
cp packaging/wrapper.sh pact-mock-service-3.0.1-1-linux-x86/bin/pact-mock-service
cp -pR build/vendor pact-mock-service-3.0.1-1-linux-x86/lib/
cp pact-mock-service.gemspec Gemfile Gemfile.lock pact-mock-service-3.0.1-1-linux-x86/lib/vendor/
cp: pact-mock-service.gemspec: No such file or directory
rake aborted!
Command failed with status (1): [cp pact-mock-service.gemspec Gemfile Gemfi...]
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `call'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `sh'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in `sh'
/Users/you54f/dev/saftest/githubrepos/forks/pact-mock_service/tasks/package.rake:87:in `create_package'
/Users/you54f/dev/saftest/githubrepos/forks/pact-mock_service/tasks/package.rake:16:in `block (3 levels) in <top (required)>'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:205:in `block in invoke_prerequisites'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:203:in `each'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:203:in `invoke_prerequisites'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:183:in `block in invoke_with_call_chain'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/you54f/.rvm/gems/ruby-2.2.6/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/you54f/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:24:in `eval'
/Users/you54f/.rvm/gems/ruby-2.2.6/bin/ruby_executable_hooks:24:in `<main>'
Tasks: TOP => package => package:linux:x86
(See full trace by running task with --trace)
bethesque commented 5 years ago

Thank you!