Skip to content

Commit

Permalink
chore: use testenv in expression_integration_test.go
Browse files Browse the repository at this point in the history
Signed-off-by: Kumar Mallikarjuna <[email protected]>
  • Loading branch information
kumar-mallikarjuna committed Dec 18, 2024
1 parent 9bef583 commit ffc298b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
57 changes: 42 additions & 15 deletions pkg/test/expression_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,66 @@ import (
)

func buildTestStep(t *testing.T) *Step {
return &Step{
Name: t.Name(),
Index: 0,
Logger: testutils.NewTestLogger(t, t.Name()),
Client: func(bool) (client.Client, error) {
return testenv.Client, nil
},
DiscoveryClient: func() (discovery.DiscoveryInterface, error) {
return testenv.DiscoveryClient, nil
},
}
}

func TestAssertExpressions(t *testing.T) {
codednsDeployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "coredns",
Namespace: "kube-system",
Labels: map[string]string{"k8s-app": "kube-dns"},
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{"k8s-app": "kube-dns"},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"k8s-app": "kube-dns"},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "coredns",
Image: "registry.k8s.io/coredns/coredns:v1.11.1",
},
},
},
},
},
}
metricServerPod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "metrics-server-xyz-pqr",
Namespace: "kube-system",
Labels: map[string]string{
"app": "metrics-server",
"k8s-app": "metrics-server",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "metrics-server",
Image: "registry.k8s.io/metrics-server/metrics-server:v0.7.2",
},
},
},
}

assert.NoError(t, testenv.Client.Create(context.TODO(), codednsDeployment))
assert.NoError(t, testenv.Client.Create(context.TODO(), metricServerPod))

return &Step{
Name: t.Name(),
Index: 0,
Logger: testutils.NewTestLogger(t, t.Name()),
Client: func(bool) (client.Client, error) {
return testenv.Client, nil
},
DiscoveryClient: func() (discovery.DiscoveryInterface, error) {
return testenv.DiscoveryClient, nil
},
}
}

func TestAssertExpressions(t *testing.T) {
testCases := []struct {
name string
loadingFailed bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ resourceRefs:
ref: metricsServer
assertAll:
- celExpr: "coredns.metadata.name == 'coredns'"
- celExpr: "metricsServer.metadata.labels['app'] == 'metrics-server'"
- celExpr: "metricsServer.metadata.labels['k8s-app'] == 'metrics-server'"
timeout: 1
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ resourceRefs:
ref: metricsServer
assertAll:
- celExpr: "coredns.metadata.name == 'metrics-server'"
- celExpr: "metricsServer.metadata.labels['app'] == 'metrics-server'"
- celExpr: "metricsServer.metadata.labels['k8s-app'] == 'metrics-server'"
timeout: 1
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ resourceRefs:
ref: metricsServer
assertAny:
- celExpr: "coredns.metadata.name == 'coredns'"
- celExpr: "metricsServer.metadata.labels['app'] == 'metrics-server-1.6'"
- celExpr: "metricsServer.metadata.labels['k8s-app'] == 'metrics-server-1.6'"
timeout: 1
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ resourceRefs:
ref: metricsServer
assertAny:
- celExpr: "coredns.metadata.name == 'metrics-server'"
- celExpr: "metricsServer.metadata.labels['app'] == 'metrics-server-1.6'"
- celExpr: "metricsServer.metadata.labels['k8s-app'] == 'metrics-server-1.6'"
timeout: 1

0 comments on commit ffc298b

Please sign in to comment.