Skip to content

Commit 9d0dc2c

Browse files
committed
fix tests. ensure i=age details presenter is updated after we modifief the image model.
1 parent 2735941 commit 9d0dc2c

4 files changed

Lines changed: 93 additions & 44 deletions

File tree

src/PharoLauncher-Tests-Commands/PhLLaunchImageCommandTest.class.st

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ Class {
33
#superclass : 'TestCase',
44
#instVars : [
55
'presenter',
6-
'imageDir',
76
'process',
8-
'runCommand',
9-
'image',
10-
'recreateCommand',
11-
'application'
7+
'image'
128
],
139
#category : 'PharoLauncher-Tests-Commands',
1410
#package : 'PharoLauncher-Tests-Commands'
@@ -22,6 +18,7 @@ PhLLaunchImageCommandTest class >> resources [
2218

2319
{ #category : 'helper' }
2420
PhLLaunchImageCommandTest >> addInitializationScriptToImage [
21+
2522
image initializationScript: self initScript
2623
]
2724

@@ -41,7 +38,10 @@ PhLLaunchImageCommandTest >> initScript [
4138
PhLLaunchImageCommandTest >> launchImage [
4239

4340
process ifNotNil: [ self error: 'Currently one execution of image per test case.' ].
44-
process := runCommand execute
41+
42+
process := PhLLaunchImageCommand new
43+
context: presenter;
44+
execute
4545
]
4646

4747
{ #category : 'private' }
@@ -52,7 +52,9 @@ PhLLaunchImageCommandTest >> performTest [
5252

5353
{ #category : 'helper' }
5454
PhLLaunchImageCommandTest >> recreateImage [
55-
recreateCommand execute.
55+
PhLRecreateImageCommand new
56+
context: presenter;
57+
execute.
5658
self selectImage.
5759
^ presenter selectedImages anyOne
5860
]
@@ -64,37 +66,29 @@ PhLLaunchImageCommandTest >> selectImage [
6466
selectImageAt: 1
6567
]
6668

69+
{ #category : 'running' }
70+
PhLLaunchImageCommandTest >> setImageOriginTemplateAndLaunchConfiguration [
71+
image
72+
originTemplate:
73+
(presenter application templateRepository createLocalTemplateNamed: 'testTemplate');
74+
launchConfigurations:
75+
{ (PhLTestLaunchConfiguration withImage: image) }
76+
]
77+
6778
{ #category : 'running' }
6879
PhLLaunchImageCommandTest >> setUp [
6980

7081
super setUp.
7182

7283
presenter := PhLTestImagesPresenter new.
73-
imageDir := FileLocator temp
74-
/ 'pharo-launcher-tests-launch-image-command'
75-
, UUID new asString.
76-
imageDir ensureCreateDirectory.
77-
78-
runCommand := PhLLaunchImageCommand new.
79-
runCommand context: presenter.
80-
recreateCommand := PhLRecreateImageCommand new.
81-
recreateCommand context: presenter.
82-
8384
image := presenter singleImage.
84-
image versionFile writeStreamDo: [ :stream |
85-
SystemVersion current major asString putOn: stream.
86-
SystemVersion current minor asString putOn: stream ].
87-
image
88-
originTemplate:
89-
(presenter application templateRepository createLocalTemplateNamed: 'testTemplate');
90-
launchConfigurations:
91-
{ (PhLTestLaunchConfiguration withImage: image) }
85+
self setImageOriginTemplateAndLaunchConfiguration.
86+
presenter updateImageDetails.
9287
]
9388

9489
{ #category : 'running' }
9590
PhLLaunchImageCommandTest >> tearDown [
9691

97-
imageDir ifNotNil: [ imageDir ensureDeleteAll ].
9892
(process isNotNil and: [ process isRunning ])
9993
ifTrue: [ process terminate ].
10094
super tearDown
@@ -121,13 +115,13 @@ PhLLaunchImageCommandTest >> testCanLaunchImage [
121115
self timeLimit: 30 seconds.
122116

123117
self useNewStableImageAndSetItAsSelectedImageInImagesPresenter.
124-
image addLaunchConfiguration:
125-
(image defaultLaunchConfiguration asLaunchConfiguration
118+
image launchConfigurations:
119+
{ image defaultLaunchConfiguration asLaunchConfiguration
126120
vmArguments: #('--headless'); "be able to run test without X session"
127121
imageArguments: #('--no-quit');
128-
yourself).
122+
yourself }.
129123

130-
process := runCommand execute.
124+
self launchImage.
131125
2 seconds wait. "let time to the image to be opened by the VM"
132126

133127
self assert: process isRunning.
@@ -136,8 +130,8 @@ PhLLaunchImageCommandTest >> testCanLaunchImage [
136130
{ #category : 'tests' }
137131
PhLLaunchImageCommandTest >> testExecutingImageWithScriptShouldSetFlagToShouldNotRun [
138132

139-
self useNewStableImageAndSetItAsSelectedImageInImagesPresenter.
140133
self addInitializationScriptToImage.
134+
presenter selectLaunchConfiguration: image launchConfigurations first.
141135
self launchImage.
142136

143137
self denyApplicationHasError.
@@ -148,9 +142,6 @@ PhLLaunchImageCommandTest >> testExecutingImageWithScriptShouldSetFlagToShouldNo
148142
PhLLaunchImageCommandTest >> testLaunchImageShouldRaiseExceptionWhenNoPharoVersionFile [
149143

150144
image versionFile ensureDelete.
151-
presenter
152-
unselectAll;
153-
selection: { image }.
154145

155146
self
156147
should: [ image launch ]
@@ -161,7 +152,9 @@ PhLLaunchImageCommandTest >> testLaunchImageShouldRaiseExceptionWhenNoPharoVersi
161152
PhLLaunchImageCommandTest >> testRecreateAnImageWithoutOpeningItShouldStillExecuteScript [
162153

163154
| recreatedImage |
155+
164156
self addInitializationScriptToImage.
157+
165158
recreatedImage := self recreateImage.
166159

167160
self assert: recreatedImage shouldRunInitializationScript.
@@ -171,15 +164,36 @@ PhLLaunchImageCommandTest >> testRecreateAnImageWithoutOpeningItShouldStillExecu
171164
PhLLaunchImageCommandTest >> testRecreateAnOpenedImageShouldStillExecuteScript [
172165

173166
| recreatedImage |
167+
174168
self addInitializationScriptToImage.
175169
self launchImage.
176170
recreatedImage := self recreateImage.
177-
171+
178172
self assert: recreatedImage shouldRunInitializationScript
179173
]
180174

181175
{ #category : 'tests' }
182-
PhLLaunchImageCommandTest >> testRunningAnImageRemovesTheInitializationScript [
176+
PhLLaunchImageCommandTest >> testRecreatingAnImageKeepsTheInitializationScript [
177+
178+
self addInitializationScriptToImage.
179+
180+
image := self recreateImage.
181+
182+
self assert: image initializationScript path equals: self initScript path
183+
]
184+
185+
{ #category : 'tests' }
186+
PhLLaunchImageCommandTest >> testRecreatingAnImageKeepsTheInitializationScriptOk [
187+
188+
image := PhLPharoStableImageResource current newRepositoryWithImage.
189+
image
190+
originTemplate:
191+
(presenter application templateRepository createLocalTemplateNamed: 'testTemplate').
192+
presenter model: (PhLDirectoryBasedImageRepository forDirectory: image file parent parent).
193+
presenter refresh.
194+
presenter selectImage: image.
195+
image := presenter selectedImages first.
196+
183197
self addInitializationScriptToImage.
184198
image := self recreateImage.
185199

src/PharoLauncher-Tests-Commands/PhLTestImagesPresenter.class.st

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"
2-
A presenter for Pharo Launcher images used for test purposes
2+
A presenter for Pharo Launcher images used for test purposes.
3+
4+
When you instantiate me, I set a PhLTestApplication that uses a PhLTestImageRepository (memory file system backed).
5+
I also create a default image named `self singleImageName`
36
"
47
Class {
58
#name : 'PhLTestImagesPresenter',
@@ -99,6 +102,18 @@ PhLTestImagesPresenter >> requestAnswer: answer [
99102
request answer: answer
100103
]
101104

105+
{ #category : 'selection' }
106+
PhLTestImagesPresenter >> selectLaunchConfiguration: aLaunchConfiguration [
107+
108+
^ descriptionPanel selectLaunchConfiguration: aLaunchConfiguration
109+
]
110+
111+
{ #category : 'api - selection' }
112+
PhLTestImagesPresenter >> selectSingleImage [
113+
114+
self selectImageAt: 1
115+
]
116+
102117
{ #category : 'configuring' }
103118
PhLTestImagesPresenter >> selection: aListOfImages [
104119
selection := aListOfImages
@@ -119,11 +134,6 @@ PhLTestImagesPresenter >> singleImageName [
119134
^ self model singleImageName
120135
]
121136

122-
{ #category : 'api - accessing' }
123-
PhLTestImagesPresenter >> templateRepository [
124-
^ application templateRepository
125-
]
126-
127137
{ #category : 'api - selection' }
128138
PhLTestImagesPresenter >> unselectAll [
129139
imageTable unselectAll.

src/PharoLauncher-Tests-Commands/PhLTestLaunchConfiguration.class.st

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Class {
99
#package : 'PharoLauncher-Tests-Commands'
1010
}
1111

12+
{ #category : 'testing' }
13+
PhLTestLaunchConfiguration >> canBeLaunched [
14+
15+
^ true
16+
]
17+
1218
{ #category : 'querying' }
1319
PhLTestLaunchConfiguration >> command [
1420
"dummy call, only requirement is that the command is available on supported Operating Systems."

src/PharoLauncher-Tests-Core/PhLPharoStableImageResource.class.st

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,33 @@ PhLPharoStableImageResource >> imageZipFile [
6161
{ #category : 'running' }
6262
PhLPharoStableImageResource >> newImage [
6363

64-
| imageDir imageFile |
65-
imageDir := self workingDir / (UUID new asString).
64+
^ self newImageIn: self workingDir / (UUID new asString)
65+
]
66+
67+
{ #category : 'running' }
68+
PhLPharoStableImageResource >> newImageIn: imageDir [
69+
70+
| imageFile |
6671
self copyImageTo: imageDir.
6772
imageFile := (imageDir childrenMatching: '*.image') first.
6873

6974
^ PhLImage location: imageFile
7075
]
7176

77+
{ #category : 'running' }
78+
PhLPharoStableImageResource >> newRepositoryWithImage [
79+
80+
| repositoryDir imageDir newImage |
81+
repositoryDir := self workingDir / (UUID new asString).
82+
repositoryDir ensureCreateDirectory.
83+
imageDir := repositoryDir / 'temp'.
84+
85+
newImage := self newImageIn: imageDir.
86+
imageDir renameTo: newImage name.
87+
newImage setLocation: repositoryDir / newImage name / (newImage name, '.image').
88+
^ newImage
89+
]
90+
7291
{ #category : 'running' }
7392
PhLPharoStableImageResource >> setUp [
7493

0 commit comments

Comments
 (0)