MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / TestAddToPod

Function TestAddToPod

internal/collector/instance_test.go:20–524  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestAddToPod(t *testing.T) {
21 // setupContext creates a context with the given feature gates enabled.
22 setupContext := func(logs, metrics bool) context.Context {
23 gate := feature.NewGate()
24 assert.NilError(t, gate.SetFromMap(map[string]bool{
25 feature.OpenTelemetryLogs: logs,
26 feature.OpenTelemetryMetrics: metrics,
27 }))
28 return feature.NewContext(context.Background(), gate)
29 }
30
31 // newPodTemplate returns a minimal PodTemplateSpec for testing.
32 newPodTemplate := func() *corev1.PodTemplateSpec {
33 return &corev1.PodTemplateSpec{}
34 }
35
36 // newConfigMap returns a ConfigMap with a name, as used by callers.
37 newConfigMap := func() *corev1.ConfigMap {
38 cm := &corev1.ConfigMap{}
39 cm.Name = "test-configmap"
40 return cm
41 }
42
43 // findContainer returns the collector container from the template, if present.
44 findContainer := func(template *corev1.PodTemplateSpec) *corev1.Container {
45 for i := range template.Spec.Containers {
46 if template.Spec.Containers[i].Name == naming.ContainerCollector {
47 return &template.Spec.Containers[i]
48 }
49 }
50 return nil
51 }
52
53 // findVolume returns the named volume from the template, if present.
54 findVolume := func(template *corev1.PodTemplateSpec, name string) *corev1.Volume {
55 for i := range template.Spec.Volumes {
56 if template.Spec.Volumes[i].Name == name {
57 return &template.Spec.Volumes[i]
58 }
59 }
60 return nil
61 }
62
63 t.Run("NoOpWhenFeaturesDisabled", func(t *testing.T) {
64 ctx := setupContext(false, false)
65 spec := &v1beta1.InstrumentationSpec{}
66 template := newPodTemplate()
67
68 AddToPod(ctx, spec, corev1.PullIfNotPresent, newConfigMap(),
69 template, nil, "", nil, false, false)
70
71 assert.Assert(t, cmp.Len(template.Spec.Containers, 0),
72 "expected no containers when features are disabled")
73 assert.Assert(t, cmp.Len(template.Spec.Volumes, 0),
74 "expected no volumes when features are disabled")
75 })
76
77 t.Run("NoOpWhenSpecIsNil", func(t *testing.T) {

Callers

nothing calls this directly

Calls 6

NewGateFunction · 0.92
NewContextFunction · 0.92
LenFunction · 0.92
AddToPodFunction · 0.85
SetFromMapMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected