Skip to content

Commit

Permalink
chore: update default port 1234 to 8888 for macos arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed May 5, 2023
1 parent 39073d8 commit 858531c
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 58 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ Use the [pact][pact] gem if you would like the full Pact DSL, mock service and v
Otherwise:

$ gem install pact-mock_service
$ pact-mock-service --consumer Foo --provider Bar --port 1234
$ pact-mock-service --consumer Foo --provider Bar --port 8888

Or add `gem "pact-mock_service"` to your Gemfile then run:

$ bundle install
$ bundle exec pact-mock-service --consumer Foo --provider Bar --port 1234
$ bundle exec pact-mock-service --consumer Foo --provider Bar --port 8888

Run `pact-mock-service help` for command line options.

Expand Down Expand Up @@ -84,11 +84,11 @@ You can find more documentation for the mock service in the repository [wiki][wi

If you need to use the mock service with HTTPS, you can use the built-in SSL mode which relies on and generates a self-signed certificate.

$ pact-mock-service --port 1234 --ssl
$ pact-mock-service --port 8888 --ssl

If you need to provide your own certificate and key, use the following syntax.

$ pact-mock-service --port 1234 --ssl --sslcert PATH_TO_CERT --sslkey PATH_TO_KEY
$ pact-mock-service --port 8888 --ssl --sslcert PATH_TO_CERT --sslkey PATH_TO_KEY

### With CORS

Expand Down
12 changes: 6 additions & 6 deletions lib/pact/mock_service/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def control
desc 'start', "Start a mock service. If the consumer, provider and pact-dir options are provided, the pact will be written automatically on shutdown (INT)."
method_option :consumer, desc: "Consumer name"
method_option :provider, desc: "Provider name"
method_option :port, aliases: "-p", default: '1234', desc: "Port on which to run the service"
method_option :port, aliases: "-p", default: '8888', desc: "Port on which to run the service"
method_option :host, aliases: "-h", desc: "Host on which to bind the service", default: 'localhost'
method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written"
method_option :pact_file_write_mode, aliases: "-m", desc: PACT_FILE_WRITE_MODE_DESC, type: :string, default: 'overwrite'
Expand All @@ -76,7 +76,7 @@ def start
end

desc 'stop', "Stop a Pact mock service"
method_option :port, aliases: "-p", desc: "Port of the service to stop", default: '1234', required: true
method_option :port, aliases: "-p", desc: "Port of the service to stop", default: '8888', required: true
method_option :pid_dir, desc: "PID dir, defaults to tmp/pids", default: "tmp/pids"

def stop
Expand All @@ -87,7 +87,7 @@ def stop
desc 'restart', "Start or restart a mock service. If the consumer, provider and pact-dir options are provided, the pact will be written automatically on shutdown (INT)."
method_option :consumer, desc: "Consumer name"
method_option :provider, desc: "Provider name"
method_option :port, aliases: "-p", default: '1234', desc: "Port on which to run the service"
method_option :port, aliases: "-p", default: '8888', desc: "Port on which to run the service"
method_option :host, aliases: "-h", desc: "Host on which to bind the service", default: 'localhost'
method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written"
method_option :pact_file_write_mode, aliases: "-m", desc: PACT_FILE_WRITE_MODE_DESC, type: :string, default: 'overwrite'
Expand All @@ -108,7 +108,7 @@ def restart
end

desc 'control-start', "Start a Pact mock service control server."
method_option :port, aliases: "-p", desc: "Port on which to run the service", default: '1234'
method_option :port, aliases: "-p", desc: "Port on which to run the service", default: '8888'
method_option :host, aliases: "-h", desc: "Host on which to bind the service", default: 'localhost'
method_option :log_dir, aliases: "-l", desc: "File to which to log output", default: "log"
method_option :log_level, desc: "Log level. Options are DEBUG INFO WARN ERROR", default: "DEBUG"
Expand All @@ -129,7 +129,7 @@ def control_start
end

desc 'control-stop', "Stop a Pact mock service control server."
method_option :port, aliases: "-p", desc: "Port of control server to stop", default: "1234"
method_option :port, aliases: "-p", desc: "Port of control server to stop", default: "8888"
method_option :pid_dir, desc: "PID dir, defaults to tmp/pids", default: "tmp/pids"

def control_stop
Expand All @@ -138,7 +138,7 @@ def control_stop
end

desc 'control-restart', "Start a Pact mock service control server."
method_option :port, aliases: "-p", desc: "Port on which to run the service", default: '1234'
method_option :port, aliases: "-p", desc: "Port on which to run the service", default: '8888'
method_option :host, aliases: "-h", desc: "Host on which to bind the service", default: 'localhost'
method_option :log_dir, aliases: "-l", desc: "File to which to log output", default: "log"
method_option :log_level, desc: "Log level. Options are DEBUG INFO WARN ERROR", default: "DEBUG"
Expand Down
8 changes: 4 additions & 4 deletions packaging/RELEASE_NOTES.md.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ To install and run on OSX:
curl -LO https://github.com/bethesque/pact-mock_service/releases/download/<TAG_NAME>/pact-mock-service-<PACKAGE_VERSION>-osx.tar.gz
tar xzf pact-mock-service-<PACKAGE_VERSION>-osx.tar.gz
cd pact-mock-service-<PACKAGE_VERSION>-osx/bin
./pact-mock-service -p 1234
./pact-mock-service -p 8888
```

To install and run on Linux 64 bit:
Expand All @@ -15,7 +15,7 @@ To install and run on Linux 64 bit:
curl -LO https://github.com/bethesque/pact-mock_service/releases/download/<TAG_NAME>/pact-mock-service-<PACKAGE_VERSION>-linux-x86_64.tar.gz
tar xzf pact-mock-service-<PACKAGE_VERSION>-linux-x86_64.tar.gz
cd pact-mock-service-<PACKAGE_VERSION>-linux-x86_64/bin
./pact-mock-service -p 1234
./pact-mock-service -p 8888
```

To install and run on Linux 32 bit:
Expand All @@ -24,13 +24,13 @@ To install and run on Linux 32 bit:
curl -LO https://github.com/bethesque/pact-mock_service/releases/download/<TAG_NAME>/pact-mock-service-<PACKAGE_VERSION>-linux-x86.tar.gz
tar xzf pact-mock-service-<PACKAGE_VERSION>-linux-x86.tar.gz
cd pact-mock-service-<PACKAGE_VERSION>-linux-x86/bin
./pact-mock-service -p 1234
./pact-mock-service -p 8888
```

To install and run on Windows:

Download package, unzip, cd to pact-mock-service-<PACKAGE_VERSION>-win32 and then run:

```
$ .\bin\pact-mock-service.bat -p 1234
$ .\bin\pact-mock-service.bat -p 8888
```
14 changes: 7 additions & 7 deletions script/example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# BEFORE SUITE start mock service
# invoked by the pact framework
bundle exec bin/pact-mock-service service \
--port 1234 \
--port 8888 \
--consumer Foo \
--provider Bar \
--pact-specification-version 2 \
Expand All @@ -14,37 +14,37 @@ pid=$!

# BEFORE SUITE wait for mock service to start up
# invoked by the pact framework
while [ "200" -ne "$(curl -H "X-Pact-Mock-Service: true" -s -o /dev/null -w "%{http_code}" localhost:1234)" ]; do sleep 0.5; done
while [ "200" -ne "$(curl -H "X-Pact-Mock-Service: true" -s -o /dev/null -w "%{http_code}" localhost:8888)" ]; do sleep 0.5; done

# uncomment this line to see the curl commands interleaved with the responses
# set -x

# BEFORE EACH TEST clear interactions from previous test
# invoked by the pact framework
curl -X DELETE -H "X-Pact-Mock-Service: true" localhost:1234/interactions
curl -X DELETE -H "X-Pact-Mock-Service: true" localhost:8888/interactions

# BEFORE A TEST set up interaction(s) just for that test
# The contents of this would be written by the developer in the provided pact DSL for
# your language eg. mockService.given(...).uponReceiving(...). ...
# This can be called mulitple times. Alternatively PUT could be used
# with a body of `{interactions: [...]}` which would negate the need to call DELETE.
curl -X POST -H "X-Pact-Mock-Service: true" -d@script/consumer-interaction.json localhost:1234/interactions
curl -X POST -H "X-Pact-Mock-Service: true" -d@script/consumer-interaction.json localhost:8888/interactions

# IN A TEST execute interaction(s)
# this would be done by the consumer code under test
curl localhost:1234/foo
curl localhost:8888/foo
echo ''

# AFTER EACH TEST verify interaction(s) took place
# This would be done explicitly by the developer or automatically by the framework,
# depending on the language
curl -H "X-Pact-Mock-Service: true" localhost:1234/interactions/verification
curl -H "X-Pact-Mock-Service: true" localhost:8888/interactions/verification

# AFTER SUITE
# write pact
# this would be invoked explictly by the developer or automatically framework,
# depending on the language
curl -X POST -H "X-Pact-Mock-Service: true" -H "Content-Length: 0" localhost:1234/pact
curl -X POST -H "X-Pact-Mock-Service: true" -H "Content-Length: 0" localhost:8888/pact

# AFTER SUITE stop mock service
# this would be invoked by the test framework
Expand Down
6 changes: 3 additions & 3 deletions script/stub_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
# BEFORE SUITE start mock service
# invoked by the pact framework
bundle exec pact-stub-service script/foo-bar.json \
--port 1234 \
--port 8888 \
--log ./tmp/bar_stub_service.log &
pid=$!

# BEFORE SUITE wait for mock service to start up
# invoked by the pact framework
while [ "200" -ne "$(curl -H "X-Pact-Mock-Service: true" -s -o /dev/null -w "%{http_code}" localhost:1234)" ]; do sleep 0.5; done
while [ "200" -ne "$(curl -H "X-Pact-Mock-Service: true" -s -o /dev/null -w "%{http_code}" localhost:8888)" ]; do sleep 0.5; done

# IN A TEST execute interaction(s)
# this would be done by the consumer code under test
curl localhost:1234/foo
curl localhost:8888/foo
echo ''


Expand Down
4 changes: 2 additions & 2 deletions spec/features/administration_endpoints_cors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@

context "when the Origin header is set" do
it "sets the Access-Control-Allow-Origin header to be the Origin" do
options '/pact', nil, { 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'X-Pact-Mock-Service, Content-Type', 'HTTP_ORIGIN' => 'http://localhost:1234' }
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:1234'
options '/pact', nil, { 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'X-Pact-Mock-Service, Content-Type', 'HTTP_ORIGIN' => 'http://localhost:8888' }
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:8888'
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/features/mock_interactions_with_cors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@
expect(last_response.status).to be 200

# OPTIONS request from the browser for the request under test
options '/alligators/new', nil, { 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'accept', 'HTTP_ORIGIN' => 'http://localhost:1234' }
options '/alligators/new', nil, { 'HTTP_ACCESS_CONTROL_REQUEST_HEADERS' => 'accept', 'HTTP_ORIGIN' => 'http://localhost:8888' }

# Ensure it allows the browser to actually make the request
expect(last_response.status).to eq 200
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:1234'
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:8888'
expect(last_response.headers['Access-Control-Allow-Credentials']).to eq 'true'
expect(last_response.headers['Access-Control-Allow-Headers']).to include 'accept'
expect(last_response.headers['Access-Control-Allow-Methods']).to include "DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT"

# Make the request
post "/alligators/new", actual_request, { 'HTTP_ACCEPT' => 'application/json', 'HTTP_ORIGIN' => 'http://localhost:1234' }
post "/alligators/new", actual_request, { 'HTTP_ACCEPT' => 'application/json', 'HTTP_ORIGIN' => 'http://localhost:8888' }

# Ensure that the response we get back was the one we expected
# and includes the CORS header
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:1234'
expect(last_response.headers['Access-Control-Allow-Origin']).to eq 'http://localhost:8888'
expect(last_response.headers['Content-Type']).to eq 'application/json'
expect(JSON.parse(last_response.body)).to eq([{ 'name' => 'Mary' }])
end
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/cli_cors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

before :all do
clear_dirs
@pid = start_server 1234, '--cors'
@pid = start_server 8888, '--cors'
end

it "responds to an OPTIONS request for a non administration request" do
response = make_options_request 1234
response = make_options_request 8888
expect(response.status).to eq 200
expect(response.headers['Access-Control-Allow-Headers']).to_not be nil
end
Expand Down
30 changes: 15 additions & 15 deletions spec/integration/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,51 @@

before :all do
clear_dirs
@pid = start_server 1234, "--pact-specification-version 3.0.0"
@pid = start_server 8888, "--pact-specification-version 3.0.0"
end

it "starts up and responds with mocked responses" do
response = setup_interaction 1234
response = setup_interaction 8888
expect(response.status).to eq 200

response = invoke_expected_request 1234
response = invoke_expected_request 8888
puts response.body if response.status != 200
expect(response.status).to eq 200
expect(response.body).to eq 'Hello world'

write_pact 1234
write_pact 8888
expect(response.status).to eq 200
end

it "respects headers with underscores" do
setup_interaction_with_underscored_header 1234
response = invoke_request_with_underscored_header 1234
setup_interaction_with_underscored_header 8888
response = invoke_request_with_underscored_header 8888
puts response.body unless response.status == 200
expect(response.status).to eq 200
end

it "sets the X-Pact-Mock-Service-Location header" do
response = setup_interaction 1234
expect(response.headers['X-Pact-Mock-Service-Location']).to eq 'http://0.0.0.0:1234'
response = setup_interaction 8888
expect(response.headers['X-Pact-Mock-Service-Location']).to eq 'http://0.0.0.0:8888'
end

it "writes logs to the specified log file" do
expect(File.exist?('tmp/integration.log')).to be true
end

it "writes the pact to the specified directory" do
clear_interactions 1234
setup_interaction 1234
invoke_expected_request 1234
clear_interactions 8888
setup_interaction 8888
invoke_expected_request 8888
expect(File.exist?('tmp/pacts/consumer-provider.json')).to be true
end

it "sets the pact specification version" do
clear_interactions 1234
setup_interaction 1234
invoke_expected_request 1234
clear_interactions 8888
setup_interaction 8888
invoke_expected_request 8888

write_pact 1234
write_pact 8888
expect(File.read("tmp/pacts/consumer-provider.json")).to include "3.0.0"
end

Expand Down
6 changes: 3 additions & 3 deletions spec/integration/control_server_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def mock_service_headers

before :all do
clear_dirs
@pid = start_control 1234, "--pact-specification-version 3"
@pid = start_control 8888, "--pact-specification-version 3"
end

it "starts up and responds with mocked responses" do
response = setup_interaction 1234
response = setup_interaction 8888
puts response.body unless response.status == 200
expect(response.status).to eq 200
mock_service_port = URI(response.headers['X-Pact-Mock-Service-Location']).port
expect(mock_service_port).to_not eq 1234
expect(mock_service_port).to_not eq 8888

response = invoke_expected_request mock_service_port
expect(response.status).to eq 200
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/control_server_with_cors_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

before :all do
clear_dirs
@pid = start_control 1234, '--cors'
@pid = start_control 8888, '--cors'
end

it "responds to an OPTIONS request for a non administration request" do
response = setup_interaction 1234
response = setup_interaction 8888
expect(response.status).to eq 200
mock_service_port = URI(response.headers['X-Pact-Mock-Service-Location']).port

Expand Down
6 changes: 3 additions & 3 deletions spec/integration/control_server_with_ssl_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

before :all do
clear_dirs
@pid = start_control 1234, '--ssl'
@pid = start_control 8888, '--ssl'
end

it "sets the X-Pact-Mock-Service-Location with https" do
response = setup_interaction 1234
response = setup_interaction 8888
expect(response.headers['X-Pact-Mock-Service-Location']).to start_with 'https://localhost:'
end

it "responds to an OPTIONS request for a non administration request" do
response = setup_interaction 1234
response = setup_interaction 8888
expect(response.status).to eq 200
mock_service_port = URI(response.headers['X-Pact-Mock-Service-Location']).port
response = connect_via_ssl mock_service_port
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/pact/mock_service/app_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Pact::MockService
let(:options) { { pact_specification_version: '3' } }

context "for http://localhost" do
let(:url) { 'http://localhost:1234'}
let(:url) { 'http://localhost:8888'}

it "starts a mock service at the given port on localhost" do
expect_any_instance_of(AppRegistration).to receive(:spawn)
Expand All @@ -27,7 +27,7 @@ module Pact::MockService

it "registers the mock service as running on the given port" do
AppManager.instance.register_mock_service_for name, url, options
expect(AppManager.instance.app_registered_on?(1234)).to eq true
expect(AppManager.instance.app_registered_on?(8888)).to eq true
end

it "reports the metric for pact mock service started" do
Expand All @@ -50,7 +50,7 @@ module Pact::MockService
end

context "for https://" do
let(:url) { 'https://localhost:1234'}
let(:url) { 'https://localhost:8888'}

it "should throw an unsupported error" do
expect { AppManager.instance.register_mock_service_for name, url, options }.to raise_error "Currently only http is supported"
Expand Down

0 comments on commit 858531c

Please sign in to comment.