@@ -26,20 +26,20 @@ import (
26
26
"github.com/stretchr/testify/assert"
27
27
)
28
28
29
- func TestDesiredConfigMap ( t * testing. T ) {
30
- expectedLables := map [string ]string {
29
+ func expectedLabels () map [ string ] string {
30
+ return map [string ]string {
31
31
"app.kubernetes.io/managed-by" : "opentelemetry-operator" ,
32
32
"app.kubernetes.io/instance" : "my-namespace.my-instance" ,
33
33
"app.kubernetes.io/part-of" : "opentelemetry" ,
34
34
"app.kubernetes.io/version" : "0.69.0" ,
35
+ "app.kubernetes.io/component" : "opentelemetry-opamp-bridge" ,
36
+ "app.kubernetes.io/name" : "my-instance-opamp-bridge" ,
35
37
}
38
+ }
36
39
37
- t .Run ("should return expected opamp-bridge config map" , func (t * testing.T ) {
38
- expectedLables ["app.kubernetes.io/component" ] = "opentelemetry-opamp-bridge"
39
- expectedLables ["app.kubernetes.io/name" ] = "my-instance-opamp-bridge"
40
-
41
- expectedData := map [string ]string {
42
- "remoteconfiguration.yaml" : `capabilities:
40
+ func TestDesiredConfigMap (t * testing.T ) {
41
+ data := map [string ]string {
42
+ "remoteconfiguration.yaml" : `capabilities:
43
43
AcceptsOpAMPConnectionSettings: true
44
44
AcceptsOtherConnectionSettings: true
45
45
AcceptsRemoteConfig: true
@@ -62,46 +62,72 @@ endpoint: ws://opamp-server:4320/v1/opamp
62
62
headers:
63
63
authorization: access-12345-token
64
64
` }
65
-
66
- opampBridge := v1alpha1.OpAMPBridge {
67
- ObjectMeta : metav1.ObjectMeta {
68
- Name : "my-instance" ,
69
- Namespace : "my-namespace" ,
65
+ tests := []struct {
66
+ description string
67
+ image string
68
+ expectedLabels func () map [string ]string
69
+ expectedData map [string ]string
70
+ }{
71
+ {
72
+ description : "should return expected opamp-bridge config map" ,
73
+ image : "ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:0.69.0" ,
74
+ expectedLabels : expectedLabels ,
75
+ expectedData : data ,
76
+ },
77
+ {
78
+ description : "should return expected opamp-bridge config map, sha256 image" ,
79
+ image : "ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:main@sha256:00738c3a6bca8f143995c9c89fd0c1976784d9785ea394fcdfe580fb18754e1e" ,
80
+ expectedLabels : func () map [string ]string {
81
+ ls := expectedLabels ()
82
+ ls ["app.kubernetes.io/version" ] = "main"
83
+ return ls
70
84
},
71
- Spec : v1alpha1.OpAMPBridgeSpec {
72
- Image : "ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:0.69.0" ,
73
- Endpoint : "ws://opamp-server:4320/v1/opamp" ,
74
- Headers : map [string ]string {"authorization" : "access-12345-token" },
75
- Capabilities : map [v1alpha1.OpAMPBridgeCapability ]bool {
76
- v1alpha1 .OpAMPBridgeCapabilityReportsStatus : true ,
77
- v1alpha1 .OpAMPBridgeCapabilityAcceptsRemoteConfig : true ,
78
- v1alpha1 .OpAMPBridgeCapabilityReportsEffectiveConfig : true ,
79
- v1alpha1 .OpAMPBridgeCapabilityReportsOwnTraces : true ,
80
- v1alpha1 .OpAMPBridgeCapabilityReportsOwnMetrics : true ,
81
- v1alpha1 .OpAMPBridgeCapabilityReportsOwnLogs : true ,
82
- v1alpha1 .OpAMPBridgeCapabilityAcceptsOpAMPConnectionSettings : true ,
83
- v1alpha1 .OpAMPBridgeCapabilityAcceptsOtherConnectionSettings : true ,
84
- v1alpha1 .OpAMPBridgeCapabilityAcceptsRestartCommand : true ,
85
- v1alpha1 .OpAMPBridgeCapabilityReportsHealth : true ,
86
- v1alpha1 .OpAMPBridgeCapabilityReportsRemoteConfig : true ,
85
+ expectedData : data ,
86
+ },
87
+ }
88
+
89
+ for _ , tc := range tests {
90
+ t .Run (tc .description , func (t * testing.T ) {
91
+ opampBridge := v1alpha1.OpAMPBridge {
92
+ ObjectMeta : metav1.ObjectMeta {
93
+ Name : "my-instance" ,
94
+ Namespace : "my-namespace" ,
87
95
},
88
- ComponentsAllowed : map [string ][]string {"receivers" : {"otlp" }, "processors" : {"memory_limiter" }, "exporters" : {"logging" }},
89
- },
90
- }
96
+ Spec : v1alpha1.OpAMPBridgeSpec {
97
+ Image : tc .image ,
98
+ Endpoint : "ws://opamp-server:4320/v1/opamp" ,
99
+ Headers : map [string ]string {"authorization" : "access-12345-token" },
100
+ Capabilities : map [v1alpha1.OpAMPBridgeCapability ]bool {
101
+ v1alpha1 .OpAMPBridgeCapabilityReportsStatus : true ,
102
+ v1alpha1 .OpAMPBridgeCapabilityAcceptsRemoteConfig : true ,
103
+ v1alpha1 .OpAMPBridgeCapabilityReportsEffectiveConfig : true ,
104
+ v1alpha1 .OpAMPBridgeCapabilityReportsOwnTraces : true ,
105
+ v1alpha1 .OpAMPBridgeCapabilityReportsOwnMetrics : true ,
106
+ v1alpha1 .OpAMPBridgeCapabilityReportsOwnLogs : true ,
107
+ v1alpha1 .OpAMPBridgeCapabilityAcceptsOpAMPConnectionSettings : true ,
108
+ v1alpha1 .OpAMPBridgeCapabilityAcceptsOtherConnectionSettings : true ,
109
+ v1alpha1 .OpAMPBridgeCapabilityAcceptsRestartCommand : true ,
110
+ v1alpha1 .OpAMPBridgeCapabilityReportsHealth : true ,
111
+ v1alpha1 .OpAMPBridgeCapabilityReportsRemoteConfig : true ,
112
+ },
113
+ ComponentsAllowed : map [string ][]string {"receivers" : {"otlp" }, "processors" : {"memory_limiter" }, "exporters" : {"logging" }},
114
+ },
115
+ }
91
116
92
- cfg := config .New ()
117
+ cfg := config .New ()
93
118
94
- params := manifests.Params {
95
- Config : cfg ,
96
- OpAMPBridge : opampBridge ,
97
- Log : logger ,
98
- }
119
+ params := manifests.Params {
120
+ Config : cfg ,
121
+ OpAMPBridge : opampBridge ,
122
+ Log : logger ,
123
+ }
99
124
100
- actual , err := ConfigMap (params )
101
- assert .NoError (t , err )
125
+ actual , err := ConfigMap (params )
126
+ assert .NoError (t , err )
102
127
103
- assert .Equal (t , "my-instance-opamp-bridge" , actual .Name )
104
- assert .Equal (t , expectedLables , actual .Labels )
105
- assert .Equal (t , expectedData , actual .Data )
106
- })
128
+ assert .Equal (t , "my-instance-opamp-bridge" , actual .Name )
129
+ assert .Equal (t , tc .expectedLabels (), actual .Labels )
130
+ assert .Equal (t , tc .expectedData , actual .Data )
131
+ })
132
+ }
107
133
}
0 commit comments