Skip to content

Commit

Permalink
Merge pull request #719 from iotaledger/remove/snap-endpoint-target-slot
Browse files Browse the repository at this point in the history
Remove target slot from `CreateSnapshot` endpoint
  • Loading branch information
muXxer authored Apr 25, 2024
2 parents 054bd7d + 62d963e commit 3659144
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 40 deletions.
6 changes: 0 additions & 6 deletions api/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ type (
Epoch iotago.EpochIndex `serix:""`
}

// CreateSnapshotRequest defines the request of a create snapshot REST API call.
CreateSnapshotRequest struct {
// The slot of the snapshot.
Slot iotago.SlotIndex `serix:""`
}

// CreateSnapshotResponse defines the response of a create snapshot REST API call.
CreateSnapshotResponse struct {
// The slot of the snapshot.
Expand Down
16 changes: 0 additions & 16 deletions api/management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ func Test_ManagementAPIDeSerialize(t *testing.T) {
},
Target: &api.PruneDatabaseResponse{},
},
{
Name: "ok - CreateSnapshotRequest",
Source: &api.CreateSnapshotRequest{
Slot: 1,
},
Target: &api.CreateSnapshotRequest{},
},
{
Name: "ok - CreateSnapshotResponse",
Source: &api.CreateSnapshotResponse{
Expand Down Expand Up @@ -185,15 +178,6 @@ func Test_ManagementAPIJSONSerialization(t *testing.T) {
},
Target: `{
"epoch": 1
}`,
},
{
Name: "ok - CreateSnapshotRequest",
Source: &api.CreateSnapshotRequest{
Slot: 1,
},
Target: `{
"slot": 1
}`,
},
{
Expand Down
12 changes: 7 additions & 5 deletions nodeclient/http_api_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ func mockGetJSONWithParams(route string, status int, body interface{}, params ma

//nolint:unparam // false positive
func mockPostJSON(route string, status int, req interface{}, resp interface{}) {
gock.New(nodeAPIUrl).
Post(route).
MatchHeader("Content-Type", api.MIMEApplicationJSON).
BodyString(string(lo.PanicOnErr(mockAPI.JSONEncode(req)))).
Reply(status).
mock := gock.New(nodeAPIUrl).Post(route)
if req != nil {
mock.MatchHeader("Content-Type", api.MIMEApplicationJSON).
BodyString(string(lo.PanicOnErr(mockAPI.JSONEncode(req))))
}

mock.Reply(status).
SetHeader("Content-Type", api.MIMEApplicationJSON).
BodyString(string(lo.PanicOnErr(mockAPI.JSONEncode(resp))))
}
Expand Down
10 changes: 3 additions & 7 deletions nodeclient/management_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type (
// PruneDatabaseByDepth prunes the database by depth.
PruneDatabaseByDepth(ctx context.Context, depth iotago.EpochIndex) (*api.PruneDatabaseResponse, error)
// CreateSnapshot creates a snapshot.
CreateSnapshot(ctx context.Context, slot iotago.SlotIndex) (*api.CreateSnapshotResponse, error)
CreateSnapshot(ctx context.Context) (*api.CreateSnapshotResponse, error)
}

managementClient struct {
Expand Down Expand Up @@ -147,14 +147,10 @@ func (client *managementClient) PruneDatabaseByDepth(ctx context.Context, depth
}

// CreateSnapshot creates a snapshot.
func (client *managementClient) CreateSnapshot(ctx context.Context, slot iotago.SlotIndex) (*api.CreateSnapshotResponse, error) {
req := &api.CreateSnapshotRequest{
Slot: slot,
}

func (client *managementClient) CreateSnapshot(ctx context.Context) (*api.CreateSnapshotResponse, error) {
res := new(api.CreateSnapshotResponse)
//nolint:bodyclose
if _, err := client.DoWithRequestHeaderHook(ctx, http.MethodPost, api.ManagementRouteSnapshotsCreate, RequestHeaderHookAcceptJSON, req, res); err != nil {
if _, err := client.DoWithRequestHeaderHook(ctx, http.MethodPost, api.ManagementRouteSnapshotsCreate, RequestHeaderHookAcceptJSON, nil, res); err != nil {
return nil, err
}

Expand Down
8 changes: 2 additions & 6 deletions nodeclient/management_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,28 +267,24 @@ func TestManagementClient_PruneDatabaseByDepth(t *testing.T) {
func TestManagementClient_CreateSnapshot(t *testing.T) {
defer gock.Off()

slot := iotago.SlotIndex(1)

originRes := &api.CreateSnapshotResponse{
Slot: 1,
FilePath: "filePath",
}

req := &api.CreateSnapshotRequest{Slot: slot}

originRoutes := &api.RoutesResponse{
Routes: []iotago.PrefixedStringUint8{api.ManagementPluginName},
}

mockGetJSON(api.RouteRoutes, 200, originRoutes)
mockPostJSON(api.ManagementRouteSnapshotsCreate, 200, req, originRes)
mockPostJSON(api.ManagementRouteSnapshotsCreate, 200, nil, originRes)

client := nodeClient(t)

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

resp, err := management.CreateSnapshot(context.Background(), slot)
resp, err := management.CreateSnapshot(context.Background())
require.NoError(t, err)
require.EqualValues(t, originRes, resp)
}

0 comments on commit 3659144

Please sign in to comment.