mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-10 09:10:27 -04:00
fix broken test
This commit is contained in:
parent
aa177de54b
commit
ee86dc87fd
2 changed files with 22 additions and 18 deletions
|
|
@ -108,24 +108,24 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
|
|||
func (*StepTypeBootCommand) Cleanup(multistep.StateBag) {}
|
||||
|
||||
// Gather scancodes to send to console efficiently.
|
||||
func gathercodes(codes []string) []string {
|
||||
result := make([]string, 0, len(codes))
|
||||
begin := 0
|
||||
end := 0
|
||||
for pos, code := range codes {
|
||||
if strings.HasPrefix(code, "wait") {
|
||||
if pos > begin {
|
||||
result = append(result, strings.Join(codes[begin:end+1], " "))
|
||||
}
|
||||
result = append(result, code)
|
||||
begin = pos + 1
|
||||
func gathercodes(codes []string) (gathered []string) {
|
||||
working := []string{}
|
||||
pushWorking := func() {
|
||||
if len(working) > 0 {
|
||||
gathered = append(gathered, strings.Join(working, " "))
|
||||
working = []string{}
|
||||
}
|
||||
end = pos
|
||||
}
|
||||
if end > begin {
|
||||
result = append(result, strings.Join(codes[begin:end+1], " "))
|
||||
for _, code := range codes {
|
||||
if strings.HasPrefix(code, "wait") {
|
||||
pushWorking()
|
||||
gathered = append(gathered, code)
|
||||
} else {
|
||||
working = append(working, code)
|
||||
}
|
||||
}
|
||||
return result
|
||||
pushWorking()
|
||||
return
|
||||
}
|
||||
|
||||
func scancodes(message string) []string {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ func TestStepTypeBootCommand_gather(t *testing.T) {
|
|||
{"02", "82", "03", "83"},
|
||||
{"wait5", "wait1", "wait10"},
|
||||
{"wait5", "02", "82", "03", "83", "wait1", "wait10"},
|
||||
{"wait1"},
|
||||
{"01"},
|
||||
}
|
||||
|
||||
expected := [][]string{
|
||||
|
|
@ -18,12 +20,14 @@ func TestStepTypeBootCommand_gather(t *testing.T) {
|
|||
{"02 82 03 83"},
|
||||
{"wait5", "wait1", "wait10"},
|
||||
{"wait5", "02 82 03 83", "wait1", "wait10"},
|
||||
{"wait1"},
|
||||
{"01"},
|
||||
}
|
||||
|
||||
for i, data := range input {
|
||||
if !reflect.DeepEqual(gathercodes(data), expected[i]) {
|
||||
t.Fatalf("%#v did not equal expected %#v", data, expected[i])
|
||||
gathered := gathercodes(data)
|
||||
if !reflect.DeepEqual(gathered, expected[i]) {
|
||||
t.Fatalf("%#v did not equal expected %#v", gathered, expected[i])
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue