Skip to content

Commit c9ec4cf

Browse files
Greg Wereschpivotalgeorge
andauthored
Update tests to use a regex to validate the shape of the date and time (#3070)
Co-authored-by: George Gelashvili <[email protected]>
1 parent d328451 commit c9ec4cf

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

command/v7/shared/app_summary_displayer_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ var _ = Describe("app summary displayer", func() {
696696
})
697697

698698
When("there is an active deployment", func() {
699+
var LastStatusChangeTimeString = "2024-07-29T17:32:29Z"
700+
var dateTimeRegexPattern = `[a-zA-Z]{3}\s\d{2}\s[a-zA-Z]{3}\s\d{2}\:\d{2}\:\d{2}\s[A-Z]{3}\s\d{4}`
701+
699702
When("the deployment strategy is rolling", func() {
700703
When("the deployment is in progress", func() {
701704
When("last status change has a timestamp", func() {
@@ -705,13 +708,14 @@ var _ = Describe("app summary displayer", func() {
705708
Strategy: constant.DeploymentStrategyRolling,
706709
StatusValue: constant.DeploymentStatusValueActive,
707710
StatusReason: constant.DeploymentStatusReasonDeploying,
708-
LastStatusChange: "2024-07-29T17:32:29Z",
711+
LastStatusChange: LastStatusChangeTimeString,
709712
},
710713
}
711714
})
712715

713716
It("displays the message", func() {
714-
Expect(testUI.Out).To(Say(`Rolling deployment currently DEPLOYING \(since Mon 29 Jul 13:32:29 EDT 2024\)`))
717+
var actualOut = fmt.Sprintf("%s", testUI.Out)
718+
Expect(actualOut).To(MatchRegexp(`Rolling deployment currently DEPLOYING \(since %s\)`, dateTimeRegexPattern))
715719
})
716720
})
717721

@@ -741,13 +745,14 @@ var _ = Describe("app summary displayer", func() {
741745
Strategy: constant.DeploymentStrategyRolling,
742746
StatusValue: constant.DeploymentStatusValueActive,
743747
StatusReason: constant.DeploymentStatusReasonCanceling,
744-
LastStatusChange: "2024-07-29T17:32:29Z",
748+
LastStatusChange: LastStatusChangeTimeString,
745749
},
746750
}
747751
})
748752

749753
It("displays the message", func() {
750-
Expect(testUI.Out).To(Say(`Rolling deployment currently CANCELING \(since Mon 29 Jul 13:32:29 EDT 2024\)`))
754+
var actualOut = fmt.Sprintf("%s", testUI.Out)
755+
Expect(actualOut).To(MatchRegexp(`Rolling deployment currently CANCELING \(since %s\)`, dateTimeRegexPattern))
751756
})
752757
})
753758
})
@@ -759,13 +764,14 @@ var _ = Describe("app summary displayer", func() {
759764
Strategy: constant.DeploymentStrategyCanary,
760765
StatusValue: constant.DeploymentStatusValueActive,
761766
StatusReason: constant.DeploymentStatusReasonDeploying,
762-
LastStatusChange: "2024-07-29T17:32:29Z",
767+
LastStatusChange: LastStatusChangeTimeString,
763768
},
764769
}
765770
})
766771

767772
It("displays the message", func() {
768-
Expect(testUI.Out).To(Say(`Canary deployment currently DEPLOYING \(since Mon 29 Jul 13:32:29 EDT 2024\)`))
773+
var actualOut = fmt.Sprintf("%s", testUI.Out)
774+
Expect(actualOut).To(MatchRegexp(`Canary deployment currently DEPLOYING \(since %s\)`, dateTimeRegexPattern))
769775
Expect(testUI.Out).NotTo(Say(`promote the canary deployment`))
770776
})
771777
})
@@ -782,13 +788,14 @@ var _ = Describe("app summary displayer", func() {
782788
Strategy: constant.DeploymentStrategyCanary,
783789
StatusValue: constant.DeploymentStatusValueActive,
784790
StatusReason: constant.DeploymentStatusReasonPaused,
785-
LastStatusChange: "2024-07-29T17:32:29Z",
791+
LastStatusChange: LastStatusChangeTimeString,
786792
},
787793
}
788794
})
789795

790796
It("displays the message", func() {
791-
Expect(testUI.Out).To(Say(`Canary deployment currently PAUSED \(since Mon 29 Jul 13:32:29 EDT 2024\)`))
797+
var actualOut = fmt.Sprintf("%s", testUI.Out)
798+
Expect(actualOut).To(MatchRegexp(`Canary deployment currently PAUSED \(since %s\)`, dateTimeRegexPattern))
792799
Expect(testUI.Out).To(Say("Please run `cf continue-deployment foobar` to promote the canary deployment, or `cf cancel-deployment foobar` to rollback to the previous version."))
793800
})
794801
})
@@ -800,13 +807,14 @@ var _ = Describe("app summary displayer", func() {
800807
Strategy: constant.DeploymentStrategyCanary,
801808
StatusValue: constant.DeploymentStatusValueActive,
802809
StatusReason: constant.DeploymentStatusReasonCanceling,
803-
LastStatusChange: "2024-07-29T17:32:29Z",
810+
LastStatusChange: LastStatusChangeTimeString,
804811
},
805812
}
806813
})
807814

808815
It("displays the message", func() {
809-
Expect(testUI.Out).To(Say(`Canary deployment currently CANCELING \(since Mon 29 Jul 13:32:29 EDT 2024\)`))
816+
var actualOut = fmt.Sprintf("%s", testUI.Out)
817+
Expect(actualOut).To(MatchRegexp(`Canary deployment currently CANCELING \(since %s\)`, dateTimeRegexPattern))
810818
Expect(testUI.Out).NotTo(Say(`promote the canary deployment`))
811819
})
812820
})

0 commit comments

Comments
 (0)