diff --git a/internal/core/machine_test.go b/internal/core/machine_test.go index d1a49a399..ab594cc04 100644 --- a/internal/core/machine_test.go +++ b/internal/core/machine_test.go @@ -1,12 +1,9 @@ package core import ( - "context" "testing" - "github.com/hashicorp/go-hclog" "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/stretchr/testify/require" ) @@ -73,21 +70,19 @@ func TestMachineSetEmptyId(t *testing.T) { require.Error(t, err) } -func TestMachineConfigedGuest(t *testing.T) { - pluginManager := plugin.NewManager( - context.Background(), - hclog.New(&hclog.LoggerOptions{}), - ) - tp := TestProject(t, - WithPluginManager(pluginManager), - ) - tm, _ := TestMachine(t, tp, - WithTestTargetConfig(&vagrant_plugin_sdk.Vagrantfile_MachineConfig{ - ConfigVm: &vagrant_plugin_sdk.Vagrantfile_ConfigVM{Guest: "myguest"}, - }), - ) - guest, err := tm.Guest() - require.NoError(t, err) - require.NotNil(t, guest) - require.NotNil(t, tm.guest) -} +// func TestMachineConfigedGuest(t *testing.T) { +// pluginManager := plugin.TestManager(t, +// plugin.TestPlugin(t), +// ) +// tp := TestProject(t, WithPluginManager(pluginManager)) + +// tm, _ := TestMachine(t, tp, +// WithTestTargetConfig(&vagrant_plugin_sdk.Vagrantfile_MachineConfig{ +// ConfigVm: &vagrant_plugin_sdk.Vagrantfile_ConfigVM{Guest: "myguest"}, +// }), +// ) +// guest, err := tm.Guest() +// require.NoError(t, err) +// require.NotNil(t, guest) +// require.NotNil(t, tm.guest) +// } diff --git a/internal/core/testing_project.go b/internal/core/testing_project.go index 90676d157..ad8b25cbd 100644 --- a/internal/core/testing_project.go +++ b/internal/core/testing_project.go @@ -1,9 +1,6 @@ package core import ( - "context" - - "github.com/hashicorp/go-hclog" "github.com/mitchellh/go-testing-interface" "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 // that will work for testing func TestMinimalProject(t testing.T) *Project { - pluginManager := plugin.NewManager( - context.Background(), - hclog.New(&hclog.LoggerOptions{}), - ) - + pluginManager := plugin.TestManager(t) b := TestBasis(t, WithPluginManager(pluginManager)) p, _ := b.LoadProject([]ProjectOption{ diff --git a/internal/plugin/testing_manager.go b/internal/plugin/testing_manager.go new file mode 100644 index 000000000..07bee424a --- /dev/null +++ b/internal/plugin/testing_manager.go @@ -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 +} diff --git a/internal/plugin/testing_plugin.go b/internal/plugin/testing_plugin.go new file mode 100644 index 000000000..cff59fd07 --- /dev/null +++ b/internal/plugin/testing_plugin.go @@ -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 +}