From 0f696aa6851712cecbb9423e56c8c74b69f5585d Mon Sep 17 00:00:00 2001 From: Pushpalanka Jayawardhana Date: Wed, 3 Jul 2024 16:28:27 +0200 Subject: [PATCH] Add/modify test for bundle failure while discovery success. --- filters/openpolicyagent/openpolicyagent.go | 10 +++++----- filters/openpolicyagent/openpolicyagent_test.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/filters/openpolicyagent/openpolicyagent.go b/filters/openpolicyagent/openpolicyagent.go index d39050bd7c..c0c56c0063 100644 --- a/filters/openpolicyagent/openpolicyagent.go +++ b/filters/openpolicyagent/openpolicyagent.go @@ -491,15 +491,15 @@ func (opa *OpenPolicyAgentInstance) Start(ctx context.Context, timeout time.Dura // Register listener for "bundle" plugin opa.manager.RegisterPluginStatusListener("bundlelistener", func(status map[string]*plugins.Status) { if _, exists := status["bundle"]; exists { - registerBundleListenerOnce.Do(func() { - bundlePlugin := bundle.Lookup(opa.manager) - if bundlePlugin != nil { + bundlePlugin := bundle.Lookup(opa.manager) + if bundlePlugin != nil { + registerBundleListenerOnce.Do(func() { bundlePlugin.Register("startuplistener", func(status bundle.Status) { handleStatusErrors(status, failed, "bundle plugin") }) - } - }) + }) + } } }) defer opa.manager.UnregisterPluginStatusListener("bundlelistener") diff --git a/filters/openpolicyagent/openpolicyagent_test.go b/filters/openpolicyagent/openpolicyagent_test.go index 3544461e7a..aaa2d55694 100644 --- a/filters/openpolicyagent/openpolicyagent_test.go +++ b/filters/openpolicyagent/openpolicyagent_test.go @@ -258,7 +258,7 @@ func TestOpaEngineStartFailureWithTimeout(t *testing.T) { err = engine.Start(ctx, cfg.startupTimeout) assert.True(t, engine.stopped) - assert.Contains(t, err.Error(), "one or more open policy agent plugins failed to start in 1s") + assert.Contains(t, err.Error(), "bundle plugin failed: bundle_error") } func TestOpaActivationSuccessWithDiscovery(t *testing.T) { @@ -339,7 +339,7 @@ func TestOpaActivationTimeOutWithDiscoveryPointingWrongBundle(t *testing.T) { instance, err := registry.NewOpenPolicyAgentInstance("test", *cfg, "testfilter") assert.Nil(t, instance) - assert.Contains(t, err.Error(), "one or more open policy agent plugins failed to start in 1s with error: context deadline exceeded") + assert.Contains(t, err.Error(), "bundle plugin failed: bundle_error") assert.Equal(t, 0, len(registry.instances)) }