Skip to content
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

Add --dry-run option to launchpad start #69

Merged
merged 10 commits into from
Apr 19, 2024
22 changes: 22 additions & 0 deletions .docker/gs64/docker-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ function assertOutputIncludesMessage() {
fi
}

function assertOutputIsEmpty() {
local output=$1

if [ -s "$output" ];then
print_error "Expected std$output to be empty when invoked with $LAST_ARGUMENTS"
cat "$output"
exit 1
fi
}

set -e

if [ $# -eq 0 ]; then
Expand Down Expand Up @@ -144,13 +154,25 @@ assertOutputIncludesMessage "\[ERROR\] \"Name\" parameter not provided. You must
print_success " Missing name, OK"
run_launchpad_gem launchpad start greeter
assertOutputIncludesMessage "\[ERROR\] \"Name\" parameter not provided. You must provide one." err
print_success " Missing name and title, OK"
gcotelli marked this conversation as resolved.
Show resolved Hide resolved

run_launchpad_gem launchpad start --dry-run greeter --name=Juan --title=Mr
assertOutputIsEmpty err
print_success " Dry run with valid parameters, OK"
run_launchpad_gem launchpad start --dry-run greeter
assertOutputIncludesMessage "\[ERROR\] \"Name\" parameter not provided. You must provide one." err
print_success " Dry run with missing parameters, OK"
print_success "OK"

print_info "Running launchpad start broken test"
run_launchpad_gem launchpad start broken --raise-error
assertOutputIncludesMessage "\[INFO\] Obtaining configuration... \[DONE\]" out
assertOutputIncludesMessage "\[ERROR\] Unexpected startup error: \"Doh!\"" err
print_success "OK"
run_launchpad_gem launchpad start --dry-run broken --raise-error
assertOutputIsEmpty err
assertOutputIncludesMessage "\[INFO\] Obtaining configuration... \[DONE\]" out
print_success "Dry run, OK"

print_info "Stopping stone"
docker stop gs64-stone
Expand Down
21 changes: 21 additions & 0 deletions .docker/pharo/docker-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ function assertOutputIncludesMessage() {
fi
}

function assertOutputIsEmpty() {
local output=$1

if [ -s "$output" ];then
print_error "Expected std$output to be empty when invoked with $LAST_ARGUMENTS"
cat "$output"
exit 1
fi
}

set -e

print_info "Building base image"
Expand Down Expand Up @@ -108,13 +118,24 @@ assertOutputIncludesMessage "\[ERROR\] \"Name\" parameter not provided. You must
print_success " Missing name, OK"
executeWithArguments docker run launchpad-examples:sut launchpad-start greeter
assertOutputIncludesMessage "\[ERROR\] \"Name\" parameter not provided. You must provide one." err
print_success " Missing name and title, OK"
executeWithArguments docker run launchpad-examples:sut launchpad-start --dry-run greeter --name=Juan --title=Mr
assertOutputIsEmpty err
print_success " Dry run with valid parameters, OK"
executeWithArguments docker run launchpad-examples:sut launchpad-start --dry-run greeter
assertOutputIncludesMessage "\[ERROR\] \"Name\" parameter not provided. You must provide one." err
print_success " Dry run with missing parameters, OK"
print_success "OK"

print_info "Running launchpad-start broken test"
executeWithArguments docker run launchpad-examples:sut launchpad-start broken --raise-error
assertOutputIncludesMessage "\[INFO\] Obtaining configuration... \[DONE\]" out
assertOutputIncludesMessage "\[ERROR\] Unexpected startup error: \"Doh!\"" err
print_success "OK"
executeWithArguments docker run launchpad-examples:sut launchpad-start --dry-run broken --raise-error
assertOutputIsEmpty err
assertOutputIncludesMessage "\[INFO\] Obtaining configuration... \[DONE\]" out
print_success "Dry run, OK"

print_info "Running launchpad-start command server test"
# broken app keeps running when passed and invalid option
Expand Down
2 changes: 1 addition & 1 deletion docs/explanation/Application-start-up.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ the logging infrastructure:
`stdout` on Unix); because there's no way to access the `stderr` handle
attached to the VM process.

