add tests
This commit is contained in:
parent
73eda08540
commit
2e2374b6be
|
@ -43,3 +43,71 @@ func TestStepExport(t *testing.T) {
|
||||||
t.Fatal("bad")
|
t.Fatal("bad")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStepExport_OutputPath(t *testing.T) {
|
||||||
|
type testCase struct {
|
||||||
|
Step *StepExport
|
||||||
|
Expected string
|
||||||
|
Reason string
|
||||||
|
}
|
||||||
|
tcs := []testCase{
|
||||||
|
{
|
||||||
|
Step: &StepExport{
|
||||||
|
Format: "ova",
|
||||||
|
OutputDir: "output-dir",
|
||||||
|
OutputFilename: "output-filename",
|
||||||
|
},
|
||||||
|
Expected: "output-dir/output-filename.ova",
|
||||||
|
Reason: "output_filename should not be vmName if set.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Step: &StepExport{
|
||||||
|
Format: "ovf",
|
||||||
|
OutputDir: "output-dir",
|
||||||
|
OutputFilename: "",
|
||||||
|
},
|
||||||
|
Expected: "output-dir/foo.ovf",
|
||||||
|
Reason: "output_filename should default to vmName.",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range tcs {
|
||||||
|
state := testState(t)
|
||||||
|
state.Put("vmName", "foo")
|
||||||
|
|
||||||
|
// Test the run
|
||||||
|
if action := tc.Step.Run(context.Background(), state); action != multistep.ActionContinue {
|
||||||
|
t.Fatalf("bad action: %#v", action)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test output state
|
||||||
|
path, ok := state.GetOk("exportPath")
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("should set exportPath")
|
||||||
|
}
|
||||||
|
if path != tc.Expected {
|
||||||
|
t.Fatalf("Expected %s didn't match received %s: %s", tc.Expected, path, tc.Reason)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStepExport_SkipExport(t *testing.T) {
|
||||||
|
state := testState(t)
|
||||||
|
step := StepExport{SkipExport: true}
|
||||||
|
|
||||||
|
state.Put("vmName", "foo")
|
||||||
|
|
||||||
|
driver := state.Get("driver").(*DriverMock)
|
||||||
|
|
||||||
|
// Test the run
|
||||||
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
||||||
|
t.Fatalf("bad action: %#v", action)
|
||||||
|
}
|
||||||
|
if _, ok := state.GetOk("error"); ok {
|
||||||
|
t.Fatal("should NOT have error")
|
||||||
|
}
|
||||||
|
// Test driver
|
||||||
|
if len(driver.VBoxManageCalls) != 0 {
|
||||||
|
t.Fatal("shouldn't have called vboxmanage; skip_export was set.")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue