@@ -76,6 +76,89 @@ func TestNativeSelfInitRequestsUseJSONPayload(t *testing.T) {
7676 }
7777}
7878
79+ func TestWorkloadObservabilityMetricsOnlyListenerIsVersionAware (t * testing.T ) {
80+ t .Parallel ()
81+
82+ tests := []struct {
83+ name string
84+ version string
85+ existingContext string
86+ wantConfig bool
87+ wantListener bool
88+ }{
89+ {
90+ name : "pre 2.5 omits metrics only listener" ,
91+ version : "2.4.4" ,
92+ wantConfig : true ,
93+ wantListener : false ,
94+ },
95+ {
96+ name : "2.5 enables metrics only listener" ,
97+ version : "2.5.0" ,
98+ wantConfig : true ,
99+ wantListener : true ,
100+ },
101+ {
102+ name : "patch upgrade source keeps metrics only listener" ,
103+ version : "2.5.3" ,
104+ wantConfig : true ,
105+ wantListener : true ,
106+ },
107+ {
108+ name : "invalid version omits metrics only listener" ,
109+ version : "custom" ,
110+ wantConfig : true ,
111+ wantListener : false ,
112+ },
113+ {
114+ name : "existing cluster leaves observability unmanaged" ,
115+ version : "2.5.4" ,
116+ existingContext : "kind-existing" ,
117+ wantConfig : false ,
118+ wantListener : false ,
119+ },
120+ }
121+
122+ for _ , tt := range tests {
123+ t .Run (tt .name , func (t * testing.T ) {
124+ t .Parallel ()
125+
126+ native := & nativeScenarioContext {
127+ opts : Config {ExistingClusterContext : tt .existingContext },
128+ }
129+ got := native .workloadObservability (tt .version )
130+ if ! tt .wantConfig {
131+ if got != nil {
132+ t .Fatalf ("workloadObservability(%q) = %#v, want nil" , tt .version , got )
133+ }
134+ return
135+ }
136+ if got == nil || got .Metrics == nil {
137+ t .Fatalf ("workloadObservability(%q) missing metrics config: %#v" , tt .version , got )
138+ }
139+ if got .Metrics .Enabled != true {
140+ t .Fatalf ("metrics enabled = %v, want true" , got .Metrics .Enabled )
141+ }
142+ if got .Metrics .ScrapeProfile != "Active" {
143+ t .Fatalf ("scrape profile = %q, want Active" , got .Metrics .ScrapeProfile )
144+ }
145+ listener := got .Metrics .MetricsOnlyListener
146+ if ! tt .wantListener {
147+ if listener != nil {
148+ t .Fatalf ("metrics only listener = %#v, want nil" , listener )
149+ }
150+ return
151+ }
152+ if listener == nil || listener .Enabled == nil || ! * listener .Enabled {
153+ t .Fatalf ("metrics only listener not enabled: %#v" , listener )
154+ }
155+ if listener .UnauthenticatedMetricsAccess == nil || ! * listener .UnauthenticatedMetricsAccess {
156+ t .Fatalf ("unauthenticated metrics access not enabled: %#v" , listener )
157+ }
158+ })
159+ }
160+ }
161+
79162func TestPhaseMeasurements (t * testing.T ) {
80163 t .Parallel ()
81164
0 commit comments