Skip to content

Commit

Permalink
update ut
Browse files Browse the repository at this point in the history
Signed-off-by: KfreeZ <[email protected]>
  • Loading branch information
KfreeZ committed Aug 12, 2024
1 parent d28e3a8 commit 9b67b39
Showing 1 changed file with 231 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,17 @@ var _ = Describe("GMConnector Controller", func() {
},
},
}
// Expect(k8sClient.Create(ctx, resource)).To(Succeed())
Eventually(func() error {
return k8sClient.Create(ctx, resource)
}, 60*time.Second, 1*time.Second).Should(Succeed())
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
}
})

AfterEach(func() {
// TODO(user): Cleanup logic after each test, like removing the resource instance.
Eventually(func() error {
resource := &mcv1alpha3.GMConnector{}
return k8sClient.Get(ctx, typeNamespacedName, resource)
}, 60*time.Second, 1*time.Second).Should(Succeed())
// TODO(user): Cleanup logic after each test, like removing the resource instance
resource := &mcv1alpha3.GMConnector{}
err := k8sClient.Get(ctx, typeNamespacedName, resource)
Expect(err).NotTo(HaveOccurred())

By("Cleanup the specific resource instance GMConnector")
resource := &mcv1alpha3.GMConnector{}
Expect(k8sClient.Get(ctx, typeNamespacedName, resource)).To(Succeed())
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
})
It("should successfully reconcile the resource", func() {
Expand All @@ -206,7 +200,97 @@ var _ = Describe("GMConnector Controller", func() {
Expect(err).NotTo(HaveOccurred())
// TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
// Example: If you expect a certain status condition after reconciliation, verify it here.

// update the resources
resource := &mcv1alpha3.GMConnector{}
Expect(k8sClient.Get(ctx, typeNamespacedName, resource)).To(Succeed())
resource.Spec = mcv1alpha3.GMConnectorSpec{
RouterConfig: mcv1alpha3.RouterConfig{
Name: "router",
ServiceName: "router-service",
Config: map[string]string{
"endpoint": "/",
},
},
Nodes: map[string]mcv1alpha3.Router{
"root": {
RouterType: "Sequence",
Steps: []mcv1alpha3.Step{
{
StepName: TeiEmbeddingGaudi,
Executor: mcv1alpha3.Executor{
InternalService: mcv1alpha3.GMCTarget{
NameSpace: "default",
ServiceName: "tei-embedding-service",
Config: map[string]string{
"endpoint": "/v1/tei-embeddings",
"MODEL_ID": "somemodel",
},
IsDownstreamService: true,
},
},
},
{
StepName: DataPrep,
Executor: mcv1alpha3.Executor{
InternalService: mcv1alpha3.GMCTarget{
NameSpace: "default",
ServiceName: "dataPrep-service",
Config: map[string]string{
"endpoint": "/v1/vec",
},
IsDownstreamService: true,
},
},
},
{
StepName: WebRetriever,
Executor: mcv1alpha3.Executor{
InternalService: mcv1alpha3.GMCTarget{
NameSpace: "default",
ServiceName: "webretriever-service",
Config: map[string]string{
"endpoint": "/v1/retrv",
"REDIS_URL": "vector-service",
"TEI_EMBEDDING_ENDPOINT": "tei-embedding-service",
},
},
},
},
{
StepName: TgiGaudi,
Executor: mcv1alpha3.Executor{
InternalService: mcv1alpha3.GMCTarget{
NameSpace: "default",
ServiceName: "tgiguadi-service-name",
Config: map[string]string{
"endpoint": "/generate",
},
IsDownstreamService: true,
},
},
},
{
StepName: Llm,
Executor: mcv1alpha3.Executor{
InternalService: mcv1alpha3.GMCTarget{
NameSpace: "default",
ServiceName: "llm-service",
Config: map[string]string{
"endpoint": "/v1/llm",
"TGI_LLM_ENDPOINT": "tgi-service-name",
},
},
},
},
},
},
},
}

Expect(k8sClient.Update(ctx, resource)).To(Succeed())
})

})
})

Expand All @@ -233,3 +317,139 @@ func TestGetServiceURL(t *testing.T) {
t.Errorf("Expected URL: %s, but got: %s", expectedURL, actualURL)
}
}
func TestIsMetadataChanged(t *testing.T) {
oldObject := &metav1.ObjectMeta{
Name: "fido",
Namespace: "sprint",
Labels: map[string]string{
"key1": "value1",
"key2": "value2",
},
Generation: 1,
}

newObject := &metav1.ObjectMeta{
Name: "dido",
Namespace: "sprint",
Labels: map[string]string{
"key1": "value1",
"key2": "value2",
},
Generation: 1,
}

changed := isMetadataChanged(nil, newObject)
if !changed {
t.Errorf("Expected metadata changes to be detected, but got false")
}

changed = isMetadataChanged(oldObject, nil)
if !changed {
t.Errorf("Expected metadata changes to be detected, but got false")
}

//check name
changed = isMetadataChanged(oldObject, newObject)
if !changed {
t.Errorf("Expected metadata changes to be detected, but got false")
}

//check name space
newObject = &metav1.ObjectMeta{
Name: "fido",
Namespace: "coca-cola",
Labels: map[string]string{
"key1": "value1",
"key2": "value2",
},
}
changed = isMetadataChanged(oldObject, newObject)
if !changed {
t.Errorf("Expected metadata changes to not be detected, but got true")
}

// check label
newObject = &metav1.ObjectMeta{
Name: "fido",
Namespace: "sprint",
Labels: map[string]string{
"key1": "value1",
"key2": "value2",
"key3": "value3",
},
DeletionTimestamp: &metav1.Time{
Time: time.Now(),
},
}
changed = isMetadataChanged(oldObject, newObject)
if !changed {
t.Errorf("Expected metadata changes to not be detected, but got true")
}

newObject.Labels = map[string]string{
"key1": "value1",
"key2": "value4",
}
changed = isMetadataChanged(oldObject, newObject)
if !changed {
t.Errorf("Expected metadata changes to not be detected, but got true")
}

newObject.Labels = map[string]string{
"key1": "value1",
}
changed = isMetadataChanged(oldObject, newObject)
if !changed {
t.Errorf("Expected metadata changes to not be detected, but got true")
}

// check deletion timestamp
newObject = &metav1.ObjectMeta{
Name: "fido",
Namespace: "sprint",
Labels: map[string]string{
"key1": "value1",
"key2": "value2",
},
DeletionTimestamp: &metav1.Time{
Time: time.Now(),
},
}
changed = isMetadataChanged(oldObject, newObject)
if !changed {
t.Errorf("Expected metadata changes to not be detected, but got true")
}

// check annotation
newObject = &metav1.ObjectMeta{
Name: "fido",
Namespace: "sprint",
Labels: map[string]string{
"key1": "value1",
"key2": "value2",
},
Annotations: map[string]string{
"key1": "value1",
"key2": "value2",
},
}
changed = isMetadataChanged(oldObject, newObject)
if changed {
t.Errorf("Expected metadata changes to not be detected, but got true")
}

// check generation
newObject = &metav1.ObjectMeta{
Name: "fido",
Namespace: "sprint",
Labels: map[string]string{
"key1": "value1",
"key2": "value2",
},
Generation: 2,
}
changed = isMetadataChanged(oldObject, newObject)
if changed {
t.Errorf("Expected metadata changes to not be detected, but got true")
}
}

0 comments on commit 9b67b39

Please sign in to comment.