As a second step, it instantiates a `LaunchpadCommandLineProcessingContext` with
As a second step, it instantiates a `LaunchpadApplicationStartingContext` with
the command-line and a reference to `stdout`. This context is later available
in all the required methods and ultimately accessible by the application in its
`basicStartWithin:` method.
Expand Down
9 changes: 8 additions & 1 deletion docs/reference/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ The `start` sub-command will start the selected application.
launchpad start [--help|-h] [--debug-mode] [--settings-file=<filename>]
[--enable-tcp-command-server=<listeningPort>]
[--enable-structured-logging]
[--dry-run]
<app> [<parameters>]
```

Expand Down Expand Up @@ -247,7 +248,7 @@ $ launchpad start greeter
launchpad-start - Start the selected application
SYNOPSYS
launchpad start [--help|-h] [--debug-mode]
[--settings-file=<filename>] <app> [<parameters>]
[--settings-file=<filename>] [--dry-run] <app> [<parameters>]
DESCRIPTION
Start the application selected via <app>.

Expand All @@ -268,6 +269,10 @@ $ launchpad start greeter
This option can occur several times to configure more
than one settings file. Supported file settings formats
are INI and JSON.
--dry-run
Perform a dry run of the application.
All the configuration will be loaded (and validated),
but the application will not start.
```

