fix broken test

pull/4305/head
Matthew Hooker 9 years ago
parent aa177de54b
commit ee86dc87fd
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1

@ -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…
Cancel
Save