...

Source file src/edge-infra.dev/pkg/k8s/runtime/controller/reconcile/reconclie_request_test.go

Documentation: edge-infra.dev/pkg/k8s/runtime/controller/reconcile

     1  package reconcile
     2  
     3  import (
     4  	"testing"
     5  
     6  	assertapi "github.com/stretchr/testify/assert"
     7  	"k8s.io/apimachinery/pkg/runtime"
     8  	"k8s.io/apimachinery/pkg/runtime/schema"
     9  )
    10  
    11  // Not using fobject to avoid test import cycle
    12  type fakeStatus struct {
    13  	RequestStatus `json:",inline"`
    14  }
    15  
    16  type fakeObj struct {
    17  	Annotations map[string]string
    18  	Status      fakeStatus
    19  }
    20  
    21  func (f fakeObj) GetObjectKind() schema.ObjectKind {
    22  	return schema.EmptyObjectKind
    23  }
    24  
    25  func (f fakeObj) DeepCopyObject() runtime.Object {
    26  	return f
    27  }
    28  
    29  func TestGetStatusLastHandledReconcileAt(t *testing.T) {
    30  	assert := assertapi.New(t)
    31  
    32  	// Get unset status lastHandledReconcileAt.
    33  	obj := &fakeObj{Annotations: map[string]string{}}
    34  	_, err := GetStatusLastHandledReconcileAt(obj)
    35  	if assert.Error(err) {
    36  		assert.ErrorIs(err, ErrLastHandledReconcileAtNotFound)
    37  	}
    38  
    39  	// Get set status lastHandledReconcileAt.
    40  	obj.Status.LastHandledReconcileAt = "foo"
    41  	ra, err := GetStatusLastHandledReconcileAt(obj)
    42  	assert.NoError(err)
    43  	assert.Equal("foo", ra)
    44  }
    45  
    46  func TestSetStatusLastHandledReconcileAt(t *testing.T) {
    47  	assert := assertapi.New(t)
    48  
    49  	obj := &fakeObj{Annotations: map[string]string{}}
    50  	err := SetStatusLastHandledReconcileAt(obj, "now")
    51  	assert.NoError(err)
    52  	assert.Equal("now", obj.Status.RequestStatus.LastHandledReconcileAt)
    53  }
    54  

View as plain text