-
Notifications
You must be signed in to change notification settings - Fork 46
/
PhLImageCreateCliCommandTest.class.st
188 lines (140 loc) · 7.16 KB
/
PhLImageCreateCliCommandTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
Class {
#name : #PhLImageCreateCliCommandTest,
#superclass : #PhLImageCliCommandTest,
#category : #'PharoLauncher-CLI-Tests'
}
{ #category : #utility }
PhLImageCreateCliCommandTest >> addLocalTemplateNamed: aName [
^ self launcherModel templateRepository createLocalTemplateNamed: aName
]
{ #category : #accessing }
PhLImageCreateCliCommandTest >> localTemplatesGroup [
^ context templateRepository localTemplatesGroup
]
{ #category : #running }
PhLImageCreateCliCommandTest >> setUp [
super setUp.
self launcherModel
templateRepository: PhLTemplateTestRepository new
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testCreateImageShouldSucceed [
self addImageNamed: 'myImage1'.
self addImageNamed: 'myImage2'.
self addLocalTemplateNamed: 'fakeTemplate'.
self runCommand: {'launcher' . 'image' . 'create' . 'myImage3' . '--templateName'. 'fakeTemplate' . '--templateCategory' . self templateRepository localTemplatesGroupName}.
self assertSuccess.
self assert: self imageRepository imagesName equals: #( 'myImage1' 'myImage3' 'myImage2' ) asSet.
self assert: (self imageRepository imageNamed: 'myimage3') isLaunched
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testCreateImageWithDevFlagUsesDevImage [
| template devTemplate |
self addTemplateCategoryNamed: self defaultTemplateCategoryName.
self addTemplateNamed: 'Pharo 9 64bit stable' inCategory: self defaultTemplateCategoryName.
devTemplate := self addTemplateNamed: 'Pharo 10 64bit (development version, latest)' inCategory: self defaultTemplateCategoryName.
context arguments: #('launcher' 'image' 'create' '--dev' 'myImage').
template := context command findTemplate.
self assert: template equals: devTemplate
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testCreateImageWithNoFlagUsesDefaultImage [
| template stableTemplate |
self addTemplateCategoryNamed: self defaultTemplateCategoryName.
stableTemplate := self addTemplateNamed: 'Pharo 9 64bit stable' inCategory: self defaultTemplateCategoryName.
self addTemplateNamed: 'Pharo 10 64bit (development version)' inCategory: self defaultTemplateCategoryName.
context arguments: {'launcher' . 'image' . 'create' . 'myImage'}.
template := context command findTemplate.
self assert: template equals: stableTemplate
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testCreateImageWithNoFlagUsesUserDefaultImageWhenSpecified [
| template devTemplate |
context pharoLauncherModel configuration:
(context pharoLauncherModel configuration
defaultTemplate: #dev;
yourself).
self addTemplateCategoryNamed: self defaultTemplateCategoryName.
self addTemplateNamed: 'Pharo 9 64bit stable' inCategory: self defaultTemplateCategoryName.
devTemplate := self addTemplateNamed: 'Pharo 10 64bit (development version, latest)' inCategory: self defaultTemplateCategoryName.
context arguments: {'launcher' . 'image' . 'create' . 'myImage'}.
template := context command findTemplate.
self assert: template equals: devTemplate
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testCreateImageWithNoLaunchFlagShouldNotLaunchImage [
self addLocalTemplateNamed: 'fakeTemplate'.
self runCommand: {'launcher' . 'image' . 'create' . 'myImage' . '--no-launch' . '--templateName'. 'fakeTemplate' . '--templateCategory' . self templateRepository localTemplatesGroupName}.
self assertSuccess.
self deny: (self imageRepository imageNamed: 'myimage') isLaunched
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testCreateImageWithTooManyArgumentShouldRaiseError [
self addImageNamed: 'myImage1'.
self addImageNamed: 'myImage2'.
self addTemplateCategoryNamed: self defaultTemplateCategoryName.
self addTemplateNamed: 'fakeTemplate' inCategory: self defaultTemplateCategoryName.
self addTemplateNamed: 'Pharo 9 64bit stable' inCategory: self defaultTemplateCategoryName.
self runCommand: {'launcher' . 'image' . 'create' . 'myImage3' . 'templateName' . 'tooManyArguments'}.
self assertFailure.
"standard err stream should include error message for trailing unknown argument."
self assert: (self errorString includesSubstring: 'tooManyArguments').
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testCreateImageWithWrongTemplateNameShouldGiveErrorMessage [
self addImageNamed: 'myImage1'.
self addImageNamed: 'myImage2'.
self addTemplateCategoryNamed: self defaultTemplateCategoryName.
self runCommand: #('launcher' 'image' 'create' 'myImage3' '--templateName' 'aRandomTemplateName').
self assertFailure.
"standard err stream should include error message for unknown template."
self assert: (self errorString includesSubstring: 'aRandomTemplateName not found')
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testCreateImageWithoutImageNameShouldGiveError [
self runCommand: {'launcher' . 'image' . 'create' }.
self assertFailure.
"standard err stream should include error message for missing image name."
self assert: (self errorString includesSubstring: 'specify the name for the new Pharo image')
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testCreateImageWithoutTemplateArgumentShouldSucceed [
self addImageNamed: 'myImage1'.
self addImageNamed: 'myImage2'.
self addTemplateCategoryNamed: self defaultTemplateCategoryName.
self addTemplateNamed: 'fakeTemplate' inCategory: self defaultTemplateCategoryName.
self addTemplateNamed: 'Pharo 9 64bit stable' inCategory: self defaultTemplateCategoryName.
self runCommand: {'launcher' . 'image' . 'create' . 'myImage3' }.
self assertSuccess.
self assert: self imageRepository imagesName equals: #( 'myImage1' 'myImage3' 'myImage2' ) asSet.
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testCreateImageWrongCategoryNameShouldRaiseError [
self addImageNamed: 'myImage1'.
self addImageNamed: 'myImage2'.
self addLocalTemplateNamed: 'fakeTemplate'.
self runCommand: {'launcher' . 'image' . 'create' . 'myImage3' . '--templateName'. 'fakeTemplate' . '--templateCategory' . 'wrong category name'}.
self assertFailure.
self assert: (self errorString includesSubstring: 'wrong category name not found').
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testTemplateCanBeFoundByShortName [
| createdTemplate foundTemplate |
self addTemplateCategoryNamed: self defaultTemplateCategoryName.
createdTemplate := self addTemplateNamed: 'fakeTemplate' shortName: 'foo' inCategory: self defaultTemplateCategoryName.
context arguments: {'launcher' . 'image' . 'create' . 'myImage3' . '--templateName'. 'foo' }.
context match.
foundTemplate := context command findUserTemplate.
self assert: foundTemplate equals: createdTemplate
]
{ #category : #tests }
PhLImageCreateCliCommandTest >> testTemplateIsFirstSearchByName [
| createdTemplate foundTemplate |
self addTemplateCategoryNamed: self defaultTemplateCategoryName.
createdTemplate := self addTemplateNamed: 'fakeTemplate' shortName: 'foo' inCategory: self defaultTemplateCategoryName.
self addTemplateNamed: 'foo' inCategory: self defaultTemplateCategoryName.
context arguments: {'launcher' . 'image' . 'create' . 'myImage3' . '--templateName'. 'fakeTemplate' }.
context match.
foundTemplate := context command findUserTemplate.
self assert: foundTemplate equals: createdTemplate
]