mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 00:45:43 +03:00
Driver plugin framework to facilitate development of driver plugins.
Implementing plugins only need to implement the DriverPlugin interface.
The framework proxies this interface to the go-plugin GRPC interface generated
from the driver.proto spec.
A testing harness is provided to allow implementing drivers to test the full
lifecycle of the driver plugin. An example use:
func TestMyDriver(t *testing.T) {
harness := NewDriverHarness(t, &MyDiverPlugin{})
// The harness implements the DriverPlugin interface and can be used as such
taskHandle, err := harness.StartTask(...)
}
25 lines
583 B
Go
25 lines
583 B
Go
package drivers
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var _ DriverPlugin = (*MockDriver)(nil)
|
|
|
|
// Very simple test to ensure the test harness works as expected
|
|
func TestDriverHarness(t *testing.T) {
|
|
handle := &TaskHandle{Config: &TaskConfig{Name: "mock"}}
|
|
d := &MockDriver{
|
|
StartTaskF: func(task *TaskConfig) (*TaskHandle, error) {
|
|
return handle, nil
|
|
},
|
|
}
|
|
harness := NewDriverHarness(t, d)
|
|
defer harness.Kill()
|
|
actual, err := harness.StartTask(&TaskConfig{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, handle.Config.Name, actual.Config.Name)
|
|
}
|