export time function

NowFunc() has to be exported so it is available for testing in other
packages.
This commit is contained in:
Roman Bednar 2023-09-13 11:32:56 +02:00
parent 9cfd96dbb5
commit 071a67d8c2
2 changed files with 7 additions and 7 deletions

View File

@ -71,7 +71,7 @@ func (persistentvolumeStrategy) PrepareForCreate(ctx context.Context, obj runtim
if utilfeature.DefaultFeatureGate.Enabled(features.PersistentVolumeLastPhaseTransitionTime) {
pv.Status.Phase = api.VolumePending
now := nowFunc()
now := NowFunc()
pv.Status.LastPhaseTransitionTime = &now
}
@ -143,7 +143,7 @@ func (persistentvolumeStatusStrategy) GetResetFields() map[fieldpath.APIVersion]
return fields
}
var nowFunc = metav1.Now
var NowFunc = metav1.Now
// PrepareForUpdate sets the Spec field which is not allowed to be changed when updating a PV's Status
func (persistentvolumeStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
@ -159,7 +159,7 @@ func (persistentvolumeStatusStrategy) PrepareForUpdate(ctx context.Context, obj,
case oldPv.Status.Phase != newPv.Status.Phase && (newPv.Status.LastPhaseTransitionTime == nil || newPv.Status.LastPhaseTransitionTime.Equal(oldPv.Status.LastPhaseTransitionTime)):
// phase changed and client didn't set or didn't change the transition time
now := nowFunc()
now := NowFunc()
newPv.Status.LastPhaseTransitionTime = &now
}
}

View File

@ -46,9 +46,9 @@ func TestStatusUpdate(t *testing.T) {
now := metav1.Now()
origin := metav1.NewTime(now.Add(time.Hour))
later := metav1.NewTime(now.Add(time.Hour * 2))
nowFunc = func() metav1.Time { return now }
NowFunc = func() metav1.Time { return now }
defer func() {
nowFunc = metav1.Now
NowFunc = metav1.Now
}()
tests := []struct {
name string
@ -376,9 +376,9 @@ func TestStatusUpdate(t *testing.T) {
func TestStatusCreate(t *testing.T) {
now := metav1.Now()
nowFunc = func() metav1.Time { return now }
NowFunc = func() metav1.Time { return now }
defer func() {
nowFunc = metav1.Now
NowFunc = metav1.Now
}()
tests := []struct {
name string