@@ -8,12 +8,11 @@ Describe Get-KubePod {
8
8
9
9
It ' Should return the pods that exist in a namespace' {
10
10
$pods = Get-KubePod - Namespace pskubectltest
11
- $pods.Count | Should -Not - BeNullOrEmpty
11
+ $pods | Should -Not - BeNullOrEmpty
12
12
$pods | ForEach-Object {
13
13
$_ | Should - BeOfType KubeClient.Models.PodV1
14
14
$_.Name | Should - BeLike ' hello-world-*'
15
15
$_.Namespace | Should - Be ' pskubectltest'
16
- $_.Status.Phase | Should - Be ' Running'
17
16
}
18
17
}
19
18
}
@@ -92,6 +91,12 @@ Describe Get-KubeResource {
92
91
$_.Status.Phase | Should - Be ' Running'
93
92
}
94
93
}
94
+
95
+ It ' Should return deployment by name' {
96
+ $deploy = Get-KubeResource Deployment - Namespace pskubectltest - Name hello- world
97
+ $deploy | Should - HaveCount 1
98
+ $deploy.Metadata.Name | Should - Be ' hello-world'
99
+ }
95
100
}
96
101
97
102
@@ -101,12 +106,12 @@ Describe Get-KubeDeployment {
101
106
102
107
It ' Should return the deployments that exist in a namespace' {
103
108
$deploy = Get-KubeDeployment - Namespace pskubectltest
104
- $deploy | Should - HaveCount 1
109
+ $deploy | Should -Not - BeNullOrEmpty
105
110
$deploy | Should - BeOfType KubeClient.Models.DeploymentV1
106
- $deploy.Name | Should - Be ' hello-world'
107
- $deploy .Namespace | Should - Be ' pskubectltest '
108
- $deploy .Desired | Should - Be 2
109
- $deploy .Current | Should - Be 2
111
+ $helloWorld = $ deploy | Where-Object { $_ .Name -eq ' hello-world' }
112
+ $helloWorld | Should -Not - BeNullOrEmpty
113
+ $helloWorld .Name | Should - Be ' hello-world '
114
+ $helloWorld .Namespace | Should - Be ' pskubectltest '
110
115
}
111
116
}
112
117
@@ -135,7 +140,7 @@ Describe Publish-KubeResource {
135
140
}
136
141
137
142
It ' Should update the resource from PSCustomObject pipeline input' {
138
- $before = (Invoke-Executable { kubectl get deploy - n pskubectltest - o json } | ConvertFrom-Json ).Items
143
+ $before = (Invoke-Executable { kubectl get deploy hello - world - n pskubectltest - o json } | ConvertFrom-Json )
139
144
$before.Metadata.Annotations.hello | Should - Be ' world'
140
145
$modified = [PSCustomObject ]@ {
141
146
Kind = ' Deployment'
@@ -182,18 +187,31 @@ Describe Publish-KubeResource {
182
187
$result | Should -Not - BeNullOrEmpty
183
188
$result | Should - BeOfType KubeClient.Models.DeploymentV1
184
189
$result.Metadata.Annotations [' hello' ] | Should - Be ' changed'
185
- $after = (Invoke-Executable { kubectl get deploy - n pskubectltest - o json } | ConvertFrom-Json ).Items
190
+ $after = (Invoke-Executable { kubectl get deploy hello- world - n pskubectltest - o json } | ConvertFrom-Json )
191
+ $after.Metadata.Annotations.hello | Should - Be ' changed'
192
+ }
193
+
194
+ It - Skip ' Should update the resource from modified Get-KubeResource pipeline input' {
195
+ $before = (Invoke-Executable { kubectl get deploy hello- world - n pskubectltest - o json } | ConvertFrom-Json )
196
+ $before.Metadata.Annotations.hello | Should - Be ' world'
197
+ $modified = Get-KubeResource - Kind Deployment - Namespace pskubectltest - Name hello- world
198
+ $modified.Metadata.Annotations [' hello' ] = ' changed'
199
+ $result = $modified | Publish-KubeResource
200
+ $result | Should -Not - BeNullOrEmpty
201
+ $result | Should - BeOfType KubeClient.Models.DeploymentV1
202
+ $result.Metadata.Annotations [' hello' ] | Should - Be ' changed'
203
+ $after = (Invoke-Executable { kubectl get deploy hello- world - n pskubectltest - o json } | ConvertFrom-Json )
186
204
$after.Metadata.Annotations.hello | Should - Be ' changed'
187
205
}
188
206
189
207
It ' Should update the resource from a path to a YAML file' {
190
- $before = (Invoke-Executable { kubectl get deploy - n pskubectltest - o json } | ConvertFrom-Json ).Items
208
+ $before = (Invoke-Executable { kubectl get deploy hello - world - n pskubectltest - o json } | ConvertFrom-Json )
191
209
$before.Metadata.Annotations.hello | Should - Be ' world'
192
210
$result = Publish-KubeResource - Path $PSScriptRoot / modified.Deployment.yml
193
211
$result | Should -Not - BeNullOrEmpty
194
212
$result | Should - BeOfType KubeClient.Models.DeploymentV1
195
213
$result.Metadata.Annotations [' hello' ] | Should - Be ' changed'
196
- $after = (Invoke-Executable { kubectl get deploy - n pskubectltest - o json } | ConvertFrom-Json ).Items
214
+ $after = (Invoke-Executable { kubectl get deploy hello - world - n pskubectltest - o json } | ConvertFrom-Json )
197
215
$after.Metadata.Annotations.hello | Should - Be ' changed'
198
216
}
199
217
}
@@ -212,15 +230,15 @@ Describe Publish-KubeResource {
212
230
Invoke-Executable { kubectl create -f $PSScriptRoot / test.Deployment.yml }
213
231
Invoke-Executable { kubectl rollout status -- namespace pskubectltest deploy/ hello- world } | Out-Stream - SuccessTarget 6
214
232
215
- $before = (Invoke-Executable { kubectl get deploy - n pskubectltest - o json } | ConvertFrom-Json ).Items
233
+ $before = (Invoke-Executable { kubectl get deploy hello - world - n pskubectltest - o json } | ConvertFrom-Json )
216
234
$before.Metadata.Annotations.hello | Should - Be ' world'
217
235
218
236
$result = Publish-KubeResource - Path $PSScriptRoot / modified.Deployment.yml - Force
219
237
$result | Should -Not - BeNullOrEmpty
220
238
$result | Should - BeOfType KubeClient.Models.DeploymentV1
221
239
$result.Metadata.Annotations.hello | Should - Be ' changed'
222
240
223
- $after = (Invoke-Executable { kubectl get deploy - n pskubectltest - o json } | ConvertFrom-Json ).Items
241
+ $after = (Invoke-Executable { kubectl get deploy hello - world - n pskubectltest - o json } | ConvertFrom-Json )
224
242
$after.Metadata.Annotations.hello | Should - Be ' changed'
225
243
}
226
244
}
@@ -235,7 +253,7 @@ Describe Publish-KubeResource {
235
253
$result | Should -Not - BeNullOrEmpty
236
254
$result | Should - BeOfType KubeClient.Models.DeploymentV1
237
255
238
- $after = (Invoke-Executable { kubectl get deploy - n pskubectltest - o json } | ConvertFrom-Json ).Items
256
+ $after = (Invoke-Executable { kubectl get deploy - n pskubectltest - o json hello - world } | ConvertFrom-Json )
239
257
$after.metadata.name | Should - Be ' hello-world'
240
258
$after.metadata.annotations.hello | Should - Be ' world'
241
259
$after.spec.selector.matchLabels.app | Should - Be ' hello-world'
@@ -250,6 +268,26 @@ Describe Publish-KubeResource {
250
268
}
251
269
}
252
270
271
+ Describe Get-KubeResourceKinds {
272
+ It ' Should return resource kinds' {
273
+ $kinds = Get-KubeResourceKinds | ForEach-Object Kind
274
+ $kinds | Should - Contain ' Deployment'
275
+ $kinds | Should - Contain ' Pod'
276
+ }
277
+ }
278
+
279
+ Describe Get-KubeLog {
280
+ BeforeEach {
281
+ Initialize-TestNamespace
282
+ Initialize-TestDeployment
283
+ }
284
+
285
+ It ' Should return the logs of a given pod' {
286
+ $logs = Get-KubeResource Pod - Namespace pskubectltest - Name hello- world- log-* | Get-KubeLog
287
+ $logs -split " `n " | Should - Contain ' Hello from Docker!'
288
+ }
289
+ }
290
+
253
291
Describe Get-KubeConfig {
254
292
255
293
It ' Should return kube configuration' {
@@ -260,3 +298,55 @@ Describe Get-KubeConfig {
260
298
$config.Contexts | Should -Not - BeNullOrEmpty
261
299
}
262
300
}
301
+
302
+ Describe Convert-KubeYaml {
303
+ It ' Should read in YAML' {
304
+ $parsed = Get-Content - Raw $PSScriptRoot / test.Deployment.yml | ConvertFrom-KubeYaml
305
+ $parsed.PSObject.TypeNames | Should - Contain ' KubeClient.Models.DeploymentV1'
306
+ $parsed.Metadata.Name | Should - Be ' hello-world'
307
+ $parsed.Spec.Replicas | Should - Be 2
308
+ }
309
+ It ' Should round-trip' {
310
+ $yaml = Get-Content - Raw $PSScriptRoot / test.Deployment.yml
311
+ $yaml | ConvertFrom-KubeYaml | ConvertTo-KubeYaml | Should - Be $yaml
312
+ }
313
+ }
314
+
315
+ Describe ConvertTo-KubeYaml {
316
+ BeforeAll {
317
+ Initialize-TestNamespace
318
+ Initialize-TestDeployment
319
+ }
320
+
321
+ It ' Should encode PSCustomObjects' {
322
+ $deploy = [PSCustomObject ]@ {
323
+ Kind = ' Deployment'
324
+ ApiVersion = ' apps/v1'
325
+ Metadata = [PSCustomObject ]@ {
326
+ Name = ' hello-world'
327
+ Namespace = ' pskubectltest'
328
+ Annotations = @ {
329
+ ' hello' = ' changed'
330
+ }
331
+ }
332
+ }
333
+ $yaml = @ (
334
+ ' kind: Deployment' ,
335
+ ' apiVersion: apps/v1' ,
336
+ ' metadata:' ,
337
+ ' name: hello-world' ,
338
+ ' namespace: pskubectltest' ,
339
+ ' annotations:' ,
340
+ ' hello: changed' ,
341
+ ' '
342
+ ) -join " `n "
343
+ $deploy | ConvertTo-KubeYaml | Should - Be $yaml
344
+ }
345
+
346
+ It ' Should encode Get-KubeResource output to YAML' {
347
+ $parsed = Get-KubeResource - Kind Deployment - Namespace pskubectltest - Name hello- world | ConvertTo-KubeYaml | ConvertFrom-KubeYaml
348
+ $parsed.Metadata.Name | Should - Be ' hello-world'
349
+ $parsed.Spec.Replicas | Should - Be 2
350
+ $parsed.Status.Replicas | Should - Be 2
351
+ }
352
+ }
0 commit comments