Skip to content

Commit

Permalink
Fix: Use 1.0.7
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <gaoce@caicloud.io>
  • Loading branch information
gaocegege committed May 17, 2019
1 parent 0b05e64 commit ddada57
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
62 changes: 59 additions & 3 deletions pkg/controller/v1alpha2/trial/trial_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
trialName = "foo"
namespace = "default"

timeout = time.Second * 5
timeout = time.Second * 20
)

var expectedRequest = reconcile.Request{NamespacedName: types.NamespacedName{Name: trialName, Namespace: namespace}}
Expand Down Expand Up @@ -57,6 +57,9 @@ func TestCreateTFJobTrial(t *testing.T) {
scheme: mgr.GetScheme(),
ManagerClient: mc,
updateStatusHandler: func(instance *trialsv1alpha2.Trial) error {
if !instance.IsCreated() {
t.Errorf("Expected got condition created")
}
return nil
},
})
Expand All @@ -80,6 +83,59 @@ func TestCreateTFJobTrial(t *testing.T) {
g.Expect(err).NotTo(gomega.HaveOccurred())
defer c.Delete(context.TODO(), instance)
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
}

func TestReconcileTFJobTrial(t *testing.T) {
g := gomega.NewGomegaWithT(t)
instance := newFakeTrialWithTFJob()

mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

mc := managerclientmock.NewMockClient(mockCtrl)
mc.EXPECT().CreateTrialInDB(gomock.Any()).Return(nil).AnyTimes()
mc.EXPECT().UpdateTrialStatusInDB(gomock.Any()).Return(nil).AnyTimes()

// Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a
// channel when it is finished.
mgr, err := manager.New(cfg, manager.Options{})
g.Expect(err).NotTo(gomega.HaveOccurred())
c := mgr.GetClient()

r := &ReconcileTrial{
Client: mgr.GetClient(),
scheme: mgr.GetScheme(),
ManagerClient: mc,
}

r.updateStatusHandler = func(instance *trialsv1alpha2.Trial) error {
if !instance.IsCreated() {
t.Errorf("Expected got condition created")
}
return r.updateStatus(instance)
}

recFn, requests := SetupTestReconcile(r)
g.Expect(add(mgr, recFn)).NotTo(gomega.HaveOccurred())

stopMgr, mgrStopped := StartTestManager(mgr, g)

defer func() {
close(stopMgr)
mgrStopped.Wait()
}()

// Create the Trial object and expect the Reconcile and Deployment to be created
err = c.Create(context.TODO(), instance)
// The instance object may not be a valid object because it might be missing some required fields.
// Please modify the instance object by adding required fields and then remove the following if statement.
if apierrors.IsInvalid(err) {
t.Logf("failed to create object, got an invalid object error: %v", err)
return
}
g.Expect(err).NotTo(gomega.HaveOccurred())
defer c.Delete(context.TODO(), instance)
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))

tfJob := &unstructured.Unstructured{}
bufSize := 1024
Expand All @@ -90,13 +146,13 @@ func TestCreateTFJobTrial(t *testing.T) {
g.Eventually(func() error { return c.Get(context.TODO(), tfJobKey, tfJob) }, timeout).
Should(gomega.Succeed())

// Delete the Deployment and expect Reconcile to be called for Deployment deletion
// Delete the TFJob and expect Reconcile to be called for TFJob deletion
g.Expect(c.Delete(context.TODO(), tfJob)).NotTo(gomega.HaveOccurred())
g.Eventually(requests, timeout).Should(gomega.Receive(gomega.Equal(expectedRequest)))
g.Eventually(func() error { return c.Get(context.TODO(), tfJobKey, tfJob) }, timeout).
Should(gomega.Succeed())

// Manually delete Deployment since GC isn't enabled in the test control plane
// Manually delete TFJob since GC isn't enabled in the test control plane
g.Eventually(func() error { return c.Delete(context.TODO(), tfJob) }, timeout).
Should(gomega.MatchError("tfjobs.kubeflow.org \"test\" not found"))
}
Expand Down
3 changes: 1 addition & 2 deletions test/scripts/v1alpha2/unit-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cd ${GO_DIR}

os=$(go env GOOS)
arch=$(go env GOARCH)
version=1.0.2 # latest stable version
version=1.0.7 # latest stable version
echo "os: ${os}, arch: ${arch}"

# download the release
Expand All @@ -46,6 +46,5 @@ curl -L -O "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${
tar -zxvf kubebuilder_${version}_${os}_${arch}.tar.gz
mv kubebuilder_${version}_${os}_${arch} /usr/local/kubebuilder
export PATH=$PATH:/usr/local/kubebuilder/bin

go test ./...
cd - > /dev/null

0 comments on commit ddada57

Please sign in to comment.