Skip to content

Commit

Permalink
Merge pull request #123910 from MarSik/fix-printer-leap-y
Browse files Browse the repository at this point in the history
Fix printers tests - remove dependency on leap years
  • Loading branch information
k8s-ci-robot committed May 22, 2024
2 parents 6809180 + 5ba8f88 commit 74d5784
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/printers/internalversion/printers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ func TestPrintIngress(t *testing.T) {
ingress := networking.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "test1",
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-10, 0, 0)},
CreationTimestamp: metav1.Time{Time: time.Now().Add(time.Duration(-10 * 365 * 24 * time.Hour))},
},
Spec: networking.IngressSpec{
IngressClassName: utilpointer.StringPtr("foo"),
Expand Down Expand Up @@ -1018,7 +1018,7 @@ func TestPrintIngressClass(t *testing.T) {
ingressClass: &networking.IngressClass{
ObjectMeta: metav1.ObjectMeta{
Name: "test1",
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-10, 0, 0)},
CreationTimestamp: metav1.Time{Time: time.Now().Add(time.Duration(-10 * 365 * 24 * time.Hour))},
},
Spec: networking.IngressClassSpec{
Controller: "example.com/controller",
Expand All @@ -1031,7 +1031,7 @@ func TestPrintIngressClass(t *testing.T) {
ingressClass: &networking.IngressClass{
ObjectMeta: metav1.ObjectMeta{
Name: "test1",
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-10, 0, 0)},
CreationTimestamp: metav1.Time{Time: time.Now().Add(time.Duration(-10 * 365 * 24 * time.Hour))},
},
Spec: networking.IngressClassSpec{
Controller: "example.com/controller",
Expand All @@ -1048,7 +1048,7 @@ func TestPrintIngressClass(t *testing.T) {
ingressClass: &networking.IngressClass{
ObjectMeta: metav1.ObjectMeta{
Name: "test2",
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-11, 0, 0)},
CreationTimestamp: metav1.Time{Time: time.Now().Add(time.Duration(-11 * 365 * 24 * time.Hour))},
},
Spec: networking.IngressClassSpec{
Controller: "example.com/controller2",
Expand Down Expand Up @@ -2276,7 +2276,7 @@ func TestTranslateTimestampSince(t *testing.T) {
{"an hour ago", translateTimestampSince(metav1.Time{Time: time.Now().Add(-6e12)}), "100m"},
{"2 days ago", translateTimestampSince(metav1.Time{Time: time.Now().UTC().AddDate(0, 0, -2)}), "2d"},
{"months ago", translateTimestampSince(metav1.Time{Time: time.Now().UTC().AddDate(0, 0, -90)}), "90d"},
{"10 years ago", translateTimestampSince(metav1.Time{Time: time.Now().UTC().AddDate(-10, 0, 0)}), "10y"},
{"10 years ago", translateTimestampSince(metav1.Time{Time: time.Now().UTC().Add(time.Duration(-10 * 365 * 24 * time.Hour))}), "10y"},
}
for _, test := range tl {
if test.got != test.exp {
Expand All @@ -2301,7 +2301,7 @@ func TestTranslateTimestampUntil(t *testing.T) {
{"in an hour", translateTimestampUntil(metav1.Time{Time: time.Now().Add(6e12 + buf)}), "100m"},
{"in 2 days", translateTimestampUntil(metav1.Time{Time: time.Now().UTC().AddDate(0, 0, 2).Add(buf)}), "2d"},
{"in months", translateTimestampUntil(metav1.Time{Time: time.Now().UTC().AddDate(0, 0, 90).Add(buf)}), "90d"},
{"in 10 years", translateTimestampUntil(metav1.Time{Time: time.Now().UTC().AddDate(10, 0, 0).Add(buf)}), "10y"},
{"in 10 years", translateTimestampUntil(metav1.Time{Time: time.Now().UTC().Add(time.Duration(10 * 365 * 24 * time.Hour)).Add(buf)}), "10y"},
}
for _, test := range tl {
if test.got != test.exp {
Expand Down Expand Up @@ -2619,7 +2619,7 @@ func TestPrintJob(t *testing.T) {
job: batch.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "job3",
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-10, 0, 0)},
CreationTimestamp: metav1.Time{Time: time.Now().Add(time.Duration(-10 * 365 * 24 * time.Hour))},
},
Spec: batch.JobSpec{
Completions: nil,
Expand All @@ -2638,7 +2638,7 @@ func TestPrintJob(t *testing.T) {
job: batch.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "job4",
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-10, 0, 0)},
CreationTimestamp: metav1.Time{Time: time.Now().Add(time.Duration(-10 * 365 * 24 * time.Hour))},
},
Spec: batch.JobSpec{
Completions: nil,
Expand Down Expand Up @@ -6678,7 +6678,7 @@ func TestPrintIPAddress(t *testing.T) {
ip := networking.IPAddress{
ObjectMeta: metav1.ObjectMeta{
Name: "192.168.2.2",
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-10, 0, 0)},
CreationTimestamp: metav1.Time{Time: time.Now().Add(time.Duration(-10 * 365 * 24 * time.Hour))},
},
Spec: networking.IPAddressSpec{
ParentRef: &networking.ParentReference{
Expand Down

0 comments on commit 74d5784

Please sign in to comment.