Skip to content

Commit

Permalink
[test] Add CreatePod() test helper
Browse files Browse the repository at this point in the history
CreatePod creates a new Pod resource with the provided annotations and spec.

Example usage:

~~~
annotations := map[string]string{}{"key": "value"}
spec := map[string]interface{}{"key": "value"}
p := th.CreatePod(types.NamespacedName{Namespace: "default", Name: "example"}, annotations, spec)
~~~

Signed-off-by: Martin Schuppert <[email protected]>
  • Loading branch information
stuggi committed Dec 11, 2024
1 parent 6dc9fd0 commit 5c9fddd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions modules/common/test/helpers/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// GetPod - retrieves a Pod resource.
Expand Down Expand Up @@ -84,3 +85,25 @@ func (tc *TestHelper) SimulatePodReady(name types.NamespacedName) {
}, tc.Timeout, tc.Interval).Should(gomega.Succeed())
tc.Logger.Info("Simulated pod ready state", "on", name)
}

// CreatePod creates a new Pod resource with the provided annotations and spec.
//
// Example usage:
//
// annotations := map[string]string{}{"key": "value"}
// spec := map[string]interface{}{"key": "value"}
// p := th.CreatePod(types.NamespacedName{Namespace: "default", Name: "example"}, annotations, spec)
func (tc *TestHelper) CreatePod(name types.NamespacedName, annotations map[string]string, spec map[string]interface{}) client.Object {
raw := map[string]interface{}{
"apiVersion": "v1",
"kind": "Pod",
"metadata": map[string]interface{}{
"annotations": annotations,
"name": name.Name,
"namespace": name.Namespace,
},
"spec": spec,
}

return tc.CreateUnstructured(raw)
}

0 comments on commit 5c9fddd

Please sign in to comment.