github.com/redhat-appstudio/release-service@v0.0.0-20240507045911-a8558ef3422a/api/v1alpha1/release_types_test.go (about) 1 /* 2 Copyright 2023. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1alpha1 18 19 import ( 20 "time" 21 22 "github.com/konflux-ci/operator-toolkit/conditions" 23 . "github.com/onsi/ginkgo/v2" 24 . "github.com/onsi/gomega" 25 . "github.com/onsi/gomega/gstruct" 26 27 "k8s.io/apimachinery/pkg/api/meta" 28 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 29 ) 30 31 var _ = Describe("Release type", func() { 32 33 When("HasEveryPostActionExecutionFinished method is called", func() { 34 var release *Release 35 36 BeforeEach(func() { 37 release = &Release{} 38 }) 39 40 It("should return false when the post-actions executed condition is missing", func() { 41 Expect(release.HasEveryPostActionExecutionFinished()).To(BeFalse()) 42 }) 43 44 It("should return true when the post-actions executed condition status is True", func() { 45 conditions.SetCondition(&release.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionTrue, SucceededReason) 46 Expect(release.HasEveryPostActionExecutionFinished()).To(BeTrue()) 47 }) 48 49 It("should return false when the post-actions executed condition status is False and the reason is Progressing", func() { 50 conditions.SetCondition(&release.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionFalse, ProgressingReason) 51 Expect(release.HasEveryPostActionExecutionFinished()).To(BeFalse()) 52 }) 53 54 It("should return true when the post-actions executed condition status is False and the reason is not Progressing", func() { 55 conditions.SetCondition(&release.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionFalse, FailedReason) 56 Expect(release.HasEveryPostActionExecutionFinished()).To(BeTrue()) 57 }) 58 59 It("should return false when the post-actions executed condition status is Unknown", func() { 60 conditions.SetCondition(&release.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionUnknown, ProgressingReason) 61 Expect(release.HasEveryPostActionExecutionFinished()).To(BeFalse()) 62 }) 63 }) 64 65 When("HasProcessingFinished method is called", func() { 66 var release *Release 67 68 BeforeEach(func() { 69 release = &Release{} 70 }) 71 72 It("should return false when the deployed condition is missing", func() { 73 Expect(release.HasProcessingFinished()).To(BeFalse()) 74 }) 75 76 It("should return true when the processed condition status is True", func() { 77 conditions.SetCondition(&release.Status.Conditions, processedConditionType, metav1.ConditionTrue, SucceededReason) 78 Expect(release.HasProcessingFinished()).To(BeTrue()) 79 }) 80 81 It("should return false when the processed condition status is False and the reason is Progressing", func() { 82 conditions.SetCondition(&release.Status.Conditions, processedConditionType, metav1.ConditionFalse, ProgressingReason) 83 Expect(release.HasProcessingFinished()).To(BeFalse()) 84 }) 85 86 It("should return true when the processed condition status is False and the reason is not Progressing", func() { 87 conditions.SetCondition(&release.Status.Conditions, processedConditionType, metav1.ConditionFalse, FailedReason) 88 Expect(release.HasProcessingFinished()).To(BeTrue()) 89 }) 90 91 It("should return false when the processed condition status is Unknown", func() { 92 conditions.SetCondition(&release.Status.Conditions, processedConditionType, metav1.ConditionUnknown, ProgressingReason) 93 Expect(release.HasProcessingFinished()).To(BeFalse()) 94 }) 95 }) 96 97 When("HasReleaseFinished method is called", func() { 98 var release *Release 99 100 BeforeEach(func() { 101 release = &Release{} 102 }) 103 104 It("should return false when the released condition is missing", func() { 105 Expect(release.HasReleaseFinished()).To(BeFalse()) 106 }) 107 108 It("should return true when the released condition status is True", func() { 109 conditions.SetCondition(&release.Status.Conditions, releasedConditionType, metav1.ConditionTrue, SucceededReason) 110 Expect(release.HasReleaseFinished()).To(BeTrue()) 111 }) 112 113 It("should return false when the released condition status is False and the reason is Progressing", func() { 114 conditions.SetCondition(&release.Status.Conditions, releasedConditionType, metav1.ConditionFalse, ProgressingReason) 115 Expect(release.HasReleaseFinished()).To(BeFalse()) 116 }) 117 118 It("should return true when the released condition status is False and the reason is not Progressing", func() { 119 conditions.SetCondition(&release.Status.Conditions, releasedConditionType, metav1.ConditionFalse, FailedReason) 120 Expect(release.HasReleaseFinished()).To(BeTrue()) 121 }) 122 123 It("should return false when the released condition status is Unknown", func() { 124 conditions.SetCondition(&release.Status.Conditions, deployedConditionType, metav1.ConditionUnknown, ProgressingReason) 125 Expect(release.HasReleaseFinished()).To(BeFalse()) 126 }) 127 }) 128 129 When("IsAttributed method is called", func() { 130 var release *Release 131 132 BeforeEach(func() { 133 release = &Release{} 134 }) 135 136 It("should return true when there is an author in the release status", func() { 137 release.Status.Attribution.Author = "user" 138 Expect(release.IsAttributed()).To(BeTrue()) 139 }) 140 141 It("should return false when there is no author in the release status", func() { 142 Expect(release.IsAttributed()).To(BeFalse()) 143 }) 144 }) 145 146 When("IsAutomated method is called", func() { 147 var release *Release 148 149 BeforeEach(func() { 150 release = &Release{} 151 }) 152 153 It("should return true when the automated field in the status is True", func() { 154 release.SetAutomated() 155 Expect(release.IsAutomated()).To(BeTrue()) 156 }) 157 158 It("should return false when the automated field in the status is False", func() { 159 release.Status.Automated = false 160 Expect(release.IsAutomated()).To(BeFalse()) 161 }) 162 163 It("should return false when the automated field in the status is missing", func() { 164 Expect(release.IsAutomated()).To(BeFalse()) 165 }) 166 }) 167 168 When("IsEveryPostActionExecuted method is called", func() { 169 var release *Release 170 171 BeforeEach(func() { 172 release = &Release{} 173 }) 174 175 It("should return true when the post-actions executed condition status is True", func() { 176 conditions.SetCondition(&release.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionTrue, SucceededReason) 177 Expect(release.IsEveryPostActionExecuted()).To(BeTrue()) 178 }) 179 180 It("should return false when the post-actions executed condition status is False", func() { 181 conditions.SetCondition(&release.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionFalse, SucceededReason) 182 Expect(release.IsEveryPostActionExecuted()).To(BeFalse()) 183 }) 184 185 It("should return false when the post-actions executed condition status is Unknown", func() { 186 conditions.SetCondition(&release.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionUnknown, SucceededReason) 187 Expect(release.IsEveryPostActionExecuted()).To(BeFalse()) 188 }) 189 190 It("should return false when the post-actions executed condition is missing", func() { 191 Expect(release.IsEveryPostActionExecuted()).To(BeFalse()) 192 }) 193 }) 194 195 When("IsEachPostActionExecuting method is called", func() { 196 var release *Release 197 198 BeforeEach(func() { 199 release = &Release{} 200 }) 201 202 It("should return false when the post-actions executed condition is missing", func() { 203 Expect(release.IsEachPostActionExecuting()).To(BeFalse()) 204 }) 205 206 It("should return false when the post-actions executed condition status is True", func() { 207 conditions.SetCondition(&release.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionTrue, SucceededReason) 208 Expect(release.IsEachPostActionExecuting()).To(BeFalse()) 209 }) 210 211 It("should return true when the post-actions executed condition status is False and the reason is Progressing", func() { 212 conditions.SetCondition(&release.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionFalse, ProgressingReason) 213 Expect(release.IsEachPostActionExecuting()).To(BeTrue()) 214 }) 215 216 It("should return false when the post-actions executed condition status is False and the reason is not Progressing", func() { 217 conditions.SetCondition(&release.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionFalse, FailedReason) 218 Expect(release.IsEachPostActionExecuting()).To(BeFalse()) 219 }) 220 221 It("should return false when the post-actions executed condition status is Unknown", func() { 222 conditions.SetCondition(&release.Status.Conditions, postActionsExecutedConditionType, metav1.ConditionUnknown, ProgressingReason) 223 Expect(release.IsEachPostActionExecuting()).To(BeFalse()) 224 }) 225 }) 226 227 When("IsProcessed method is called", func() { 228 var release *Release 229 230 BeforeEach(func() { 231 release = &Release{} 232 }) 233 234 It("should return true when the processed condition status is True", func() { 235 conditions.SetCondition(&release.Status.Conditions, processedConditionType, metav1.ConditionTrue, SucceededReason) 236 Expect(release.IsProcessed()).To(BeTrue()) 237 }) 238 239 It("should return false when the processed condition status is False", func() { 240 conditions.SetCondition(&release.Status.Conditions, processedConditionType, metav1.ConditionFalse, SucceededReason) 241 Expect(release.IsProcessed()).To(BeFalse()) 242 }) 243 244 It("should return false when the processed condition status is Unknown", func() { 245 conditions.SetCondition(&release.Status.Conditions, processedConditionType, metav1.ConditionUnknown, SucceededReason) 246 Expect(release.IsProcessed()).To(BeFalse()) 247 }) 248 249 It("should return false when the processed condition is missing", func() { 250 Expect(release.IsProcessed()).To(BeFalse()) 251 }) 252 }) 253 254 When("IsProcessing method is called", func() { 255 var release *Release 256 257 BeforeEach(func() { 258 release = &Release{} 259 }) 260 261 It("should return false when the processed condition is missing", func() { 262 Expect(release.IsProcessing()).To(BeFalse()) 263 }) 264 265 It("should return false when the processed condition status is True", func() { 266 conditions.SetCondition(&release.Status.Conditions, processedConditionType, metav1.ConditionTrue, SucceededReason) 267 Expect(release.IsProcessing()).To(BeFalse()) 268 }) 269 270 It("should return true when the processed condition status is False and the reason is Progressing", func() { 271 conditions.SetCondition(&release.Status.Conditions, processedConditionType, metav1.ConditionFalse, ProgressingReason) 272 Expect(release.IsProcessing()).To(BeTrue()) 273 }) 274 275 It("should return false when the processed condition status is False and the reason is not Progressing", func() { 276 conditions.SetCondition(&release.Status.Conditions, processedConditionType, metav1.ConditionFalse, FailedReason) 277 Expect(release.IsProcessing()).To(BeFalse()) 278 }) 279 280 It("should return false when the processed condition status is Unknown", func() { 281 conditions.SetCondition(&release.Status.Conditions, processedConditionType, metav1.ConditionUnknown, ProgressingReason) 282 Expect(release.IsProcessing()).To(BeFalse()) 283 }) 284 }) 285 286 When("IsReleased method is called", func() { 287 var release *Release 288 289 BeforeEach(func() { 290 release = &Release{} 291 }) 292 293 It("should return true when the released condition status is True", func() { 294 conditions.SetCondition(&release.Status.Conditions, releasedConditionType, metav1.ConditionTrue, SucceededReason) 295 Expect(release.IsReleased()).To(BeTrue()) 296 }) 297 298 It("should return false when the released condition status is False", func() { 299 conditions.SetCondition(&release.Status.Conditions, releasedConditionType, metav1.ConditionFalse, SucceededReason) 300 Expect(release.IsReleased()).To(BeFalse()) 301 }) 302 303 It("should return false when the released condition status is Unknown", func() { 304 conditions.SetCondition(&release.Status.Conditions, releasedConditionType, metav1.ConditionUnknown, SucceededReason) 305 Expect(release.IsReleased()).To(BeFalse()) 306 }) 307 308 It("should return false when the released condition is missing", func() { 309 Expect(release.IsReleased()).To(BeFalse()) 310 }) 311 }) 312 313 When("IsReleasing method is called", func() { 314 var release *Release 315 316 BeforeEach(func() { 317 release = &Release{} 318 }) 319 320 It("should return false when the released condition is missing", func() { 321 Expect(release.IsReleasing()).To(BeFalse()) 322 }) 323 324 It("should return false when the released condition status is True", func() { 325 conditions.SetCondition(&release.Status.Conditions, releasedConditionType, metav1.ConditionTrue, SucceededReason) 326 Expect(release.IsReleasing()).To(BeFalse()) 327 }) 328 329 It("should return true when the released condition status is False and the reason is Progressing", func() { 330 conditions.SetCondition(&release.Status.Conditions, releasedConditionType, metav1.ConditionFalse, ProgressingReason) 331 Expect(release.IsReleasing()).To(BeTrue()) 332 }) 333 334 It("should return false when the released condition status is False and the reason is not Progressing", func() { 335 conditions.SetCondition(&release.Status.Conditions, releasedConditionType, metav1.ConditionFalse, FailedReason) 336 Expect(release.IsReleasing()).To(BeFalse()) 337 }) 338 339 It("should return false when the released condition status is Unknown", func() { 340 conditions.SetCondition(&release.Status.Conditions, releasedConditionType, metav1.ConditionUnknown, ProgressingReason) 341 Expect(release.IsReleasing()).To(BeFalse()) 342 }) 343 }) 344 345 When("IsValid method is called", func() { 346 var release *Release 347 348 BeforeEach(func() { 349 release = &Release{} 350 }) 351 352 It("should return true when the validated condition status is True", func() { 353 conditions.SetCondition(&release.Status.Conditions, validatedConditionType, metav1.ConditionTrue, SucceededReason) 354 Expect(release.IsValid()).To(BeTrue()) 355 }) 356 357 It("should return false when the validated condition status is False", func() { 358 conditions.SetCondition(&release.Status.Conditions, validatedConditionType, metav1.ConditionFalse, SucceededReason) 359 Expect(release.IsValid()).To(BeFalse()) 360 }) 361 362 It("should return false when the validated condition status is Unknown", func() { 363 conditions.SetCondition(&release.Status.Conditions, validatedConditionType, metav1.ConditionUnknown, SucceededReason) 364 Expect(release.IsValid()).To(BeFalse()) 365 }) 366 367 It("should return false when the validated condition is missing", func() { 368 Expect(release.IsValid()).To(BeFalse()) 369 }) 370 }) 371 372 When("MarkProcessed method is called", func() { 373 var release *Release 374 375 BeforeEach(func() { 376 release = &Release{} 377 }) 378 379 It("should do nothing if the Release processing has not started", func() { 380 release.MarkProcessed() 381 Expect(release.Status.Processing.CompletionTime).To(BeNil()) 382 }) 383 384 It("should do nothing if the Release processing finished", func() { 385 release.MarkProcessing("") 386 release.MarkProcessed() 387 Expect(release.Status.Processing.CompletionTime.IsZero()).To(BeFalse()) 388 release.Status.Processing.CompletionTime = &metav1.Time{} 389 release.MarkProcessed() 390 Expect(release.Status.Processing.CompletionTime.IsZero()).To(BeTrue()) 391 }) 392 393 It("should register the completion time", func() { 394 release.MarkProcessing("") 395 Expect(release.Status.Processing.CompletionTime.IsZero()).To(BeTrue()) 396 release.MarkProcessed() 397 Expect(release.Status.Processing.CompletionTime.IsZero()).To(BeFalse()) 398 }) 399 400 It("should register the condition", func() { 401 Expect(release.Status.Conditions).To(HaveLen(0)) 402 release.MarkProcessing("") 403 release.MarkProcessed() 404 405 condition := meta.FindStatusCondition(release.Status.Conditions, processedConditionType.String()) 406 Expect(condition).NotTo(BeNil()) 407 Expect(*condition).To(MatchFields(IgnoreExtras, Fields{ 408 "Reason": Equal(SucceededReason.String()), 409 "Status": Equal(metav1.ConditionTrue), 410 })) 411 }) 412 }) 413 414 When("MarkProcessing method is called", func() { 415 var release *Release 416 417 BeforeEach(func() { 418 release = &Release{} 419 }) 420 421 It("should do nothing if the Release processing finished", func() { 422 release.MarkProcessing("") 423 release.MarkProcessed() 424 Expect(release.IsProcessing()).To(BeFalse()) 425 release.MarkProcessing("") 426 Expect(release.IsProcessing()).To(BeFalse()) 427 }) 428 429 It("should register the start time if it's not processing", func() { 430 Expect(release.Status.Processing.StartTime).To(BeNil()) 431 release.MarkProcessing("") 432 Expect(release.Status.Processing.StartTime).NotTo(BeNil()) 433 }) 434 435 It("should not register the start time if it's processing already", func() { 436 Expect(release.Status.Processing.StartTime).To(BeNil()) 437 release.MarkProcessing("") 438 release.Status.Processing.StartTime = &metav1.Time{} 439 Expect(release.Status.Processing.StartTime.IsZero()).To(BeTrue()) 440 release.MarkProcessing("") 441 Expect(release.Status.Processing.StartTime.IsZero()).To(BeTrue()) 442 }) 443 444 It("should register the condition", func() { 445 Expect(release.Status.Conditions).To(HaveLen(0)) 446 release.MarkProcessing("foo") 447 448 condition := meta.FindStatusCondition(release.Status.Conditions, processedConditionType.String()) 449 Expect(condition).NotTo(BeNil()) 450 Expect(*condition).To(MatchFields(IgnoreExtras, Fields{ 451 "Message": Equal("foo"), 452 "Reason": Equal(ProgressingReason.String()), 453 "Status": Equal(metav1.ConditionFalse), 454 })) 455 }) 456 }) 457 458 When("MarkProcessingFailed method is called", func() { 459 var release *Release 460 461 BeforeEach(func() { 462 release = &Release{} 463 }) 464 465 It("should do nothing if the Release processing has not started", func() { 466 release.MarkProcessingFailed("") 467 Expect(release.Status.Processing.CompletionTime).To(BeNil()) 468 }) 469 470 It("should do nothing if the Release processing finished", func() { 471 release.MarkProcessing("") 472 release.MarkProcessed() 473 Expect(release.Status.Processing.CompletionTime.IsZero()).To(BeFalse()) 474 release.Status.Processing.CompletionTime = &metav1.Time{} 475 release.MarkProcessingFailed("") 476 Expect(release.Status.Processing.CompletionTime.IsZero()).To(BeTrue()) 477 }) 478 479 It("should register the completion time", func() { 480 release.MarkProcessing("") 481 Expect(release.Status.Processing.CompletionTime.IsZero()).To(BeTrue()) 482 release.MarkProcessingFailed("") 483 Expect(release.Status.Processing.CompletionTime.IsZero()).To(BeFalse()) 484 }) 485 486 It("should register the condition", func() { 487 Expect(release.Status.Conditions).To(HaveLen(0)) 488 release.MarkProcessing("") 489 release.MarkProcessingFailed("foo") 490 491 condition := meta.FindStatusCondition(release.Status.Conditions, processedConditionType.String()) 492 Expect(condition).NotTo(BeNil()) 493 Expect(*condition).To(MatchFields(IgnoreExtras, Fields{ 494 "Message": Equal("foo"), 495 "Reason": Equal(FailedReason.String()), 496 "Status": Equal(metav1.ConditionFalse), 497 })) 498 }) 499 }) 500 501 When("MarkPostActionsExecuted method is called", func() { 502 var release *Release 503 504 BeforeEach(func() { 505 release = &Release{} 506 }) 507 508 It("should do nothing if the Release post-actions execution has not started", func() { 509 release.MarkPostActionsExecuted() 510 Expect(release.Status.PostActionsExecution.CompletionTime).To(BeNil()) 511 }) 512 513 It("should do nothing if the Release post-actions execution finished", func() { 514 release.MarkPostActionsExecuting("") 515 release.MarkPostActionsExecuted() 516 Expect(release.Status.PostActionsExecution.CompletionTime.IsZero()).To(BeFalse()) 517 release.Status.PostActionsExecution.CompletionTime = &metav1.Time{} 518 release.MarkPostActionsExecuted() 519 Expect(release.Status.PostActionsExecution.CompletionTime.IsZero()).To(BeTrue()) 520 }) 521 522 It("should register the completion time", func() { 523 release.MarkPostActionsExecuting("") 524 Expect(release.Status.PostActionsExecution.CompletionTime.IsZero()).To(BeTrue()) 525 release.MarkPostActionsExecuted() 526 Expect(release.Status.PostActionsExecution.CompletionTime.IsZero()).To(BeFalse()) 527 }) 528 529 It("should register the condition", func() { 530 Expect(release.Status.Conditions).To(HaveLen(0)) 531 release.MarkPostActionsExecuting("") 532 release.MarkPostActionsExecuted() 533 534 condition := meta.FindStatusCondition(release.Status.Conditions, postActionsExecutedConditionType.String()) 535 Expect(condition).NotTo(BeNil()) 536 Expect(*condition).To(MatchFields(IgnoreExtras, Fields{ 537 "Reason": Equal(SucceededReason.String()), 538 "Status": Equal(metav1.ConditionTrue), 539 })) 540 }) 541 }) 542 543 When("MarkPostActionsExecuting method is called", func() { 544 var release *Release 545 546 BeforeEach(func() { 547 release = &Release{} 548 }) 549 550 It("should do nothing if the Release post-actions execution finished", func() { 551 release.MarkPostActionsExecuting("") 552 release.MarkPostActionsExecuted() 553 Expect(release.IsEachPostActionExecuting()).To(BeFalse()) 554 release.MarkPostActionsExecuting("") 555 Expect(release.IsEachPostActionExecuting()).To(BeFalse()) 556 }) 557 558 It("should register the start time if it's not executing post-actions", func() { 559 Expect(release.Status.PostActionsExecution.StartTime).To(BeNil()) 560 release.MarkPostActionsExecuting("") 561 Expect(release.Status.PostActionsExecution.StartTime).NotTo(BeNil()) 562 }) 563 564 It("should not register the start time if it's executing post-actions already", func() { 565 Expect(release.Status.PostActionsExecution.StartTime).To(BeNil()) 566 release.MarkPostActionsExecuting("") 567 release.Status.PostActionsExecution.StartTime = &metav1.Time{} 568 Expect(release.Status.PostActionsExecution.StartTime.IsZero()).To(BeTrue()) 569 release.MarkPostActionsExecuting("") 570 Expect(release.Status.PostActionsExecution.StartTime.IsZero()).To(BeTrue()) 571 }) 572 573 It("should register the condition", func() { 574 Expect(release.Status.Conditions).To(HaveLen(0)) 575 release.MarkPostActionsExecuting("foo") 576 577 condition := meta.FindStatusCondition(release.Status.Conditions, postActionsExecutedConditionType.String()) 578 Expect(condition).NotTo(BeNil()) 579 Expect(*condition).To(MatchFields(IgnoreExtras, Fields{ 580 "Message": Equal("foo"), 581 "Reason": Equal(ProgressingReason.String()), 582 "Status": Equal(metav1.ConditionFalse), 583 })) 584 }) 585 }) 586 587 When("MarkPostActionsExecutionFailed method is called", func() { 588 var release *Release 589 590 BeforeEach(func() { 591 release = &Release{} 592 }) 593 594 It("should do nothing if the Release post-actions execution has not started", func() { 595 release.MarkPostActionsExecutionFailed("") 596 Expect(release.Status.PostActionsExecution.CompletionTime).To(BeNil()) 597 }) 598 599 It("should do nothing if the Release post-actions execution finished", func() { 600 release.MarkPostActionsExecuting("") 601 release.MarkPostActionsExecuted() 602 Expect(release.Status.PostActionsExecution.CompletionTime.IsZero()).To(BeFalse()) 603 release.Status.PostActionsExecution.CompletionTime = &metav1.Time{} 604 release.MarkPostActionsExecutionFailed("") 605 Expect(release.Status.PostActionsExecution.CompletionTime.IsZero()).To(BeTrue()) 606 }) 607 608 It("should register the completion time", func() { 609 release.MarkPostActionsExecuting("") 610 Expect(release.Status.PostActionsExecution.CompletionTime.IsZero()).To(BeTrue()) 611 release.MarkPostActionsExecutionFailed("") 612 Expect(release.Status.PostActionsExecution.CompletionTime.IsZero()).To(BeFalse()) 613 }) 614 615 It("should register the condition", func() { 616 Expect(release.Status.Conditions).To(HaveLen(0)) 617 release.MarkPostActionsExecuting("") 618 release.MarkPostActionsExecutionFailed("foo") 619 620 condition := meta.FindStatusCondition(release.Status.Conditions, postActionsExecutedConditionType.String()) 621 Expect(condition).NotTo(BeNil()) 622 Expect(*condition).To(MatchFields(IgnoreExtras, Fields{ 623 "Message": Equal("foo"), 624 "Reason": Equal(FailedReason.String()), 625 "Status": Equal(metav1.ConditionFalse), 626 })) 627 }) 628 }) 629 630 When("MarkReleased method is called", func() { 631 var release *Release 632 633 BeforeEach(func() { 634 release = &Release{} 635 }) 636 637 It("should do nothing if the Release has not started", func() { 638 release.MarkReleased() 639 Expect(release.Status.CompletionTime).To(BeNil()) 640 }) 641 642 It("should do nothing if the Release has finished", func() { 643 release.MarkReleasing("") 644 release.MarkReleased() 645 Expect(release.Status.CompletionTime.IsZero()).To(BeFalse()) 646 release.Status.CompletionTime = &metav1.Time{} 647 release.MarkReleased() 648 Expect(release.Status.CompletionTime.IsZero()).To(BeTrue()) 649 }) 650 651 It("should register the completion time", func() { 652 release.MarkReleasing("") 653 Expect(release.Status.CompletionTime.IsZero()).To(BeTrue()) 654 release.MarkReleased() 655 Expect(release.Status.CompletionTime.IsZero()).To(BeFalse()) 656 }) 657 658 It("should register the condition", func() { 659 Expect(release.Status.Conditions).To(HaveLen(0)) 660 release.MarkReleasing("") 661 release.MarkReleased() 662 663 condition := meta.FindStatusCondition(release.Status.Conditions, releasedConditionType.String()) 664 Expect(condition).NotTo(BeNil()) 665 Expect(*condition).To(MatchFields(IgnoreExtras, Fields{ 666 "Reason": Equal(SucceededReason.String()), 667 "Status": Equal(metav1.ConditionTrue), 668 })) 669 }) 670 }) 671 672 When("MarkReleasing method is called", func() { 673 var release *Release 674 675 BeforeEach(func() { 676 release = &Release{} 677 }) 678 679 It("should do nothing if the Release finished", func() { 680 release.MarkReleasing("") 681 release.MarkReleased() 682 Expect(release.IsReleasing()).To(BeFalse()) 683 release.MarkReleasing("") 684 Expect(release.IsReleasing()).To(BeFalse()) 685 }) 686 687 It("should register the start time if it's not releasing", func() { 688 Expect(release.Status.StartTime).To(BeNil()) 689 release.MarkReleasing("") 690 Expect(release.Status.StartTime).NotTo(BeNil()) 691 }) 692 693 It("should not register the start time if it's releasing already", func() { 694 Expect(release.Status.StartTime).To(BeNil()) 695 release.MarkReleasing("") 696 release.Status.StartTime = &metav1.Time{} 697 Expect(release.Status.StartTime.IsZero()).To(BeTrue()) 698 release.MarkReleasing("") 699 Expect(release.Status.StartTime.IsZero()).To(BeTrue()) 700 }) 701 702 It("should register the condition", func() { 703 Expect(release.Status.Conditions).To(HaveLen(0)) 704 release.MarkReleasing("foo") 705 706 condition := meta.FindStatusCondition(release.Status.Conditions, releasedConditionType.String()) 707 Expect(condition).NotTo(BeNil()) 708 Expect(*condition).To(MatchFields(IgnoreExtras, Fields{ 709 "Message": Equal("foo"), 710 "Reason": Equal(ProgressingReason.String()), 711 "Status": Equal(metav1.ConditionFalse), 712 })) 713 }) 714 }) 715 716 When("MarkReleaseFailed method is called", func() { 717 var release *Release 718 719 BeforeEach(func() { 720 release = &Release{} 721 }) 722 723 It("should do nothing if the Release has not started", func() { 724 release.MarkReleaseFailed("") 725 Expect(release.Status.CompletionTime).To(BeNil()) 726 }) 727 728 It("should do nothing if the Release has finished", func() { 729 release.MarkReleasing("") 730 release.MarkReleased() 731 Expect(release.Status.CompletionTime.IsZero()).To(BeFalse()) 732 release.Status.CompletionTime = &metav1.Time{} 733 release.MarkReleaseFailed("") 734 Expect(release.Status.CompletionTime.IsZero()).To(BeTrue()) 735 }) 736 737 It("should register the completion time", func() { 738 release.MarkReleasing("") 739 Expect(release.Status.CompletionTime.IsZero()).To(BeTrue()) 740 release.MarkReleaseFailed("") 741 Expect(release.Status.CompletionTime.IsZero()).To(BeFalse()) 742 }) 743 744 It("should register the condition", func() { 745 Expect(release.Status.Conditions).To(HaveLen(0)) 746 release.MarkReleasing("") 747 release.MarkReleaseFailed("foo") 748 749 condition := meta.FindStatusCondition(release.Status.Conditions, releasedConditionType.String()) 750 Expect(condition).NotTo(BeNil()) 751 Expect(*condition).To(MatchFields(IgnoreExtras, Fields{ 752 "Message": Equal("foo"), 753 "Reason": Equal(FailedReason.String()), 754 "Status": Equal(metav1.ConditionFalse), 755 })) 756 }) 757 }) 758 759 When("MarkValidated method is called", func() { 760 var release *Release 761 762 BeforeEach(func() { 763 release = &Release{} 764 }) 765 766 It("should do nothing if the Release is valid", func() { 767 release.MarkValidated() 768 Expect(release.Status.Validation.Time.IsZero()).To(BeFalse()) 769 release.Status.Validation.Time = &metav1.Time{} 770 release.MarkValidated() 771 Expect(release.Status.Validation.Time.IsZero()).To(BeTrue()) 772 }) 773 774 It("should register the validation time", func() { 775 Expect(release.Status.Validation.Time.IsZero()).To(BeTrue()) 776 release.MarkValidated() 777 Expect(release.Status.Validation.Time.IsZero()).To(BeFalse()) 778 }) 779 780 It("should register the condition", func() { 781 Expect(release.Status.Conditions).To(HaveLen(0)) 782 release.MarkValidated() 783 784 condition := meta.FindStatusCondition(release.Status.Conditions, validatedConditionType.String()) 785 Expect(condition).NotTo(BeNil()) 786 Expect(*condition).To(MatchFields(IgnoreExtras, Fields{ 787 "Reason": Equal(SucceededReason.String()), 788 "Status": Equal(metav1.ConditionTrue), 789 })) 790 }) 791 }) 792 793 When("MarkValidationFailed method is called", func() { 794 var release *Release 795 796 BeforeEach(func() { 797 release = &Release{} 798 }) 799 800 It("should not register the post-validation failure if it was not marked as valid before", func() { 801 release.MarkValidationFailed("") 802 Expect(release.Status.Validation.FailedPostValidation).To(BeFalse()) 803 }) 804 805 It("should register the post-validation failure if it was marked as valid before", func() { 806 release.MarkValidated() 807 release.MarkValidationFailed("") 808 Expect(release.Status.Validation.FailedPostValidation).To(BeTrue()) 809 }) 810 811 It("should register the validation time", func() { 812 Expect(release.Status.Validation.Time).To(BeNil()) 813 release.MarkValidationFailed("") 814 Expect(release.Status.Validation.Time.IsZero()).To(BeFalse()) 815 }) 816 817 It("should register the condition", func() { 818 Expect(release.Status.Conditions).To(HaveLen(0)) 819 release.MarkValidationFailed("foo") 820 821 condition := meta.FindStatusCondition(release.Status.Conditions, validatedConditionType.String()) 822 Expect(condition).NotTo(BeNil()) 823 Expect(*condition).To(MatchFields(IgnoreExtras, Fields{ 824 "Message": Equal("foo"), 825 "Reason": Equal(FailedReason.String()), 826 "Status": Equal(metav1.ConditionFalse), 827 })) 828 }) 829 }) 830 831 When("SetAutomated method is called", func() { 832 var release *Release 833 834 BeforeEach(func() { 835 release = &Release{} 836 }) 837 838 It("should set the automated field in the status to True", func() { 839 release.SetAutomated() 840 Expect(release.Status.Automated).To(BeTrue()) 841 }) 842 }) 843 844 When("getPhaseReason method is called", func() { 845 var release *Release 846 847 BeforeEach(func() { 848 release = &Release{} 849 }) 850 851 It("returns the reason associated with the condition type", func() { 852 release.MarkValidated() 853 Expect(release.getPhaseReason(validatedConditionType)).To(Equal(SucceededReason.String())) 854 }) 855 856 It("returns an empty string if the condition is not found", func() { 857 Expect(release.getPhaseReason(validatedConditionType)).To(Equal("")) 858 }) 859 }) 860 861 When("hasPhaseFinished method is called", func() { 862 var release *Release 863 864 BeforeEach(func() { 865 release = &Release{} 866 }) 867 868 It("should return false when the condition is missing", func() { 869 Expect(release.hasPhaseFinished(deployedConditionType)).To(BeFalse()) 870 }) 871 872 It("should return true when the condition status is True", func() { 873 conditions.SetCondition(&release.Status.Conditions, deployedConditionType, metav1.ConditionTrue, SucceededReason) 874 Expect(release.hasPhaseFinished(deployedConditionType)).To(BeTrue()) 875 }) 876 877 It("should return false when the condition status is False and the reason is Progressing", func() { 878 conditions.SetCondition(&release.Status.Conditions, deployedConditionType, metav1.ConditionFalse, ProgressingReason) 879 Expect(release.hasPhaseFinished(deployedConditionType)).To(BeFalse()) 880 }) 881 882 It("should return true when the condition status is False and the reason is not Progressing", func() { 883 conditions.SetCondition(&release.Status.Conditions, deployedConditionType, metav1.ConditionFalse, FailedReason) 884 Expect(release.hasPhaseFinished(deployedConditionType)).To(BeTrue()) 885 }) 886 887 It("should return false when the condition status is Unknown", func() { 888 conditions.SetCondition(&release.Status.Conditions, deployedConditionType, metav1.ConditionUnknown, ProgressingReason) 889 Expect(release.hasPhaseFinished(deployedConditionType)).To(BeFalse()) 890 }) 891 }) 892 893 When("isPhaseProgressing method is called", func() { 894 var release *Release 895 896 BeforeEach(func() { 897 release = &Release{} 898 }) 899 900 It("should return false when the condition is missing", func() { 901 Expect(release.isPhaseProgressing(deployedConditionType)).To(BeFalse()) 902 }) 903 904 It("should return false when the condition status is True", func() { 905 conditions.SetCondition(&release.Status.Conditions, deployedConditionType, metav1.ConditionTrue, SucceededReason) 906 Expect(release.isPhaseProgressing(deployedConditionType)).To(BeFalse()) 907 }) 908 909 It("should return true when the condition status is False and the reason is Progressing", func() { 910 conditions.SetCondition(&release.Status.Conditions, deployedConditionType, metav1.ConditionFalse, ProgressingReason) 911 Expect(release.isPhaseProgressing(deployedConditionType)).To(BeTrue()) 912 }) 913 914 It("should return false when the condition status is False and the reason is not Progressing", func() { 915 conditions.SetCondition(&release.Status.Conditions, deployedConditionType, metav1.ConditionFalse, FailedReason) 916 Expect(release.isPhaseProgressing(deployedConditionType)).To(BeFalse()) 917 }) 918 919 It("should return false when the condition status is Unknown", func() { 920 conditions.SetCondition(&release.Status.Conditions, deployedConditionType, metav1.ConditionUnknown, ProgressingReason) 921 Expect(release.isPhaseProgressing(deployedConditionType)).To(BeFalse()) 922 }) 923 }) 924 925 When("SetExpirationTime method is called", func() { 926 var release *Release 927 928 BeforeEach(func() { 929 release = &Release{} 930 }) 931 932 It("should set the ExpirationTime", func() { 933 expireDays := time.Duration(5) 934 creationTime := release.CreationTimestamp 935 expectedExpirationTime := &metav1.Time{Time: creationTime.Add(time.Hour * 24 * expireDays)} 936 937 release.SetExpirationTime(expireDays) 938 Expect(release.Status.ExpirationTime).To(Equal(expectedExpirationTime)) 939 }) 940 }) 941 })