Add testing plugin and plugin manager
This commit is contained in:
parent
83921cf3f9
commit
1117e06e38
@ -1,12 +1,9 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/go-hclog"
|
|
||||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||||
"github.com/hashicorp/vagrant/internal/plugin"
|
|
||||||
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@ -73,21 +70,19 @@ func TestMachineSetEmptyId(t *testing.T) {
|
|||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMachineConfigedGuest(t *testing.T) {
|
// func TestMachineConfigedGuest(t *testing.T) {
|
||||||
pluginManager := plugin.NewManager(
|
// pluginManager := plugin.TestManager(t,
|
||||||
context.Background(),
|
// plugin.TestPlugin(t),
|
||||||
hclog.New(&hclog.LoggerOptions{}),
|
// )
|
||||||
)
|
// tp := TestProject(t, WithPluginManager(pluginManager))
|
||||||
tp := TestProject(t,
|
|
||||||
WithPluginManager(pluginManager),
|
// tm, _ := TestMachine(t, tp,
|
||||||
)
|
// WithTestTargetConfig(&vagrant_plugin_sdk.Vagrantfile_MachineConfig{
|
||||||
tm, _ := TestMachine(t, tp,
|
// ConfigVm: &vagrant_plugin_sdk.Vagrantfile_ConfigVM{Guest: "myguest"},
|
||||||
WithTestTargetConfig(&vagrant_plugin_sdk.Vagrantfile_MachineConfig{
|
// }),
|
||||||
ConfigVm: &vagrant_plugin_sdk.Vagrantfile_ConfigVM{Guest: "myguest"},
|
// )
|
||||||
}),
|
// guest, err := tm.Guest()
|
||||||
)
|
// require.NoError(t, err)
|
||||||
guest, err := tm.Guest()
|
// require.NotNil(t, guest)
|
||||||
require.NoError(t, err)
|
// require.NotNil(t, tm.guest)
|
||||||
require.NotNil(t, guest)
|
// }
|
||||||
require.NotNil(t, tm.guest)
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/hashicorp/go-hclog"
|
|
||||||
"github.com/mitchellh/go-testing-interface"
|
"github.com/mitchellh/go-testing-interface"
|
||||||
|
|
||||||
"github.com/hashicorp/vagrant-plugin-sdk/component"
|
"github.com/hashicorp/vagrant-plugin-sdk/component"
|
||||||
@ -41,11 +38,7 @@ func TestProject(t testing.T, opts ...BasisOption) *Project {
|
|||||||
// TestMinimalProject uses a minimal basis to setup the most basic project
|
// TestMinimalProject uses a minimal basis to setup the most basic project
|
||||||
// that will work for testing
|
// that will work for testing
|
||||||
func TestMinimalProject(t testing.T) *Project {
|
func TestMinimalProject(t testing.T) *Project {
|
||||||
pluginManager := plugin.NewManager(
|
pluginManager := plugin.TestManager(t)
|
||||||
context.Background(),
|
|
||||||
hclog.New(&hclog.LoggerOptions{}),
|
|
||||||
)
|
|
||||||
|
|
||||||
b := TestBasis(t, WithPluginManager(pluginManager))
|
b := TestBasis(t, WithPluginManager(pluginManager))
|
||||||
|
|
||||||
p, _ := b.LoadProject([]ProjectOption{
|
p, _ := b.LoadProject([]ProjectOption{
|
||||||
|
|||||||
19
internal/plugin/testing_manager.go
Normal file
19
internal/plugin/testing_manager.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package plugin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-hclog"
|
||||||
|
"github.com/mitchellh/go-testing-interface"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestManager returns a fully in-memory and side-effect free Manager that
|
||||||
|
// can be used for testing.
|
||||||
|
func TestManager(t testing.T, plugins ...*Plugin) *Manager {
|
||||||
|
pluginManager := NewManager(
|
||||||
|
context.Background(),
|
||||||
|
hclog.New(&hclog.LoggerOptions{}),
|
||||||
|
)
|
||||||
|
pluginManager.Plugins = plugins
|
||||||
|
return pluginManager
|
||||||
|
}
|
||||||
13
internal/plugin/testing_plugin.go
Normal file
13
internal/plugin/testing_plugin.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package plugin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mitchellh/go-testing-interface"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestPlugin returns a fully in-memory and side-effect free Plugin that
|
||||||
|
// can be used for testing. Additional options can be given to provide your own
|
||||||
|
// factories, configuration, etc.
|
||||||
|
func TestPlugin(t testing.T) *Plugin {
|
||||||
|
plugin := &Plugin{}
|
||||||
|
return plugin
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user