2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-01-22 19:03:49 -05:00
|
|
|
"context"
|
2014-04-06 13:21:22 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
2016-12-11 14:13:37 -05:00
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
2014-04-06 13:21:22 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepAttachFloppy_impl(t *testing.T) {
|
|
|
|
var _ multistep.Step = new(StepAttachFloppy)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepAttachFloppy(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepAttachFloppy)
|
|
|
|
|
|
|
|
// Create a temporary file for our floppy file
|
|
|
|
tf, err := ioutil.TempFile("", "packer")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
tf.Close()
|
|
|
|
defer os.Remove(tf.Name())
|
|
|
|
|
|
|
|
state.Put("floppy_path", tf.Name())
|
|
|
|
state.Put("vmName", "foo")
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2014-04-06 13:21:22 -04:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
2014-06-06 09:54:19 -04:00
|
|
|
if len(driver.PrlctlCalls) != 2 {
|
2014-04-06 13:21:22 -04:00
|
|
|
t.Fatal("not enough calls to prlctl")
|
|
|
|
}
|
|
|
|
|
|
|
|
if driver.PrlctlCalls[0][0] != "set" {
|
|
|
|
t.Fatal("bad call")
|
|
|
|
}
|
2014-06-06 09:54:19 -04:00
|
|
|
if driver.PrlctlCalls[0][2] != "--device-del" {
|
2014-04-06 13:21:22 -04:00
|
|
|
t.Fatal("bad call")
|
|
|
|
}
|
2014-06-06 09:54:19 -04:00
|
|
|
if driver.PrlctlCalls[0][3] != "fdd0" {
|
|
|
|
t.Fatal("bad call")
|
|
|
|
}
|
|
|
|
|
|
|
|
if driver.PrlctlCalls[1][0] != "set" {
|
|
|
|
t.Fatal("bad call")
|
|
|
|
}
|
|
|
|
if driver.PrlctlCalls[1][2] != "--device-add" {
|
|
|
|
t.Fatal("bad call")
|
|
|
|
}
|
|
|
|
if driver.PrlctlCalls[1][3] != "fdd" {
|
|
|
|
t.Fatal("bad call")
|
|
|
|
}
|
|
|
|
if driver.PrlctlCalls[1][6] != "--connect" {
|
2014-04-06 13:21:22 -04:00
|
|
|
t.Fatal("bad call")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepAttachFloppy_noFloppy(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepAttachFloppy)
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2014-04-06 13:21:22 -04:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(driver.PrlctlCalls) > 0 {
|
2014-05-01 16:58:17 -04:00
|
|
|
t.Fatal("should not call prlctl")
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|
|
|
|
}
|