Skip to content

Commit

Permalink
Add/modify test for bundle failure while discovery success.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pushpalanka committed Jul 3, 2024
1 parent fb9df05 commit 6f69e3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions filters/openpolicyagent/openpolicyagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions filters/openpolicyagent/openpolicyagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func TestRegistry(t *testing.T) {
assert.Error(t, err, "should not work after close")
}

func TestOpaEngineStartFailureWithTimeout(t *testing.T) {
func TestOpaEngineStartFailureWithWrongBundle(t *testing.T) {
_, config := mockControlPlaneWithDiscoveryBundle("bundles/discovery-with-wrong-bundle")

registry := NewOpenPolicyAgentRegistry(WithReuseDuration(1*time.Second), WithCleanInterval(1*time.Second))
Expand All @@ -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) {
Expand Down Expand Up @@ -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))
}

Expand Down

0 comments on commit 6f69e3c

Please sign in to comment.