1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package node
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestParseHTTPHeader(t *testing.T) {
for _, test := range []struct {
desc string
str string
expHdr http.Header
expErr bool
}{
{
desc: "err-empty",
expErr: true,
},
{
desc: "err-no-colon",
str: "Key",
expErr: true,
},
{
desc: "err-only-key",
str: "Key:",
expErr: true,
},
{
desc: "err-no-space",
str: "Key:value",
expErr: true,
},
{
desc: "valid",
str: "Key: value",
expHdr: http.Header{"Key": []string{"value"}},
},
{
desc: "valid-small",
str: "key: value",
expHdr: http.Header{"Key": []string{"value"}},
},
{
desc: "valid-spaces-colons",
str: "X-Key: a long value with spaces: and: colons",
expHdr: http.Header{"X-Key": []string{"a long value with spaces: and: colons"}},
},
} {
t.Run(test.desc, func(t *testing.T) {
h, err := parseHTTPHeader(test.str)
if test.expErr {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, test.expHdr, h)
}
})
}
}
func TestL1BeaconEndpointConfig_Setup(t *testing.T) {
for _, test := range []struct {
desc string
baa []string
len int
}{
{
desc: "empty",
},
{
desc: "one",
baa: []string{"http://foo.bar"},
len: 1,
},
{
desc: "three",
baa: []string{"http://foo.bar", "http://op.ti", "http://ba.se"},
len: 3,
},
} {
t.Run(test.desc, func(t *testing.T) {
cfg := L1BeaconEndpointConfig{BeaconFallbackAddrs: test.baa}
_, fb, err := cfg.Setup(context.Background(), nil)
require.NoError(t, err)
require.Len(t, fb, test.len)
})
}
}