-
Notifications
You must be signed in to change notification settings - Fork 55
/
ready_internal_test.go
59 lines (53 loc) · 1.14 KB
/
ready_internal_test.go
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
package app
import (
"encoding/json"
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// Checking that ExecutionP2PPeers does not appear in the JSON output if it's
// set to nil, but appears if it's set to 0 or any other number.
func TestReadinessStatusMarshaling(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input *uint64
output string
}{
{
name: "ExecutionP2PPeers is 22",
input: uint64Ptr(22),
},
{
name: "ExecutionP2PPeers is 0",
input: uint64Ptr(0),
},
{
name: "ExecutionP2PPeers is nil",
input: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
status := readinessStatus{
ExecutionP2PPeers: tt.input,
}
data, err := json.Marshal(&status)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if tt.input != nil {
require.True(t,
strings.Contains(string(data), fmt.Sprintf("\"execution_p2p_peers\":%v", *tt.input)),
tt.name)
} else {
require.False(t, strings.Contains(string(data), "execution_p2p_peers"), tt.name)
}
})
}
}
func uint64Ptr(i uint64) *uint64 {
return &i
}