github.com/koko1123/flow-go-1@v0.29.6/model/fingerprint/fingerprint_test.go (about) 1 package fingerprint 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 9 "github.com/koko1123/flow-go-1/model/fingerprint/mock" 10 ) 11 12 func TestFingerprint(t *testing.T) { 13 tests := []struct { 14 input interface{} 15 output string 16 }{ 17 {"abc", "0x83616263"}, 18 {uint(3), "0x03"}, 19 {[]byte{}, "0x80"}, 20 {[]byte{0x01, 0xff}, "0x8201ff"}, 21 {struct{ a uint }{a: uint(2)}, "0xc0"}, 22 } 23 24 for _, te := range tests { 25 t.Run(fmt.Sprintf("Input %#v should produce output %s", te.input, te.output), func(t *testing.T) { 26 assert.Equal(t, te.output, fmt.Sprintf("%#x", Fingerprint(te.input))) 27 }) 28 } 29 } 30 31 func TestFingerprinter(t *testing.T) { 32 input := new(mock.Fingerprinter) 33 input.On("Fingerprint").Return([]byte{0xab, 0xcd, 0xef}).Once() 34 35 assert.Equal(t, "0xabcdef", fmt.Sprintf("%#x", Fingerprint(input))) 36 input.AssertExpectations(t) 37 }