-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add dedicated test for resource modifications
- Loading branch information
Showing
4 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package k8sresources_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestK8sresources(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "K8s Resources Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// SPDX-FileCopyrightText: Copyright 2024 Dash0 Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package k8sresources | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
. "github.com/dash0hq/dash0-operator/test/util" | ||
) | ||
|
||
// Maintenance note: There is some overlap of test cases between this file and dash0_webhook_test.go. This is | ||
// intentional. However, this test should be used for more fine-grained test cases, while dash0_webhook_test.go should | ||
// be used to verify external effects (recording events etc.) that cannot be covered in this test. | ||
|
||
var _ = Describe("Dash0 Webhook", func() { | ||
|
||
ctx := context.Background() | ||
|
||
Context("when mutating new deployments", func() { | ||
It("should inject Dash into a new basic deployment", func() { | ||
deployment := BasicDeployment(TestNamespaceName, DeploymentName) | ||
result := ModifyPodSpec(&deployment.Spec.Template.Spec, log.FromContext(ctx)) | ||
|
||
Expect(result).To(BeTrue()) | ||
VerifyModifiedDeployment(deployment, DeploymentExpectations{ | ||
Volumes: 1, | ||
Dash0VolumeIdx: 0, | ||
InitContainers: 1, | ||
Dash0InitContainerIdx: 0, | ||
Containers: []ContainerExpectations{{ | ||
VolumeMounts: 1, | ||
Dash0VolumeMountIdx: 0, | ||
EnvVars: 1, | ||
NodeOptionsEnvVarIdx: 0, | ||
}}, | ||
}) | ||
}) | ||
|
||
It("should inject Dash into a new deployment that has multiple Containers, and already has Volumes and init Containers", func() { | ||
deployment := DeploymentWithMoreBellsAndWhistles(TestNamespaceName, DeploymentName) | ||
result := ModifyPodSpec(&deployment.Spec.Template.Spec, log.FromContext(ctx)) | ||
|
||
Expect(result).To(BeTrue()) | ||
VerifyModifiedDeployment(deployment, DeploymentExpectations{ | ||
Volumes: 3, | ||
Dash0VolumeIdx: 2, | ||
InitContainers: 3, | ||
Dash0InitContainerIdx: 2, | ||
Containers: []ContainerExpectations{ | ||
{ | ||
VolumeMounts: 2, | ||
Dash0VolumeMountIdx: 1, | ||
EnvVars: 2, | ||
NodeOptionsEnvVarIdx: 1, | ||
}, | ||
{ | ||
VolumeMounts: 3, | ||
Dash0VolumeMountIdx: 2, | ||
EnvVars: 3, | ||
NodeOptionsEnvVarIdx: 2, | ||
}, | ||
}, | ||
}) | ||
}) | ||
|
||
It("should update existing Dash artifacts in a new deployment", func() { | ||
deployment := DeploymentWithExistingDash0Artifacts(TestNamespaceName, DeploymentName) | ||
result := ModifyPodSpec(&deployment.Spec.Template.Spec, log.FromContext(ctx)) | ||
|
||
Expect(result).To(BeTrue()) | ||
VerifyModifiedDeployment(deployment, DeploymentExpectations{ | ||
Volumes: 3, | ||
Dash0VolumeIdx: 1, | ||
InitContainers: 3, | ||
Dash0InitContainerIdx: 1, | ||
Containers: []ContainerExpectations{ | ||
{ | ||
VolumeMounts: 2, | ||
Dash0VolumeMountIdx: 1, | ||
EnvVars: 2, | ||
NodeOptionsEnvVarIdx: 1, | ||
NodeOptionsUsesValueFrom: true, | ||
}, | ||
{ | ||
VolumeMounts: 3, | ||
Dash0VolumeMountIdx: 1, | ||
EnvVars: 3, | ||
NodeOptionsEnvVarIdx: 1, | ||
NodeOptionsValue: "--require /opt/dash0/instrumentation/node.js/node_modules/@dash0/opentelemetry/src/index.js --require something-else --experimental-modules", | ||
}, | ||
}, | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters