Skip to content

Commit 82babdb

Browse files
authored
Merge pull request #4 from YOU54F/feat/rename-bin-to-pact-mock-server
Feat/rename bin to pact mock server
2 parents a21104c + a48de45 commit 82babdb

23 files changed

Lines changed: 179 additions & 122 deletions

pact_mock_server_cli/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@ expectest = "0.12.0"
5656
trycmd = "0.15.7"
5757
test-log = "0.2.16"
5858
env_logger = "0.11.5"
59+
60+
# create bin and lib entries
61+
[[bin]]
62+
name = "pact-mock-server"
63+
path = "src/bin.rs"
64+
[lib]
65+
name = "pact_mock_server_cli"
66+
path = "src/lib.rs"

pact_mock_server_cli/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ ARG BIN_ARCH=x86_64
44
ARG VERSION=1.0.5
55

66
RUN apk --no-cache add wget
7-
RUN wget -O pact_mock_server_cli.gz https://github.com/pact-foundation/pact-reference/releases/download/pact_mock_server_cli-v${VERSION}/pact_mock_server_cli-linux-${BIN_ARCH}.gz
8-
RUN gunzip pact_mock_server_cli.gz
9-
RUN chmod +x pact_mock_server_cli
7+
RUN wget -O pact-mock-server.gz https://github.com/pact-foundation/pact-reference/releases/download/pact_mock_server_cli-v${VERSION}/pact-mock-server-linux-${BIN_ARCH}.gz
8+
RUN gunzip pact-mock-server.gz
9+
RUN chmod +x pact-mock-server
1010

1111

1212
# Now, we need to build our _real_ Docker container, copying in the executable.
1313
FROM ${ARCH}alpine:3.16
1414
RUN apk --no-cache add ca-certificates
1515
COPY --from=builder \
16-
/pact_mock_server_cli \
16+
/pact-mock-server \
1717
/usr/local/bin/
1818

1919
EXPOSE 8080 9000-9020
2020

21-
ENTRYPOINT ["/usr/local/bin/pact_mock_server_cli"]
21+
ENTRYPOINT ["/usr/local/bin/pact-mock-server"]
2222
CMD ["start", "--base-port", "9000"]

