Skip to content

Commit 76fd8b3

Browse files
committed
fix envtest for experiment-controller
1 parent 53ed06b commit 76fd8b3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pkg/controller.v1beta1/experiment/experiment_controller_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import (
4343
trialsv1beta1 "github.com/kubeflow/katib/pkg/apis/controller/trials/v1beta1"
4444
"github.com/kubeflow/katib/pkg/controller.v1beta1/consts"
4545
experimentUtil "github.com/kubeflow/katib/pkg/controller.v1beta1/experiment/util"
46-
util "github.com/kubeflow/katib/pkg/controller.v1beta1/util"
46+
"github.com/kubeflow/katib/pkg/controller.v1beta1/util"
4747
manifestmock "github.com/kubeflow/katib/pkg/mock/v1beta1/experiment/manifest"
4848
suggestionmock "github.com/kubeflow/katib/pkg/mock/v1beta1/experiment/suggestion"
4949
)
@@ -163,7 +163,7 @@ func TestReconcile(t *testing.T) {
163163

164164
mockCtrl2 := gomock.NewController(t)
165165
defer mockCtrl2.Finish()
166-
mockGenerator := manifestmock.NewMockGenerator(mockCtrl)
166+
mockGenerator := manifestmock.NewMockGenerator(mockCtrl2)
167167

168168
// Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a
169169
// channel when it is finished.
@@ -217,7 +217,6 @@ func TestReconcile(t *testing.T) {
217217
nil).AnyTimes()
218218

219219
suggestionRestartNo := newFakeSuggestion()
220-
221220
mockSuggestion.EXPECT().GetOrCreateSuggestion(gomock.Any(), gomock.Any()).Return(
222221
suggestionRestartNo, nil).AnyTimes()
223222

@@ -304,10 +303,10 @@ func TestReconcile(t *testing.T) {
304303
)
305304

306305
// Test 1 - Regural experiment run
307-
instance := newFakeInstance()
308306

309307
// Create the suggestion with NeverResume
310-
g.Expect(c.Create(context.TODO(), suggestionRestartNo)).NotTo(gomega.HaveOccurred())
308+
suggestionInstance := newFakeSuggestion()
309+
g.Expect(c.Create(context.TODO(), suggestionInstance)).NotTo(gomega.HaveOccurred())
311310
// Manually update suggestion's status with 3 suggestions
312311
// Ones redundant trial is deleted, suggestion status must be updated
313312
g.Eventually(func() error {
@@ -321,6 +320,7 @@ func TestReconcile(t *testing.T) {
321320
}, timeout).ShouldNot(gomega.HaveOccurred())
322321

323322
// Create the experiment
323+
instance := newFakeInstance()
324324
g.Expect(c.Create(context.TODO(), instance)).NotTo(gomega.HaveOccurred())
325325

326326
// Expect that experiment status is running
@@ -382,7 +382,7 @@ func TestReconcile(t *testing.T) {
382382
}, timeout).Should(gomega.BeTrue())
383383

384384
// Delete the suggestion
385-
g.Expect(c.Delete(context.TODO(), suggestionRestartNo)).NotTo(gomega.HaveOccurred())
385+
g.Expect(c.Delete(context.TODO(), suggestionInstance)).NotTo(gomega.HaveOccurred())
386386

387387
// Expect that suggestion with ResumePolicy = NeverResume is deleted
388388
g.Eventually(func() bool {
@@ -391,7 +391,9 @@ func TestReconcile(t *testing.T) {
391391
}, timeout).Should(gomega.BeTrue())
392392

393393
// Create the suggestion with ResumePolicy = FromVolume
394-
g.Expect(c.Create(context.TODO(), suggestionRestartYes)).NotTo(gomega.HaveOccurred())
394+
suggestionInstance = newFakeSuggestion()
395+
suggestionInstance.Spec.ResumePolicy = experimentsv1beta1.FromVolume
396+
g.Expect(c.Create(context.TODO(), suggestionInstance)).NotTo(gomega.HaveOccurred())
395397
// Expect that suggestion is created
396398
g.Eventually(func() bool {
397399
return errors.IsNotFound(c.Get(context.TODO(),
@@ -437,7 +439,7 @@ func TestReconcile(t *testing.T) {
437439
}, timeout).Should(gomega.BeTrue())
438440

439441
// Delete the suggestion
440-
g.Expect(c.Delete(context.TODO(), suggestionRestartYes)).NotTo(gomega.HaveOccurred())
442+
g.Expect(c.Delete(context.TODO(), suggestionInstance)).NotTo(gomega.HaveOccurred())
441443

442444
// Expect that suggestion with ResumePolicy = FromVolume is deleted
443445
g.Eventually(func() bool {

0 commit comments

Comments
 (0)