AUse test table to test for multiple configs

This commit is contained in:
sophia 2022-02-23 17:15:36 -06:00 committed by Paul Hinze
parent 4068760588
commit 16e415f929
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0

View File

@ -76,6 +76,16 @@ func TestMachineSetEmptyId(t *testing.T) {
}
func TestMachineConfigedGuest(t *testing.T) {
type test struct {
config *vagrant_plugin_sdk.Vagrantfile_ConfigVM
errors bool
}
tests := []test{
{config: &vagrant_plugin_sdk.Vagrantfile_ConfigVM{Guest: "myguest"}, errors: false},
{config: &vagrant_plugin_sdk.Vagrantfile_ConfigVM{Guest: "idontexist"}, errors: true},
}
guestMock := &coremocks.Guest{}
guestMock.On("Seeds").Return(sdkcore.NewSeeds(), nil)
guestMock.On("Seed", mock.AnythingOfType("")).Return(nil)
@ -87,13 +97,21 @@ func TestMachineConfigedGuest(t *testing.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)
for _, tc := range tests {
tm, _ := TestMachine(t, tp,
WithTestTargetConfig(&vagrant_plugin_sdk.Vagrantfile_MachineConfig{
ConfigVm: tc.config,
}),
)
guest, err := tm.Guest()
if tc.errors {
require.Error(t, err)
require.Nil(t, guest)
require.Nil(t, tm.guest)
} else {
require.NoError(t, err)
require.NotNil(t, guest)
require.NotNil(t, tm.guest)
}
}
}