Skip to content

Commit 3659144

Browse files
authored
Merge pull request #719 from iotaledger/remove/snap-endpoint-target-slot
Remove target slot from `CreateSnapshot` endpoint
2 parents 054bd7d + 62d963e commit 3659144

5 files changed

+12
-40
lines changed

api/management.go

-6
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ type (
5757
Epoch iotago.EpochIndex `serix:""`
5858
}
5959

60-
// CreateSnapshotRequest defines the request of a create snapshot REST API call.
61-
CreateSnapshotRequest struct {
62-
// The slot of the snapshot.
63-
Slot iotago.SlotIndex `serix:""`
64-
}
65-
6660
// CreateSnapshotResponse defines the response of a create snapshot REST API call.
6761
CreateSnapshotResponse struct {
6862
// The slot of the snapshot.

api/management_test.go

-16
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@ func Test_ManagementAPIDeSerialize(t *testing.T) {
6868
},
6969
Target: &api.PruneDatabaseResponse{},
7070
},
71-
{
72-
Name: "ok - CreateSnapshotRequest",
73-
Source: &api.CreateSnapshotRequest{
74-
Slot: 1,
75-
},
76-
Target: &api.CreateSnapshotRequest{},
77-
},
7871
{
7972
Name: "ok - CreateSnapshotResponse",
8073
Source: &api.CreateSnapshotResponse{
@@ -185,15 +178,6 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) {
185178
},
186179
Target: `{
187180
"epoch": 1
188-
}`,
189-
},
190-
{
191-
Name: "ok - CreateSnapshotRequest",
192-
Source: &api.CreateSnapshotRequest{
193-
Slot: 1,
194-
},
195-
Target: `{
196-
"slot": 1
197181
}`,
198182
},
199183
{

nodeclient/http_api_client_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ func mockGetJSONWithParams(route string, status int, body interface{}, params ma
7676

7777
//nolint:unparam // false positive
7878
func mockPostJSON(route string, status int, req interface{}, resp interface{}) {
79-
gock.New(nodeAPIUrl).
80-
Post(route).
81-
MatchHeader("Content-Type", api.MIMEApplicationJSON).
82-
BodyString(string(lo.PanicOnErr(mockAPI.JSONEncode(req)))).
83-
Reply(status).
79+
mock := gock.New(nodeAPIUrl).Post(route)
80+
if req != nil {
81+
mock.MatchHeader("Content-Type", api.MIMEApplicationJSON).
82+
BodyString(string(lo.PanicOnErr(mockAPI.JSONEncode(req))))
83+
}
84+
85+
mock.Reply(status).
8486
SetHeader("Content-Type", api.MIMEApplicationJSON).
8587
BodyString(string(lo.PanicOnErr(mockAPI.JSONEncode(resp))))
8688
}

nodeclient/management_client.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type (
2626
// PruneDatabaseByDepth prunes the database by depth.
2727
PruneDatabaseByDepth(ctx context.Context, depth iotago.EpochIndex) (*api.PruneDatabaseResponse, error)
2828
// CreateSnapshot creates a snapshot.
29-
CreateSnapshot(ctx context.Context, slot iotago.SlotIndex) (*api.CreateSnapshotResponse, error)
29+
CreateSnapshot(ctx context.Context) (*api.CreateSnapshotResponse, error)
3030
}
3131

3232
managementClient struct {
@@ -147,14 +147,10 @@ func (client *managementClient) PruneDatabaseByDepth(ctx context.Context, depth
147147
}
148148

149149
// CreateSnapshot creates a snapshot.
150-
func (client *managementClient) CreateSnapshot(ctx context.Context, slot iotago.SlotIndex) (*api.CreateSnapshotResponse, error) {
151-
req := &api.CreateSnapshotRequest{
152-
Slot: slot,
153-
}
154-
150+
func (client *managementClient) CreateSnapshot(ctx context.Context) (*api.CreateSnapshotResponse, error) {
155151
res := new(api.CreateSnapshotResponse)
156152
//nolint:bodyclose
157-
if _, err := client.DoWithRequestHeaderHook(ctx, http.MethodPost, api.ManagementRouteSnapshotsCreate, RequestHeaderHookAcceptJSON, req, res); err != nil {
153+
if _, err := client.DoWithRequestHeaderHook(ctx, http.MethodPost, api.ManagementRouteSnapshotsCreate, RequestHeaderHookAcceptJSON, nil, res); err != nil {
158154
return nil, err
159155
}
160156

nodeclient/management_client_test.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -267,28 +267,24 @@ func TestManagementClient_PruneDatabaseByDepth(t *testing.T) {
267267
func TestManagementClient_CreateSnapshot(t *testing.T) {
268268
defer gock.Off()
269269

270-
slot := iotago.SlotIndex(1)
271-
272270
originRes := &api.CreateSnapshotResponse{
273271
Slot: 1,
274272
FilePath: "filePath",
275273
}
276274

277-
req := &api.CreateSnapshotRequest{Slot: slot}
278-
279275
originRoutes := &api.RoutesResponse{
280276
Routes: []iotago.PrefixedStringUint8{api.ManagementPluginName},
281277
}
282278

283279
mockGetJSON(api.RouteRoutes, 200, originRoutes)
284-
mockPostJSON(api.ManagementRouteSnapshotsCreate, 200, req, originRes)
280+
mockPostJSON(api.ManagementRouteSnapshotsCreate, 200, nil, originRes)
285281

286282
client := nodeClient(t)
287283

288284
management, err := client.Management(context.TODO())
289285
require.NoError(t, err)
290286

291-
resp, err := management.CreateSnapshot(context.Background(), slot)
287+
resp, err := management.CreateSnapshot(context.Background())
292288
require.NoError(t, err)
293289
require.EqualValues(t, originRes, resp)
294290
}

0 commit comments

Comments
 (0)