Skip to content

Commit

Permalink
fix commented test
Browse files Browse the repository at this point in the history
  • Loading branch information
ramkrishankumarN committed Nov 19, 2024
1 parent e0a1040 commit 064307a
Showing 1 changed file with 64 additions and 65 deletions.
129 changes: 64 additions & 65 deletions src/apm/java_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,72 +28,71 @@ func TestJavaInjector_Inject(t *testing.T) {
expectedPod corev1.Pod
expectedErrStr string
}{
/*
{
name: "nothing",
},
{
name: "a container, no instrumentation",
pod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
expectedPod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
},
{
name: "a container, wrong instrumentation (not the correct lang)",
pod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
expectedPod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
inst: v1alpha2.Instrumentation{Spec: v1alpha2.InstrumentationSpec{Agent: v1alpha2.Agent{Language: "not-this"}}},
},
{
name: "a container, instrumentation with blank licenseKeySecret",
pod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
expectedPod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
expectedErrStr: "licenseKeySecret must not be blank",
inst: v1alpha2.Instrumentation{Spec: v1alpha2.InstrumentationSpec{Agent: v1alpha2.Agent{Language: "java"}}},
},
{
name: "a container, instrumentation",
pod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
expectedPod: corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
DescK8sAgentOperatorVersionLabelName: version.Get().Operator},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: "test",
Env: []corev1.EnvVar{
{Name: "JAVA_TOOL_OPTIONS", Value: " -javaagent:/newrelic-instrumentation/newrelic-agent.jar"},
{Name: "NEW_RELIC_APP_NAME", Value: "test"},
{Name: "NEW_RELIC_LABELS", Value: "operator:auto-injection"},
{Name: "NEW_RELIC_K8S_OPERATOR_ENABLED", Value: "true"},
{Name: "NEW_RELIC_LICENSE_KEY", ValueFrom: &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{LocalObjectReference: corev1.LocalObjectReference{Name: "newrelic-key-secret"}, Key: "new_relic_license_key", Optional: &vtrue}}},
},
VolumeMounts: []corev1.VolumeMount{{Name: "newrelic-instrumentation", MountPath: "/newrelic-instrumentation"}},
}},
InitContainers: []corev1.Container{{
Name: "newrelic-instrumentation-java",
Command: []string{"cp", "/newrelic-agent.jar", "/newrelic-instrumentation/newrelic-agent.jar"},
VolumeMounts: []corev1.VolumeMount{{Name: "newrelic-instrumentation", MountPath: "/newrelic-instrumentation"}},
}},
Volumes: []corev1.Volume{{Name: "newrelic-instrumentation", VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}}}},

{
name: "nothing",
},
{
name: "a container, no instrumentation",
pod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
expectedPod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
},
{
name: "a container, wrong instrumentation (not the correct lang)",
pod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
expectedPod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
inst: v1alpha2.Instrumentation{Spec: v1alpha2.InstrumentationSpec{Agent: v1alpha2.Agent{Language: "not-this"}}},
},
{
name: "a container, instrumentation with blank licenseKeySecret",
pod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
expectedPod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
expectedErrStr: "licenseKeySecret must not be blank",
inst: v1alpha2.Instrumentation{Spec: v1alpha2.InstrumentationSpec{Agent: v1alpha2.Agent{Language: "java"}}},
},
{
name: "a container, instrumentation",
pod: corev1.Pod{Spec: corev1.PodSpec{Containers: []corev1.Container{
{Name: "test"},
}}},
expectedPod: corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
DescK8sAgentOperatorVersionLabelName: version.Get().Operator},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: "test",
Env: []corev1.EnvVar{
{Name: "JAVA_TOOL_OPTIONS", Value: " -javaagent:/newrelic-instrumentation/newrelic-agent.jar"},
{Name: "NEW_RELIC_APP_NAME", Value: "test"},
{Name: "NEW_RELIC_LABELS", Value: "operator:auto-injection"},
{Name: "NEW_RELIC_K8S_OPERATOR_ENABLED", Value: "true"},
{Name: "NEW_RELIC_LICENSE_KEY", ValueFrom: &corev1.EnvVarSource{SecretKeyRef: &corev1.SecretKeySelector{LocalObjectReference: corev1.LocalObjectReference{Name: "newrelic-key-secret"}, Key: "new_relic_license_key", Optional: &vtrue}}},
},
VolumeMounts: []corev1.VolumeMount{{Name: "newrelic-instrumentation", MountPath: "/newrelic-instrumentation"}},
}},
inst: v1alpha2.Instrumentation{Spec: v1alpha2.InstrumentationSpec{Agent: v1alpha2.Agent{Language: "java"}, LicenseKeySecret: "newrelic-key-secret"}},
},
*/
InitContainers: []corev1.Container{{
Name: "newrelic-instrumentation-java",
Command: []string{"cp", "/newrelic-agent.jar", "/newrelic-instrumentation/newrelic-agent.jar"},
VolumeMounts: []corev1.VolumeMount{{Name: "newrelic-instrumentation", MountPath: "/newrelic-instrumentation"}},
}},
Volumes: []corev1.Volume{{Name: "newrelic-instrumentation", VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}}}},
}},
inst: v1alpha2.Instrumentation{Spec: v1alpha2.InstrumentationSpec{Agent: v1alpha2.Agent{Language: "java"}, LicenseKeySecret: "newrelic-key-secret"}},
},
{
name: "a container, instrumentation with added new relic labels",
pod: corev1.Pod{
Expand Down

0 comments on commit 064307a

Please sign in to comment.