pact_mock_server_cli/README.md

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ restful web api or through the command line interface. It implements the [V4 Pac
88

99
## Command line interface
1010

11-
The mock server is bundles as a single binary executable `pact_mock_server_cli`. Running this with out any options displays
11+
The mock server is bundles as a single binary executable `pact-mock-server`. Running this with out any options displays
1212
the standard help.
1313

1414
```console,ignore
15-
$ ./pact_mock_server_cli --help
16-
./pact_mock_server_cli v1.0.0
15+
$ ./pact-mock-server --help
16+
./pact-mock-server v1.0.0
1717
Standalone Pact mock server
1818
1919
USAGE:
20-
pact_mock_server_cli [FLAGS] [OPTIONS] <SUBCOMMAND>
20+
pact-mock-server [FLAGS] [OPTIONS] <SUBCOMMAND>
2121
2222
FLAGS:
2323
--help Prints help information
@@ -72,10 +72,10 @@ This prints either the main help or the help for a sub-command.
7272
This starts the master mock server. This server needs to be running for the other sub-commands to work.
7373

7474
```console
75-
$ ./pact_mock_server_cli help start
75+
$ ./pact-mock-server help start
7676
Starts the master mock server
7777

78-
Usage: pact_mock_server_cli start [OPTIONS]
78+
Usage: pact-mock-server start [OPTIONS]
7979

8080
Options:
8181
--help Print help and exit
@@ -101,7 +101,7 @@ This sets the output directory that log files and pact files are written to. It
101101
##### Example
102102

103103
```console,ignore
104-
$ ./pact_mock_server_cli start -l debug -o logs/
104+
$ ./pact-mock-server start -l debug -o logs/
105105
15:40:08 [DEBUG] hyper::server: threads = 10
106106
15:40:08 [INFO] pact_mock_server_cli::server: Server started on port 8080
107107
```
@@ -114,22 +114,23 @@ will be displayed.
114114
Note, the tls option will only be available if the tls create feature is enabled.
115115

116116
```console
117-
$ ./pact_mock_server_cli help create
117+
$ ./pact-mock-server help create
118118
Creates a new mock server from a pact file
119119

120-
Usage: pact_mock_server_cli create [OPTIONS] --file <file>
120+
Usage: pact-mock-server create [OPTIONS] --file <file>
121121

122122
Options:
123-
-f, --file <file> the pact file to define the mock server
124-
--help Print help and exit
125-
-c, --cors-preflight Handle CORS pre-flight requests
126-
-v, --version Print version information and exit
127-
-p, --port <port> port the master mock server runs on (defaults to 8080)
128-
--tls Enable TLS with the mock server (will use a self-signed certificate)
129-
-h, --host <host> hostname the master mock server runs on (defaults to localhost)
130-
-l, --loglevel <loglevel> Log level for mock servers to write to the log file (defaults to info) [possible values: error, warn, info, debug, trace, none]
131-
--no-term-log Turns off using terminal ANSI escape codes
132-
--no-file-log Do not log to an output file
123+
-f, --file <file> the pact file to define the mock server
124+
--help Print help and exit
125+
-c, --cors-preflight Handle CORS pre-flight requests
126+
-v, --version Print version information and exit
127+
-p, --port <port> port the master mock server runs on (defaults to 8080)
128+
--specification <specification> The Pact specification version to use (defaults to V4)
129+
-h, --host <host> hostname the master mock server runs on (defaults to localhost)
130+
--tls Enable TLS with the mock server (will use a self-signed certificate)
131+
-l, --loglevel <loglevel> Log level for mock servers to write to the log file (defaults to info) [possible values: error, warn, info, debug, trace, none]
132+
--no-term-log Turns off using terminal ANSI escape codes
133+
--no-file-log Do not log to an output file
133134

134135

135136
```
@@ -143,7 +144,7 @@ This option specifies the pact file to base the mock server on. It is a mandator
143144
##### Example
144145

145146
```console,ignore
146-
$ ./pact_mock_server_cli create -f ../../../libpact_matching/tests/pact.json
147+
$ ./pact-mock-server create -f ../../../libpact_matching/tests/pact.json
147148
15:43:47 [INFO] pact_mock_server_cli::create_mock: Creating mock server from file ../../../libpact_matching/tests/pact.json
148149
Mock server "7d1bf906d0ff42528f2d7d794dd19c5b" started on port 52943
149150
```
@@ -153,10 +154,10 @@ Mock server "7d1bf906d0ff42528f2d7d794dd19c5b" started on port 52943
153154
Lists out all running mock servers with their ID, port, provider name and status.
154155

155156
```console
156-
$ ./pact_mock_server_cli list --help
157+
$ ./pact-mock-server list --help
157158
Lists all the running mock servers
158159

159-
Usage: pact_mock_server_cli list [OPTIONS]
160+
Usage: pact-mock-server list [OPTIONS]
160161

161162
Options:
162163
--help Print help and exit
@@ -173,7 +174,7 @@ Options:
173174
##### Example
174175

175176
```console,ignore
176-
$ ./pact_mock_server_cli list
177+
$ ./pact-mock-server list
177178
Mock Server Id Port Provider Status
178179
7d1bf906d0ff42528f2d7d794dd19c5b 52943 Alice Service error
179180
```
@@ -185,10 +186,10 @@ expectations have been met, the pact file will be written out to the output dire
185186
sub-command. If there is any errors, no pact file will be written and the errors displayed to the console.
186187

187188
```console
188-
$ ./pact_mock_server_cli verify --help
189+
$ ./pact-mock-server verify --help
189190
Verify the mock server by id or port number, and generate a pact file if all ok
190191

191-
Usage: pact_mock_server_cli verify [OPTIONS]
192+
Usage: pact-mock-server verify [OPTIONS]
192193

193194
Options:
194195
--help
@@ -228,7 +229,7 @@ The port number of the mock server to verify. Either this option or the mock ser
228229
In the case of a mock server that has issues:
229230

230231
```console,ignore
231-
$ ./pact_mock_server_cli verify -m 52943
232+
$ ./pact-mock-server verify -m 52943
232233
Mock server 7d1bf906d0ff42528f2d7d794dd19c5b/52943 failed verification with 1 errors
233234
234235
0 - Expected request was not received - {"method":"GET","path":"/mallory","query":"name=ron&status=good"}
@@ -237,7 +238,7 @@ Mock server 7d1bf906d0ff42528f2d7d794dd19c5b/52943 failed verification with 1 er
237238
and for a mock server that has matched all requests:
238239

239240
```console,ignore
240-
$ ./pact_mock_server_cli verify -m 52943
241+
$ ./pact-mock-server verify -m 52943
241242
Mock server 7d1bf906d0ff42528f2d7d794dd19c5b/52943 verified ok
242243
```
243244

@@ -246,10 +247,10 @@ Mock server 7d1bf906d0ff42528f2d7d794dd19c5b/52943 verified ok
246247
Shutdown the mock server by id or port number, releasing all its resources.
247248

248249
```console
249-
$ ./pact_mock_server_cli help shutdown
250+
$ ./pact-mock-server help shutdown
250251
Shutdown the mock server by id or port number, releasing all its resources
251252

252-
Usage: pact_mock_server_cli shutdown [OPTIONS]
253+
Usage: pact-mock-server shutdown [OPTIONS]
253254

254255
Options:
255256
--help
@@ -287,7 +288,7 @@ The port number of the mock server to shutdown. Either this option or the mock s
287288
##### Example
288289

289290
```console,ignore
290-
$ ./pact_mock_server_cli shutdown -i 3a94a472d04849048b78109e288702d0
291+
$ ./pact-mock-server shutdown -i 3a94a472d04849048b78109e288702d0
291292
Mock server with id '3a94a472d04849048b78109e288702d0' shutdown ok
292293
```
293294

pact_mock_server_cli/release-linux.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ build_x86_64() {
1919

2020
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
2121
gzip_and_sum \
22-
"$CARGO_TARGET_DIR/x86_64-unknown-linux-musl/release/pact_mock_server_cli" \
23-
"$ARTIFACTS_DIR/pact_mock_server_cli-linux-x86_64.gz"
22+
"$CARGO_TARGET_DIR/x86_64-unknown-linux-musl/release/pact-mock-server" \
23+
"$ARTIFACTS_DIR/pact-mock-server-linux-x86_64.gz"
2424
fi
2525
}
2626

@@ -34,8 +34,8 @@ build_aarch64() {
3434

3535
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
3636
gzip_and_sum \
37-
"$CARGO_TARGET_DIR/aarch64-unknown-linux-musl/release/pact_mock_server_cli" \
38-
"$ARTIFACTS_DIR/pact_mock_server_cli-linux-aarch64.gz"
37+
"$CARGO_TARGET_DIR/aarch64-unknown-linux-musl/release/pact-mock-server" \
38+
"$ARTIFACTS_DIR/pact-mock-server-linux-aarch64.gz"
3939
fi
4040
}
4141

pact_mock_server_cli/release-macos.sh

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ build_x86_64() {
2222

2323
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
2424
gzip_and_sum \
25-
"$CARGO_TARGET_DIR/x86_64-apple-darwin/release/pact_mock_server_cli" \
26-
"$ARTIFACTS_DIR/pact_mock_server_cli-osx-x86_64.gz"
27-
gzip_and_sum \
28-
"$CARGO_TARGET_DIR/x86_64-apple-darwin/release/pact_mock_server_cli" \
29-
"$ARTIFACTS_DIR/pact_mock_server_cli-macos-x86_64.gz"
25+
"$CARGO_TARGET_DIR/x86_64-apple-darwin/release/pact-mock-server" \
26+
"$ARTIFACTS_DIR/pact-mock-server-macos-x86_64.gz"
3027
fi
3128
}
3229

@@ -36,11 +33,8 @@ build_aarch64() {
3633

3734
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
3835
gzip_and_sum \
39-
"$CARGO_TARGET_DIR/aarch64-apple-darwin/release/pact_mock_server_cli" \
40-
"$ARTIFACTS_DIR/pact_mock_server_cli-osx-aarch64.gz"
41-
gzip_and_sum \
42-
"$CARGO_TARGET_DIR/aarch64-apple-darwin/release/pact_mock_server_cli" \
43-
"$ARTIFACTS_DIR/pact_mock_server_cli-macos-aarch64.gz"
36+
"$CARGO_TARGET_DIR/aarch64-apple-darwin/release/pact-mock-server" \
37+
"$ARTIFACTS_DIR/pact-mock-server-macos-aarch64.gz"
4438
fi
4539
}
4640

pact_mock_server_cli/release-win.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ build_x86_64() {
2020
# If --release in cargo flags, then gzip and sum the release artifacts
2121
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
2222
gzip_and_sum \
23-
"$CARGO_TARGET_DIR/x86_64-pc-windows-msvc/release/pact_mock_server_cli.exe" \
24-
"$ARTIFACTS_DIR/pact_mock_server_cli-windows-x86_64.exe.gz"
23+
"$CARGO_TARGET_DIR/x86_64-pc-windows-msvc/release/pact-mock-server.exe" \
24+
"$ARTIFACTS_DIR/pact-mock-server-windows-x86_64.exe.gz"
2525
fi
2626
}
2727

@@ -31,8 +31,8 @@ build_aarch64() {
3131

3232
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
3333
gzip_and_sum \
34-
"$CARGO_TARGET_DIR/aarch64-pc-windows-msvc/release/pact_mock_server_cli.exe" \
35-
"$ARTIFACTS_DIR/pact_mock_server_cli-windows-aarch64.exe.gz"
34+
"$CARGO_TARGET_DIR/aarch64-pc-windows-msvc/release/pact-mock-server.exe" \
35+
"$ARTIFACTS_DIR/pact-mock-server-windows-aarch64.exe.gz"
3636
fi
3737
}
3838

pact_mock_server_cli/src/bin.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[tokio::main]
2+
async fn main() {
3+
match pact_mock_server_cli::handle_command_args().await {
4+
Ok(_) => (),
5+
Err(err) => std::process::exit(err)
6+
}
7+
}

pact_mock_server_cli/src/create_mock.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ pub async fn create_mock_server(host: &str, port: u16, matches: &ArgMatches, usa
1515

1616
match RequestResponsePact::read_pact(Path::new(file)) {
1717
Ok(ref pact) => {
18-
let mut args = vec![];
18+
let mut args = Vec::<String>::new();
1919
if matches.get_flag("cors") {
2020
info!("Setting mock server to handle CORS pre-flight requests");
21-
args.push("cors=true");
21+
args.push("cors=true".to_string());
22+
}
23+
if let Some(specification) = matches.get_one::<String>("specification") {
24+
info!("Setting mock server to use pact specification {}", specification);
25+
let spec_arg = format!("specification={}", specification);
26+
args.push(spec_arg);
2227
}
2328
if matches.get_flag("tls") {
2429
info!("Setting mock server to use TLS");
25-
args.push("tls=true");
30+
args.push("tls=true".to_string());
2631
}
2732
let url = if args.is_empty() {
2833
format!("http://{}:{}/", host, port)

0 commit comments

Comments
 (0)