Skip to content

Commit

Permalink
Validate plugin type
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Putilov <[email protected]>
  • Loading branch information
m8rge committed Sep 4, 2020
1 parent 235480d commit edd05a4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
13 changes: 9 additions & 4 deletions plugin/storage/grpc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Configuration struct {
PluginLogLevel string `yaml:"log-level" mapstructure:"log_level"`
}

// Build instantiates a StoragePlugin
// Build instantiates a PluginServices
func (c *Configuration) Build() (*PluginServices, error) {
// #nosec G204
cmd := exec.Command(c.PluginBinary, "--config", c.PluginConfigurationFile)
Expand Down Expand Up @@ -67,9 +67,14 @@ func (c *Configuration) Build() (*PluginServices, error) {
if !ok {
return nil, fmt.Errorf("unexpected type for plugin \"%s\"", shared.StoragePluginIdentifier)
}

archiveStoragePlugin := raw.(shared.ArchiveStoragePlugin)
capabilities := raw.(shared.PluginCapabilities)
archiveStoragePlugin, ok := raw.(shared.ArchiveStoragePlugin)
if !ok {
return nil, fmt.Errorf("unexpected type for plugin \"%s\"", shared.StoragePluginIdentifier)
}
capabilities, ok := raw.(shared.PluginCapabilities)
if !ok {
return nil, fmt.Errorf("unexpected type for plugin \"%s\"", shared.StoragePluginIdentifier)
}

return &PluginServices{
Store: storagePlugin,
Expand Down
28 changes: 28 additions & 0 deletions plugin/storage/grpc/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,34 @@ func TestGRPCStorageFactory_CapabilitiesDisabled(t *testing.T) {
assert.Nil(t, writer)
}

func TestGRPCStorageFactory_CapabilitiesError(t *testing.T) {
f := NewFactory()
v := viper.New()
f.InitFromViper(v)

capabilities := new(mocks.PluginCapabilities)
customError := errors.New("made-up error")
capabilities.On("Capabilities").
Return(nil, customError)

f.builder = &mockPluginBuilder{
plugin: &mockPlugin{
capabilities: capabilities,
archiveWriter: new(spanStoreMocks.Writer),
archiveReader: new(spanStoreMocks.Reader),
},
}
assert.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop()))

assert.NotNil(t, f.store)
reader, err := f.CreateArchiveSpanReader()
assert.EqualError(t, err, customError.Error())
assert.Nil(t, reader)
writer, err := f.CreateArchiveSpanWriter()
assert.EqualError(t, err, customError.Error())
assert.Nil(t, writer)
}

func TestWithConfiguration(t *testing.T) {
f := NewFactory()
v, command := config.Viperize(f.AddFlags)
Expand Down

0 comments on commit edd05a4

Please sign in to comment.