Exemplo n.º 1
0
//TestUIDContext validates that a UID can be get/set on a context object
func TestUIDContext(t *testing.T) {
	ctx := genericapirequest.NewContext()
	_, ok := genericapirequest.UIDFrom(ctx)
	if ok {
		t.Fatalf("Should not be ok because there is no UID on the context")
	}
	ctx = genericapirequest.WithUID(
		ctx,
		types.UID("testUID"),
	)
	_, ok = genericapirequest.UIDFrom(ctx)
	if !ok {
		t.Fatalf("Error getting UID")
	}
}
Exemplo n.º 2
0
// TestFillObjectMetaSystemFields validates that system populated fields are set on an object
func TestFillObjectMetaSystemFields(t *testing.T) {
	ctx := genericapirequest.NewDefaultContext()
	resource := metav1.ObjectMeta{}
	FillObjectMetaSystemFields(ctx, &resource)
	if resource.CreationTimestamp.Time.IsZero() {
		t.Errorf("resource.CreationTimestamp is zero")
	} else if len(resource.UID) == 0 {
		t.Errorf("resource.UID missing")
	}
	// verify we can inject a UID
	uid := uuid.NewUUID()
	ctx = genericapirequest.WithUID(ctx, uid)
	resource = metav1.ObjectMeta{}
	FillObjectMetaSystemFields(ctx, &resource)
	if resource.UID != uid {
		t.Errorf("resource.UID expected: %v, actual: %v", uid, resource.UID)
	}
}