Skip to content

Commit

Permalink
fix ut
Browse files Browse the repository at this point in the history
  • Loading branch information
Eikykun committed Dec 8, 2023
1 parent fd291b3 commit 067febb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

appsv1alpha1 "kusionstack.io/operating/apis/apps/v1alpha1"
"kusionstack.io/operating/pkg/utils/inject"
)

var (
env *envtest.Environment
mgr manager.Manager
c client.Client
env *envtest.Environment
mgr manager.Manager
c client.Client
request chan reconcile.Request

ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup
Expand Down Expand Up @@ -77,6 +80,7 @@ func TestMain(m *testing.M) {
}()
<-time.After(time.Second * 5)
code := m.Run()
Stop()
env.Stop()
os.Exit(code)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ import (

func TestPodTransitionRule(t *testing.T) {
g := gomega.NewGomegaWithT(t)
defer Stop()
<-time.After(1 * time.Second)
var pods []*corev1.Pod
pods = append(pods,
genDefaultPod("default", "pod-test-1"),
Expand Down Expand Up @@ -170,10 +168,8 @@ func TestPodTransitionRule(t *testing.T) {

func TestWebhookRule(t *testing.T) {
g := gomega.NewGomegaWithT(t)

stop, finish := RunHttpServer(handleHttpAlwaysSuccess, "8888")
defer func() {
Stop()
stop <- struct{}{}
<-finish
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var (
}
timeout = int64(60)
interval = int64(5)
pollRS = &appsv1alpha1.PodTransitionRule{
poRS = &appsv1alpha1.PodTransitionRule{
ObjectMeta: metav1.ObjectMeta{
Name: "podtransitionrule-poll",
Namespace: "default",
Expand Down Expand Up @@ -212,6 +212,7 @@ func TestWebhookPollFail(t *testing.T) {
}
subjects := sets.NewString("test-pod-a", "test-pod-b", "test-pod-c")
g := gomega.NewGomegaWithT(t)
pollRS := poRS.DeepCopy()
webhooks := GetWebhook(pollRS)
g.Expect(len(webhooks)).Should(gomega.BeEquivalentTo(1))
web := webhooks[0]
Expand Down Expand Up @@ -276,6 +277,7 @@ func TestWebhookPoll(t *testing.T) {
}
subjects := sets.NewString("test-pod-a", "test-pod-b", "test-pod-c")
g := gomega.NewGomegaWithT(t)
pollRS := poRS.DeepCopy()
webhooks := GetWebhook(pollRS)
g.Expect(len(webhooks)).Should(gomega.BeEquivalentTo(1))
web := webhooks[0]
Expand All @@ -302,7 +304,7 @@ func TestWebhookPoll(t *testing.T) {
<-time.After(5 * time.Second)
state = &appsv1alpha1.RuleState{Name: web.RuleName, WebhookStatus: res.RuleState.WebhookStatus}
pollRS.Status.RuleStates = []*appsv1alpha1.RuleState{state}
webhooks = GetWebhook(pollRS)
webhooks = GetWebhook(pollRS.DeepCopy())
web = webhooks[0]
res = web.Do(targets, subjects)
rj, _ = json.Marshal(res)
Expand All @@ -314,7 +316,7 @@ func TestWebhookPoll(t *testing.T) {
<-time.After(5 * time.Second)
state = &appsv1alpha1.RuleState{Name: web.RuleName, WebhookStatus: res.RuleState.WebhookStatus}
pollRS.Status.RuleStates = []*appsv1alpha1.RuleState{state}
webhooks = GetWebhook(pollRS)
webhooks = GetWebhook(pollRS.DeepCopy())
web = webhooks[0]
res = web.Do(targets, subjects)
rj, _ = json.Marshal(res)
Expand Down

0 comments on commit 067febb

Please sign in to comment.