github.com/martinohmann/rfoutlet@v1.2.1-0.20220707195255-8a66aa411105/pkg/gpio/transmitter_test.go (about)

     1  package gpio
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestTransmitterTransmit(t *testing.T) {
    10  	pin := NewFakeOutputPin()
    11  
    12  	tx := NewPinTransmitter(pin, TransmissionCount(1))
    13  	defer tx.Close()
    14  
    15  	<-tx.Transmit(0x1, DefaultProtocols[0], 190)
    16  
    17  	assert.Equal(
    18  		t,
    19  		[]int{1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0},
    20  		pin.Values,
    21  	)
    22  }
    23  
    24  func TestTransmitterClose(t *testing.T) {
    25  	pin := NewFakeOutputPin()
    26  
    27  	tx := NewPinTransmitter(pin)
    28  	assert.Nil(t, tx.Close())
    29  
    30  	assert.True(t, pin.Closed)
    31  }