github.com/mitchellh/packer@v1.3.2/common/bootcommand/vnc_driver_test.go (about)

     1  package bootcommand
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  type event struct {
    12  	u    uint32
    13  	down bool
    14  }
    15  
    16  type sender struct {
    17  	e []event
    18  }
    19  
    20  func (s *sender) KeyEvent(u uint32, down bool) error {
    21  	s.e = append(s.e, event{u, down})
    22  	return nil
    23  }
    24  
    25  func Test_vncSpecialLookup(t *testing.T) {
    26  	in := "<rightShift><rightshiftoff><RIGHTSHIFTON>"
    27  	expected := []event{
    28  		{0xFFE2, true},
    29  		{0xFFE2, false},
    30  		{0xFFE2, false},
    31  		{0xFFE2, true},
    32  	}
    33  	s := &sender{}
    34  	d := NewVNCDriver(s, time.Duration(0))
    35  	seq, err := GenerateExpressionSequence(in)
    36  	assert.NoError(t, err)
    37  	err = seq.Do(context.Background(), d)
    38  	assert.NoError(t, err)
    39  	assert.Equal(t, expected, s.e)
    40  }
    41  
    42  func Test_vncIntervalNotGiven(t *testing.T) {
    43  	s := &sender{}
    44  	d := NewVNCDriver(s, time.Duration(0))
    45  	assert.Equal(t, d.interval, time.Duration(100)*time.Millisecond)
    46  }
    47  
    48  func Test_vncIntervalGiven(t *testing.T) {
    49  	s := &sender{}
    50  	d := NewVNCDriver(s, time.Duration(5000)*time.Millisecond)
    51  	assert.Equal(t, d.interval, time.Duration(5000)*time.Millisecond)
    52  }