Skip to content

Commit

Permalink
add tests for noEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
chengchengpei committed Jul 3, 2020
1 parent 76cbc8c commit 4558aa3
Showing 1 changed file with 143 additions and 0 deletions.
143 changes: 143 additions & 0 deletions operator/controllers/noengine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,146 @@ var _ = Describe("Create a Seldon Deployment without engine", func() {
})

})

var _ = Describe("Create a Seldon Deployment with engine", func() {
const timeout = time.Second * 30
const interval = time.Second * 1
By("Creating a resource")
It("should create a resource with defaults", func() {
Expect(k8sClient).NotTo(BeNil())
var modelType = machinelearningv1.MODEL
key := types.NamespacedName{
Name: "dep2-1",
Namespace: "default",
}
instance := &machinelearningv1.SeldonDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: key.Name,
Namespace: key.Namespace,
},
Spec: machinelearningv1.SeldonDeploymentSpec{
Name: "mydep2-1",
Predictors: []machinelearningv1.PredictorSpec{
{
Annotations: map[string]string{
"seldon.io/no-engine": "false",
},
Name: "p1",
ComponentSpecs: []*machinelearningv1.SeldonPodSpec{
{
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Image: "seldonio/mock_classifier:1.0",
Name: "classifier",
},
},
},
},
},
Graph: machinelearningv1.PredictiveUnit{
Name: "classifier",
Type: &modelType,
},
},
},
},
}

// Run Defaulter
instance.Default()

Expect(k8sClient.Create(context.Background(), instance)).Should(Succeed())
//time.Sleep(time.Second * 5)

fetched := &machinelearningv1.SeldonDeployment{}
Eventually(func() error {
err := k8sClient.Get(context.Background(), key, fetched)
return err
}, timeout, interval).Should(BeNil())
Expect(fetched.Name).Should(Equal("dep2-1"))

depKey := types.NamespacedName{
Name: machinelearningv1.GetDeploymentName(instance, instance.Spec.Predictors[0], instance.Spec.Predictors[0].ComponentSpecs[0], 0),
Namespace: "default",
}
depFetched := &appsv1.Deployment{}
Eventually(func() error {
err := k8sClient.Get(context.Background(), depKey, depFetched)
return err
}, timeout, interval).Should(BeNil())
Expect(len(depFetched.Spec.Template.Spec.Containers)).Should(Equal(2))

Expect(k8sClient.Delete(context.Background(), instance)).Should(Succeed())
})
})

var _ = Describe("Create a Seldon Deployment without seldon.io/no-engine annotation", func() {
const timeout = time.Second * 30
const interval = time.Second * 1
By("Creating a resource")
It("should create a resource with defaults", func() {
Expect(k8sClient).NotTo(BeNil())
var modelType = machinelearningv1.MODEL
key := types.NamespacedName{
Name: "dep2-2",
Namespace: "default",
}
instance := &machinelearningv1.SeldonDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: key.Name,
Namespace: key.Namespace,
},
Spec: machinelearningv1.SeldonDeploymentSpec{
Name: "mydep2-2",
Predictors: []machinelearningv1.PredictorSpec{
{
Name: "p1",
ComponentSpecs: []*machinelearningv1.SeldonPodSpec{
{
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Image: "seldonio/mock_classifier:1.0",
Name: "classifier",
},
},
},
},
},
Graph: machinelearningv1.PredictiveUnit{
Name: "classifier",
Type: &modelType,
},
},
},
},
}

// Run Defaulter
instance.Default()

Expect(k8sClient.Create(context.Background(), instance)).Should(Succeed())
//time.Sleep(time.Second * 5)

fetched := &machinelearningv1.SeldonDeployment{}
Eventually(func() error {
err := k8sClient.Get(context.Background(), key, fetched)
return err
}, timeout, interval).Should(BeNil())
Expect(fetched.Name).Should(Equal("dep2-2"))

depKey := types.NamespacedName{
Name: machinelearningv1.GetDeploymentName(instance, instance.Spec.Predictors[0], instance.Spec.Predictors[0].ComponentSpecs[0], 0),
Namespace: "default",
}
depFetched := &appsv1.Deployment{}
Eventually(func() error {
err := k8sClient.Get(context.Background(), depKey, depFetched)
return err
}, timeout, interval).Should(BeNil())
Expect(len(depFetched.Spec.Template.Spec.Containers)).Should(Equal(2))

Expect(k8sClient.Delete(context.Background(), instance)).Should(Succeed())
})
})

0 comments on commit 4558aa3

Please sign in to comment.