chore: replacing timer ptr with ptr.To

Kubernetes-commit: 2b13b87e609b83f453f7a160d9cae8a15c0e64f2
This commit is contained in:
PatrickLaabs 2025-07-17 15:11:55 +02:00 committed by Kubernetes Publisher
parent be36413bbc
commit d4f7b29b04

View File

@ -25,6 +25,7 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"k8s.io/client-go/tools/clientcmd/api" "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/tools/metrics" "k8s.io/client-go/tools/metrics"
"k8s.io/utils/ptr"
) )
type mockExpiryGauge struct { type mockExpiryGauge struct {
@ -35,10 +36,6 @@ func (m *mockExpiryGauge) Set(t *time.Time) {
m.v = t m.v = t
} }
func ptr(t time.Time) *time.Time {
return &t
}
func TestCertificateExpirationTracker(t *testing.T) { func TestCertificateExpirationTracker(t *testing.T) {
now := time.Now() now := time.Now()
mockMetric := &mockExpiryGauge{} mockMetric := &mockExpiryGauge{}
@ -60,25 +57,25 @@ func TestCertificateExpirationTracker(t *testing.T) {
desc: "ttl for one authenticator", desc: "ttl for one authenticator",
auth: firstAuthenticator, auth: firstAuthenticator,
time: now.Add(time.Minute * 10), time: now.Add(time.Minute * 10),
want: ptr(now.Add(time.Minute * 10)), want: ptr.To(now.Add(time.Minute * 10)),
}, },
{ {
desc: "second authenticator shorter ttl", desc: "second authenticator shorter ttl",
auth: secondAuthenticator, auth: secondAuthenticator,
time: now.Add(time.Minute * 5), time: now.Add(time.Minute * 5),
want: ptr(now.Add(time.Minute * 5)), want: ptr.To(now.Add(time.Minute * 5)),
}, },
{ {
desc: "update shorter to be longer", desc: "update shorter to be longer",
auth: secondAuthenticator, auth: secondAuthenticator,
time: now.Add(time.Minute * 15), time: now.Add(time.Minute * 15),
want: ptr(now.Add(time.Minute * 10)), want: ptr.To(now.Add(time.Minute * 10)),
}, },
{ {
desc: "update shorter to be zero time", desc: "update shorter to be zero time",
auth: firstAuthenticator, auth: firstAuthenticator,
time: time.Time{}, time: time.Time{},
want: ptr(now.Add(time.Minute * 15)), want: ptr.To(now.Add(time.Minute * 15)),
}, },
{ {
desc: "update last to be zero time records nil", desc: "update last to be zero time records nil",
@ -194,8 +191,8 @@ func TestCallsMetric(t *testing.T) {
callsMetricComparer := cmp.Comparer(func(a, b mockCallsMetric) bool { callsMetricComparer := cmp.Comparer(func(a, b mockCallsMetric) bool {
return a.exitCode == b.exitCode && a.errorType == b.errorType return a.exitCode == b.exitCode && a.errorType == b.errorType
}) })
actuallCallsMetrics := callsMetricCounter.calls actualCallsMetrics := callsMetricCounter.calls
if diff := cmp.Diff(wantCallsMetrics, actuallCallsMetrics, callsMetricComparer); diff != "" { if diff := cmp.Diff(wantCallsMetrics, actualCallsMetrics, callsMetricComparer); diff != "" {
t.Fatalf("got unexpected metrics calls; -want, +got:\n%s", diff) t.Fatalf("got unexpected metrics calls; -want, +got:\n%s", diff)
} }
} }