]> git.r.bdr.sh - rbdr/mobius/blame - hotline/server_blackbox_test.go
Replace hardcoded version with ldflag usage
[rbdr/mobius] / hotline / server_blackbox_test.go
CommitLineData
6988a057
JH
1package hotline
2
625b0580 3import (
7cd900d6 4 "encoding/hex"
00d1ef67 5 "github.com/stretchr/testify/assert"
a6216dd8 6 "log/slog"
625b0580 7 "os"
625b0580
JH
8 "testing"
9)
10
a6216dd8
JH
11func NewTestLogger() *slog.Logger {
12 return slog.New(slog.NewTextHandler(os.Stdout, nil))
625b0580
JH
13}
14
7cd900d6
JH
15// assertTransferBytesEqual takes a string with a hexdump in the same format that `hexdump -C` produces and compares with
16// a hexdump for the bytes in got, after stripping the create/modify timestamps.
17// I don't love this, but as git does not preserve file create/modify timestamps, we either need to fully mock the
18// filesystem interactions or work around in this way.
19// TODO: figure out a better solution
20func assertTransferBytesEqual(t *testing.T, wantHexDump string, got []byte) bool {
21 if wantHexDump == "" {
22 return true
23 }
24
25 var clean []byte
26 clean = append(clean, got[:92]...) // keep the first 92 bytes
27 clean = append(clean, make([]byte, 16)...) // replace the next 16 bytes for create/modify timestamps
28 clean = append(clean, got[108:]...) // keep the rest
29
30 return assert.Equal(t, wantHexDump, hex.Dump(clean))
31}
32
aebc4d36 33// tranAssertEqual compares equality of transactions slices after stripping out the random ID
00d1ef67
JH
34func tranAssertEqual(t *testing.T, tran1, tran2 []Transaction) bool {
35 var newT1 []Transaction
36 var newT2 []Transaction
7cd900d6 37
92a7e455
JH
38 for _, trans := range tran1 {
39 trans.ID = []byte{0, 0, 0, 0}
7cd900d6
JH
40 var fs []Field
41 for _, field := range trans.Fields {
95159e55 42 if field.ID == [2]byte{0x00, 0x6b} {
7cd900d6
JH
43 continue
44 }
45 fs = append(fs, field)
46 }
47 trans.Fields = fs
00d1ef67
JH
48 newT1 = append(newT1, trans)
49 }
625b0580 50
92a7e455
JH
51 for _, trans := range tran2 {
52 trans.ID = []byte{0, 0, 0, 0}
7cd900d6
JH
53 var fs []Field
54 for _, field := range trans.Fields {
95159e55 55 if field.ID == [2]byte{0x00, 0x6b} {
7cd900d6
JH
56 continue
57 }
58 fs = append(fs, field)
59 }
60 trans.Fields = fs
00d1ef67 61 newT2 = append(newT2, trans)
00d1ef67 62 }
625b0580 63
00d1ef67 64 return assert.Equal(t, newT1, newT2)
92a7e455 65}