Skip to content

Commit

Permalink
Test helper func for simulating pod running phase
Browse files Browse the repository at this point in the history
  • Loading branch information
abays committed Feb 19, 2024
1 parent 1c6e452 commit ce865a8
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions modules/common/test/helpers/pod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2024 Red Hat
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package helpers

import (
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)

// GetPod - retrieves a Pod resource.
//
// example usage:
//
// th.Pod(types.NamespacedName{Name: "test-pod", Namespace: "test-namespace"})
func (tc *TestHelper) GetPod(name types.NamespacedName) *corev1.Pod {
pod := &corev1.Pod{}
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(tc.K8sClient.Get(tc.Ctx, name, pod)).Should(gomega.Succeed())
}, tc.Timeout, tc.Interval).Should(gomega.Succeed())
return pod
}

// SimulatePodPhaseRunning retrieves the Pod and simulates
// a running phase for the Pod in a Kubernetes cluster.
//
// example usage:
//
// th.SimulatePodPhaseRunning(types.NamespacedName{Name: "test-pod", Namespace: "test-namespace"})
func (tc *TestHelper) SimulatePodPhaseRunning(name types.NamespacedName) {
gomega.Eventually(func(g gomega.Gomega) {
pod := tc.GetPod(name)
pod.Status.Phase = corev1.PodRunning
g.Expect(tc.K8sClient.Status().Update(tc.Ctx, pod)).To(gomega.Succeed())

}, tc.Timeout, tc.Interval).Should(gomega.Succeed())
tc.Logger.Info("Simulated pod running phase", "on", name)
}

0 comments on commit ce865a8

Please sign in to comment.