Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ettec committed Dec 17, 2024
1 parent 6e30294 commit 51fb7ca
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/capabilities/capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,11 @@ func Test_MustNewCapabilityInfo(t *testing.T) {
)
})
}

func Test_RemoteExecutableConfig_ApplyDefaults(t *testing.T) {
rec := &RemoteExecutableConfig{}
rec.ApplyDefaults()

assert.Equal(t, DefaultRegistrationRefresh, rec.RegistrationRefresh)
assert.Equal(t, DefaultRegistrationExpiry, rec.RegistrationExpiry)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"testing"
"time"

"github.com/hashicorp/go-plugin"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -435,3 +436,54 @@ func TestCapabilitiesRegistry_ConfigForCapabilities(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, expectedCapConfig, capConf)
}

func TestCapabilitiesRegistry_ConfigForCapability_RemoteExecutableConfig(t *testing.T) {
stopCh := make(chan struct{})
logger := logger.Test(t)
reg := mocks.NewCapabilitiesRegistry(t)

pluginName := "registry-test"
client, server := plugin.TestPluginGRPCConn(
t,
true,
map[string]plugin.Plugin{
pluginName: &testRegistryPlugin{
impl: reg,
brokerExt: &net.BrokerExt{
BrokerConfig: net.BrokerConfig{
StopCh: stopCh,
Logger: logger,
},
},
},
},
)

defer client.Close()
defer server.Stop()

regClient, err := client.Dispense(pluginName)
require.NoError(t, err)

rc, ok := regClient.(*capabilitiesRegistryClient)
require.True(t, ok)

capID := "some-cap@1.0.0"
donID := uint32(1)
wm, err := values.WrapMap(map[string]any{"hello": "world"})
require.NoError(t, err)

var rec capabilities.RemoteExecutableConfig
rec.ApplyDefaults()
expectedCapConfig := capabilities.CapabilityConfiguration{
DefaultConfig: wm,
RemoteExecutableConfig: &rec,
}
reg.On("ConfigForCapability", mock.Anything, capID, donID).Once().Return(expectedCapConfig, nil)

capConf, err := rc.ConfigForCapability(tests.Context(t), capID, donID)
require.NoError(t, err)
assert.Equal(t, expectedCapConfig, capConf)
assert.Equal(t, 30*time.Second, capConf.RemoteExecutableConfig.RegistrationRefresh)
assert.Equal(t, 2*time.Minute, capConf.RemoteExecutableConfig.RegistrationExpiry)
}

0 comments on commit 51fb7ca

Please sign in to comment.