Refactor mocks to be wrapped by testing plugin objects
This commit is contained in:
parent
8df560d659
commit
33ecb07156
@ -4,55 +4,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/component"
|
||||
componentmocks "github.com/hashicorp/vagrant-plugin-sdk/component/mocks"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/core"
|
||||
coremocks "github.com/hashicorp/vagrant-plugin-sdk/core/mocks"
|
||||
"github.com/hashicorp/vagrant/internal/plugin"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type TestGuestPlugin struct {
|
||||
plugin.TestPluginWithFakeBroker
|
||||
coremocks.Guest
|
||||
}
|
||||
|
||||
type TestHostPlugin struct {
|
||||
plugin.TestPluginWithFakeBroker
|
||||
componentmocks.Host
|
||||
}
|
||||
|
||||
type TestSyncedFolderPlugin struct {
|
||||
plugin.TestPluginWithFakeBroker
|
||||
componentmocks.SyncedFolder
|
||||
}
|
||||
|
||||
func BuildTestGuestPlugin(name string) *TestGuestPlugin {
|
||||
p := &TestGuestPlugin{}
|
||||
p.On("SetPluginName", mock.AnythingOfType("string")).Return(nil)
|
||||
p.On("Seed", mock.AnythingOfType("*core.Seeds")).Return(nil)
|
||||
p.On("Seeds").Return(core.NewSeeds(), nil)
|
||||
p.On("PluginName").Return(name, nil)
|
||||
return p
|
||||
}
|
||||
|
||||
func BuildTestHostPlugin(name string) *TestHostPlugin {
|
||||
p := &TestHostPlugin{}
|
||||
p.On("SetPluginName", mock.AnythingOfType("string")).Return(nil)
|
||||
p.On("Seed", mock.AnythingOfType("*core.Seeds")).Return(nil)
|
||||
p.On("Seeds").Return(core.NewSeeds(), nil)
|
||||
p.On("PluginName").Return(name, nil)
|
||||
return p
|
||||
}
|
||||
|
||||
func BuildTestSyncedFolderPlugin() *TestSyncedFolderPlugin {
|
||||
p := &TestSyncedFolderPlugin{}
|
||||
p.On("SetPluginName", mock.AnythingOfType("string")).Return(nil)
|
||||
p.On("Seed", mock.AnythingOfType("*core.Seeds")).Return(nil)
|
||||
p.On("Seeds").Return(core.NewSeeds(), nil)
|
||||
return p
|
||||
}
|
||||
|
||||
func TestBasisPlugins(t *testing.T) {
|
||||
myguest := plugin.TestPlugin(t,
|
||||
BuildTestGuestPlugin("myguest"),
|
||||
|
||||
@ -5,37 +5,56 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
sdkcore "github.com/hashicorp/vagrant-plugin-sdk/core"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/core"
|
||||
coremocks "github.com/hashicorp/vagrant-plugin-sdk/core/mocks"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/datadir"
|
||||
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
|
||||
"github.com/hashicorp/vagrant/internal/plugin"
|
||||
"github.com/hashicorp/vagrant/internal/server/singleprocess"
|
||||
"github.com/mitchellh/go-testing-interface"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func seededHostMock(name string) *coremocks.Host {
|
||||
guestMock := &coremocks.Host{}
|
||||
guestMock.On("Seeds").Return(sdkcore.NewSeeds(), nil)
|
||||
guestMock.On("Seed", mock.AnythingOfType("")).Return(nil)
|
||||
guestMock.On("PluginName").Return(name, nil)
|
||||
return guestMock
|
||||
type TestGuestPlugin struct {
|
||||
plugin.TestPluginWithFakeBroker
|
||||
coremocks.Guest
|
||||
}
|
||||
|
||||
func seededGuestMock(name string) *coremocks.Guest {
|
||||
guestMock := &coremocks.Guest{}
|
||||
guestMock.On("Seeds").Return(sdkcore.NewSeeds(), nil)
|
||||
guestMock.On("Seed", mock.AnythingOfType("")).Return(nil)
|
||||
guestMock.On("PluginName").Return(name, nil)
|
||||
return guestMock
|
||||
type TestHostPlugin struct {
|
||||
plugin.TestPluginWithFakeBroker
|
||||
coremocks.Host
|
||||
}
|
||||
|
||||
func seededSyncedFolderMock(name string) *coremocks.SyncedFolder {
|
||||
guestMock := &coremocks.SyncedFolder{}
|
||||
guestMock.On("Seeds").Return(sdkcore.NewSeeds(), nil)
|
||||
guestMock.On("Seed", mock.AnythingOfType("")).Return(nil)
|
||||
return guestMock
|
||||
type TestSyncedFolderPlugin struct {
|
||||
plugin.TestPluginWithFakeBroker
|
||||
coremocks.SyncedFolder
|
||||
}
|
||||
|
||||
func BuildTestGuestPlugin(name string) *TestGuestPlugin {
|
||||
p := &TestGuestPlugin{}
|
||||
p.On("SetPluginName", mock.AnythingOfType("string")).Return(nil)
|
||||
p.On("Seed", mock.AnythingOfType("*core.Seeds")).Return(nil)
|
||||
p.On("Seeds").Return(core.NewSeeds(), nil)
|
||||
p.On("PluginName").Return(name, nil)
|
||||
return p
|
||||
}
|
||||
|
||||
func BuildTestHostPlugin(name string) *TestHostPlugin {
|
||||
p := &TestHostPlugin{}
|
||||
p.On("SetPluginName", mock.AnythingOfType("string")).Return(nil)
|
||||
p.On("Seed", mock.AnythingOfType("*core.Seeds")).Return(nil)
|
||||
p.On("Seeds").Return(core.NewSeeds(), nil)
|
||||
p.On("PluginName").Return(name, nil)
|
||||
return p
|
||||
}
|
||||
|
||||
func BuildTestSyncedFolderPlugin() *TestSyncedFolderPlugin {
|
||||
p := &TestSyncedFolderPlugin{}
|
||||
p.On("SetPluginName", mock.AnythingOfType("string")).Return(nil)
|
||||
p.On("Seed", mock.AnythingOfType("*core.Seeds")).Return(nil)
|
||||
p.On("Seeds").Return(core.NewSeeds(), nil)
|
||||
return p
|
||||
}
|
||||
|
||||
func TestBasis(t testing.T, opts ...BasisOption) (b *Basis) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user