code.pfad.fr/gohmekit@v0.2.1/pairing/device_test.go (about)

     1  package pairing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gotest.tools/v3/assert"
     7  )
     8  
     9  func TestFormatDeviceID(t *testing.T) {
    10  	cc := map[string]struct {
    11  		input  []byte
    12  		output string
    13  	}{
    14  		"empty": {
    15  			input:  nil,
    16  			output: "",
    17  		},
    18  		"one byte": {
    19  			input:  []byte{1},
    20  			output: "01",
    21  		},
    22  		"uppercase": {
    23  			input:  []byte{10},
    24  			output: "0A",
    25  		},
    26  		"two bytes": {
    27  			input:  []byte{1, 2},
    28  			output: "01:02",
    29  		},
    30  		"6 bytes (48 bits)": {
    31  			input:  []byte{1, 32, 42, 56, 255, 0},
    32  			output: "01:20:2A:38:FF:00",
    33  		},
    34  	}
    35  	for name, c := range cc {
    36  		t.Run(name, func(t *testing.T) {
    37  			out := formatPairingID(c.input)
    38  			assert.Equal(t, c.output, string(out))
    39  		})
    40  	}
    41  }