Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Merge 2c1bed2 into 5be8c31
Browse files Browse the repository at this point in the history
  • Loading branch information
scothis authored Aug 30, 2023
2 parents 5be8c31 + 2c1bed2 commit b3065a7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
3 changes: 1 addition & 2 deletions testing/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ func NewFakeClientWrapper(client client.Client) *clientWrapper {
c.AddReactor("create", "*", func(action Action) (bool, runtime.Object, error) {
if createAction, ok := action.(CreateAction); ok && action.GetSubresource() == "" {
obj := createAction.GetObject()
if accessor, ok := obj.(metav1.ObjectMetaAccessor); ok {
objmeta := accessor.GetObjectMeta()
if objmeta, ok := obj.(metav1.Object); ok {
if objmeta.GetName() == "" && objmeta.GetGenerateName() != "" {
c.genCount++
// mutate the existing obj
Expand Down
48 changes: 48 additions & 0 deletions testing/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/vmware-labs/reconciler-runtime/reconcilers"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -321,6 +322,53 @@ func TestExpectConfig(t *testing.T) {
`Missing create for config "test": `,
},
},
"generate name": {
config: ExpectConfig{
ExpectCreates: []client.Object{
&resources.TestResource{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
GenerateName: "resource-",
},
},
},
},
operation: func(t *testing.T, ctx context.Context, c reconcilers.Config) {
r := &resources.TestResource{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
GenerateName: "resource-",
},
}

c.Create(ctx, r)
},
},
"generate name unstructured": {
config: ExpectConfig{
ExpectCreates: []client.Object{
&unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "testing.reconciler.runtime/v1",
"kind": "TestResource",
"metadata": map[string]interface{}{
"namespace": ns,
"generateName": "resource-",
},
},
},
},
},
operation: func(t *testing.T, ctx context.Context, c reconcilers.Config) {
u := &unstructured.Unstructured{}
u.SetAPIVersion("testing.reconciler.runtime/v1")
u.SetKind("TestResource")
u.SetNamespace(ns)
u.SetGenerateName("resource-")

c.Create(ctx, u)
},
},

"expected update": {
config: ExpectConfig{
Expand Down

0 comments on commit b3065a7

Please sign in to comment.