-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathstatus_test.go
More file actions
143 lines (123 loc) · 4.09 KB
/
status_test.go
File metadata and controls
143 lines (123 loc) · 4.09 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright 2023 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package api_test
import (
"context"
"net/http"
"testing"
"github.com/ethersphere/bee/v2/pkg/api"
"github.com/ethersphere/bee/v2/pkg/jsonhttp"
"github.com/ethersphere/bee/v2/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/v2/pkg/log"
"github.com/ethersphere/bee/v2/pkg/postage"
"github.com/ethersphere/bee/v2/pkg/status"
"github.com/ethersphere/bee/v2/pkg/storer"
"github.com/ethersphere/bee/v2/pkg/topology"
)
func TestGetStatus(t *testing.T) {
t.Parallel()
const url = "/status"
t.Run("node", func(t *testing.T) {
t.Parallel()
mode := api.FullMode
ssr := api.StatusSnapshotResponse{
Proximity: 256,
BeeMode: mode.String(),
ReserveSize: 128,
ReserveSizeWithinRadius: 64,
PullsyncRate: 64,
StorageRadius: 8,
ConnectedPeers: 0,
NeighborhoodSize: 1,
BatchCommitment: 1,
IsReachable: true,
LastSyncedBlock: 6092500,
CommittedDepth: 1,
}
ssMock := &statusSnapshotMock{
syncRate: ssr.PullsyncRate,
reserveSize: int(ssr.ReserveSize),
reserveSizeWithinRadius: ssr.ReserveSizeWithinRadius,
storageRadius: ssr.StorageRadius,
commitment: ssr.BatchCommitment,
chainState: &postage.ChainState{Block: ssr.LastSyncedBlock},
committedDepth: ssr.CommittedDepth,
}
statusSvc := status.NewService(
log.Noop,
nil,
new(topologyPeersIterNoopMock),
mode.String(),
ssMock,
ssMock,
nil,
)
statusSvc.SetSync(ssMock)
client, _, _, _ := newTestServer(t, testServerOptions{
BeeMode: mode,
NodeStatus: statusSvc,
})
jsonhttptest.Request(t, client, http.MethodGet, url, http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(ssr),
)
})
t.Run("bad request", func(t *testing.T) {
t.Parallel()
client, _, _, _ := newTestServer(t, testServerOptions{
BeeMode: api.DevMode,
NodeStatus: status.NewService(
log.Noop,
nil,
new(topologyPeersIterNoopMock),
"",
nil,
nil,
nil,
),
})
jsonhttptest.Request(t, client, http.MethodGet, url, http.StatusBadRequest,
jsonhttptest.WithExpectedJSONResponse(jsonhttp.StatusResponse{
Message: api.ErrUnsupportedDevNodeOperation.Error(),
Code: http.StatusBadRequest,
}),
)
})
}
// topologyPeersIterNoopMock is noop topology.PeerIterator.
type topologyPeersIterNoopMock struct{}
func (m *topologyPeersIterNoopMock) EachConnectedPeer(_ topology.EachPeerFunc, _ topology.Select) error {
return nil
}
func (m *topologyPeersIterNoopMock) EachConnectedPeerRev(_ topology.EachPeerFunc, _ topology.Select) error {
return nil
}
func (m *topologyPeersIterNoopMock) IsReachable() bool {
return true
}
// statusSnapshotMock satisfies the following interfaces:
// - status.Reserve
// - status.SyncReporter
// - postage.CommitmentGetter
type statusSnapshotMock struct {
syncRate float64
reserveSize int
reserveSizeWithinRadius uint64
storageRadius uint8
commitment uint64
chainState *postage.ChainState
neighborhoods []*storer.NeighborhoodStat
committedDepth uint8
}
func (m *statusSnapshotMock) SyncRate() float64 { return m.syncRate }
func (m *statusSnapshotMock) ReserveSize() int { return m.reserveSize }
func (m *statusSnapshotMock) StorageRadius() uint8 { return m.storageRadius }
func (m *statusSnapshotMock) Commitment() (uint64, error) { return m.commitment, nil }
func (m *statusSnapshotMock) GetChainState() *postage.ChainState { return m.chainState }
func (m *statusSnapshotMock) ReserveSizeWithinRadius() uint64 {
return m.reserveSizeWithinRadius
}
func (m *statusSnapshotMock) NeighborhoodsStat(ctx context.Context) ([]*storer.NeighborhoodStat, error) {
return m.neighborhoods, nil
}
func (m *statusSnapshotMock) CommittedDepth() uint8 { return m.committedDepth }