Skip to content

Commit 2b56293

Browse files
committed
Enable status plugin to make Prometheus test pass
Signed-off-by: Magnus Jungsbluth <[email protected]>
1 parent 3bf67fe commit 2b56293

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

filters/openpolicyagent/openpolicyagent_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func mockControlPlaneWithDiscoveryBundle(discoveryBundle string) (*opasdktest.Se
157157

158158
type controlPlaneConfig struct {
159159
enableJwtCaching bool
160+
enableStatus bool
160161
}
161162
type ControlPlaneOption func(*controlPlaneConfig)
162163

@@ -166,6 +167,12 @@ func WithJwtCaching(enabled bool) ControlPlaneOption {
166167
}
167168
}
168169

170+
func WithStatusPluginEnabled(enabled bool) ControlPlaneOption {
171+
return func(cfg *controlPlaneConfig) {
172+
cfg.enableStatus = enabled
173+
}
174+
}
175+
169176
func mockControlPlaneWithResourceBundle(opts ...ControlPlaneOption) (*opasdktest.Server, []byte) {
170177
opaControlPlane := opasdktest.MustNewServer(
171178
opasdktest.MockBundle("/bundles/test", map[string]string{
@@ -217,6 +224,15 @@ func mockControlPlaneWithResourceBundle(opts ...ControlPlaneOption) (*opasdktest
217224
`
218225
}
219226

227+
statusConfig := ""
228+
if cfg.enableStatus {
229+
statusConfig = `
230+
"status": {
231+
"console": true
232+
},
233+
`
234+
}
235+
220236
config := []byte(fmt.Sprintf(`{
221237
"services": {
222238
"test": {
@@ -229,14 +245,15 @@ func mockControlPlaneWithResourceBundle(opts ...ControlPlaneOption) (*opasdktest
229245
}
230246
},
231247
%s
248+
%s
232249
"plugins": {
233250
"envoy_ext_authz_grpc": {
234251
"path": "envoy/authz/allow",
235252
"dry-run": false,
236253
"skip-request-body-parse": false
237254
}
238255
}
239-
}`, opaControlPlane.URL(), jwtCacheConfig))
256+
}`, opaControlPlane.URL(), jwtCacheConfig, statusConfig))
240257

241258
return opaControlPlane, config
242259
}
@@ -1081,7 +1098,7 @@ func TestBodyExtractionUnknownBody(t *testing.T) {
10811098
}
10821099

10831100
func TestPrometheusPluginStatusGaugeRegistered(t *testing.T) {
1084-
_, config := mockControlPlaneWithResourceBundle()
1101+
_, config := mockControlPlaneWithResourceBundle(WithStatusPluginEnabled(true))
10851102

10861103
reg := prometheus.NewRegistry()
10871104
registry, err := NewOpenPolicyAgentRegistry(

0 commit comments

Comments
 (0)