- `debug-mode` Enable the debugging mode.
Expand All @@ -290,3 +295,5 @@ $ launchpad start greeter
can be used to send commands controlling the application using a TCP port.
- `--enable-structured-logging` Enable structured logging. When enabled the log
will be emitted in JSON format.
- `--dry-run` Perform a dry run of the application. All the configuration will
be loaded (and validated), but the application will not start.
12 changes: 5 additions & 7 deletions source/Launchpad-Applications/LaunchpadApplication.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,14 @@ LaunchpadApplication >> stackTraceDumper [
LaunchpadApplication >> startWithin: context [

mode
value: [
value: [
commandServer start.
LogRecord emitInfo: self class summary.
self
logConfigurationWithin: context;
basicStartWithin: context
self logConfigurationWithin: context.
context run: [ self basicStartWithin: context ]
]
onErrorDo: [ :error |
LogRecord emitError:
( 'Unexpected startup error: "<1s>"' expandMacrosWith: error messageText ).
onErrorDo: [ :error |
LogRecord emitError: ( 'Unexpected startup error: "<1s>"' expandMacrosWith: error messageText ).
self stackTraceDumper dumpStackTraceFor: error.
self exitFailure
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Extension { #name : #LaunchpadStartApplicationCommand }
Extension { #name : 'LaunchpadStartApplicationCommand' }

{ #category : #'*Launchpad-Commands-Pharo' }
{ #category : '*Launchpad-Commands-Pharo' }
LaunchpadStartApplicationCommand >> enableTCPCommandServerListeningOn: listeningPort [

commandServer := TCPCommandServer listeningOn: listeningPort.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,67 @@
Class {
#name : #LaunchpadTCPCommandServerOption,
#superclass : #LaunchpadOption,
#name : 'LaunchpadTCPCommandServerOption',
#superclass : 'LaunchpadOption',
#instVars : [
'command'
],
#category : #'Launchpad-Commands-Pharo'
#category : 'Launchpad-Commands-Pharo',
#package : 'Launchpad-Commands-Pharo'
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
LaunchpadTCPCommandServerOption class >> for: aCommand [

^ self new initializeFor: aCommand
]

{ #category : #testing }
{ #category : 'testing' }
LaunchpadTCPCommandServerOption class >> isExtendedStartingOption [

^ true
]

{ #category : #testing }
{ #category : 'testing' }
LaunchpadTCPCommandServerOption >> canHandle: argument [

^ argument beginsWith: '--' , self name , '='
]

{ #category : #evaluating }
{ #category : 'evaluating' }
LaunchpadTCPCommandServerOption >> evaluateWithin: context handling: argument [

| listeningPort |

listeningPort := ( argument withoutFirst: self name size + 3 ) asNumber.
command enableTCPCommandServerListeningOn: listeningPort
command enableTCPCommandServerListeningOn: listeningPort.
^ context
]

{ #category : #initialization }
{ #category : 'initialization' }
LaunchpadTCPCommandServerOption >> initializeFor: aCommand [

command := aCommand
]

{ #category : #accessing }
{ #category : 'accessing' }
LaunchpadTCPCommandServerOption >> name [

^ 'enable-tcp-command-server'
]

{ #category : #printing }
{ #category : 'printing' }
LaunchpadTCPCommandServerOption >> printHelpOn: stream [

super printHelpOn: stream.
self printSuffixOn: stream
]

{ #category : #printing }
{ #category : 'printing' }
LaunchpadTCPCommandServerOption >> printSuffixOn: stream [

stream nextPutAll: '=<listeningPort>'
]

{ #category : #accessing }
{ #category : 'accessing' }
LaunchpadTCPCommandServerOption >> summary [

^ 'Enable a TCP command server. This can be used to send commands controlling the application using a TCP port.'
Expand Down
23 changes: 12 additions & 11 deletions source/Launchpad-Commands-Pharo/TCPCommandServer.class.st
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
Class {
#name : #TCPCommandServer,
#superclass : #CommandServer,
#name : 'TCPCommandServer',
#superclass : 'CommandServer',
#instVars : [
'listeningPort',
'commmands',
'connectionSocket',
'serverProcess'
],
#category : #'Launchpad-Commands-Pharo'
#category : 'Launchpad-Commands-Pharo',
#package : 'Launchpad-Commands-Pharo'
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
TCPCommandServer class >> listeningOn: port [

^ self new initializeListeningOn: port
]

{ #category : #private }
{ #category : 'private' }
TCPCommandServer >> initializeConnectionSocket [

connectionSocket := Socket newTCP
]

{ #category : #initialize }
{ #category : 'initialize' }
TCPCommandServer >> initializeListeningOn: port [

listeningPort := port.
commmands := Dictionary new.
self initializeConnectionSocket
]

{ #category : #accessing }
{ #category : 'accessing' }
TCPCommandServer >> listeningPort [

^ listeningPort
]

{ #category : #registering }
{ #category : 'registering' }
TCPCommandServer >> registerCommandNamed: commandName executing: aBlock [

commmands at: commandName put: aBlock
]

{ #category : #private }
{ #category : 'private' }
TCPCommandServer >> serverLoop [

^ [
Expand All @@ -57,7 +58,7 @@ TCPCommandServer >> serverLoop [
] repeat
]

{ #category : #controlling }
{ #category : 'controlling' }
TCPCommandServer >> start [

LogRecord emitInfo:
Expand All @@ -74,7 +75,7 @@ TCPCommandServer >> start [
serverProcess resume
]

{ #category : #controlling }
{ #category : 'controlling' }
TCPCommandServer >> stop [

serverProcess ifNotNil: #terminate.
Expand Down
2 changes: 1 addition & 1 deletion source/Launchpad-Commands-Pharo/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #'Launchpad-Commands-Pharo' }
Package { #name : 'Launchpad-Commands-Pharo' }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"
A LaunchpadApplicationDryRunContextTest is a test class for testing the behavior of LaunchpadApplicationDryRunContext
"
Class {
#name : 'LaunchpadApplicationDryRunContextTest',
#superclass : 'TestCase',
#category : 'Launchpad-Commands-Tests',
#package : 'Launchpad-Commands-Tests'
}

{ #category : 'tests' }
LaunchpadApplicationDryRunContextTest >> testConverting [

| context |

context := LaunchpadApplicationDryRunContext handling: ( CommandLineArguments withArguments: #( ) ).

self assert: context asDryRunContext equals: context
]
Loading
Loading