Skip to content

Commit 5907d26

Browse files
authored
chore(pkg/gw): support multiple kv pairs in set endpoint (#34)
* chore(pkg/gw): support multiple kv pairs in set endpoint Signed-off-by: Jeronimo Irazabal <[email protected]> * chore(pkg/gw): upgrade to immudb v1.5.0 Signed-off-by: Jeronimo Irazabal <[email protected]> --------- Signed-off-by: Jeronimo Irazabal <[email protected]>
1 parent df2e9eb commit 5907d26

File tree

12 files changed

+1035
-193
lines changed

12 files changed

+1035
-193
lines changed

cmd/immugw/command/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import (
2222
"github.com/codenotary/immudb/cmd/docs/man"
2323
c "github.com/codenotary/immudb/cmd/helper"
2424
"github.com/codenotary/immudb/cmd/version"
25+
"github.com/codenotary/immudb/embedded/logger"
2526
"github.com/codenotary/immudb/pkg/client"
2627
"github.com/codenotary/immudb/pkg/client/homedir"
2728
"github.com/codenotary/immudb/pkg/client/tokenservice"
28-
"github.com/codenotary/immudb/pkg/logger"
2929
"github.com/codenotary/immugw/cmd/immugw/command/service"
3030
"github.com/codenotary/immugw/pkg/gw"
3131
"github.com/spf13/cobra"

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ module github.com/codenotary/immugw
33
go 1.13
44

55
require (
6-
github.com/codenotary/immudb v1.4.1
7-
github.com/golang/protobuf v1.5.2
6+
github.com/codenotary/immudb v1.5.1-0.20230727141041-91c79c4bc953
7+
github.com/golang/protobuf v1.5.3
88
github.com/grpc-ecosystem/grpc-gateway v1.16.0
99
github.com/prometheus/client_golang v1.12.2
1010
github.com/rs/cors v1.7.0
11-
github.com/spf13/cobra v1.2.1
12-
github.com/spf13/viper v1.12.0
13-
github.com/stretchr/testify v1.7.1
11+
github.com/spf13/cobra v1.6.1
12+
github.com/spf13/viper v1.15.0
13+
github.com/stretchr/testify v1.8.3
1414
github.com/takama/daemon v0.12.0
15-
google.golang.org/grpc v1.46.2
15+
google.golang.org/grpc v1.56.2
1616
)
1717

1818
replace github.com/takama/daemon v0.12.0 => github.com/codenotary/daemon v0.0.0-20200507161650-3d4bcb5230f4

go.sum

Lines changed: 991 additions & 147 deletions
Large diffs are not rendered by default.

pkg/gw/immugw_server_mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ limitations under the License.
1717
package gw
1818

1919
import (
20+
"github.com/codenotary/immudb/embedded/logger"
2021
"github.com/codenotary/immudb/pkg/api/schema"
2122
"github.com/codenotary/immudb/pkg/client"
22-
"github.com/codenotary/immudb/pkg/logger"
2323
)
2424

2525
// TODO OGG: move this in a subpackage: gwtest

pkg/gw/immugw_server_mock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"errors"
2121
"testing"
2222

23+
"github.com/codenotary/immudb/embedded/logger"
2324
"github.com/codenotary/immudb/pkg/api/schema"
24-
"github.com/codenotary/immudb/pkg/logger"
2525
"github.com/stretchr/testify/require"
2626
)
2727

pkg/gw/metrics.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ package gw
1919
import (
2020
"expvar"
2121
"fmt"
22-
"github.com/codenotary/immudb/pkg/api/schema"
23-
"github.com/prometheus/client_golang/prometheus/promhttp"
2422
"net/http"
2523
"sync"
2624
"time"
2725

26+
"github.com/codenotary/immudb/pkg/api/schema"
27+
"github.com/prometheus/client_golang/prometheus/promhttp"
28+
2829
"github.com/prometheus/client_golang/prometheus/promauto"
2930

30-
"github.com/codenotary/immudb/pkg/logger"
31+
"github.com/codenotary/immudb/embedded/logger"
3132
"github.com/codenotary/immugw/pkg/json"
3233
"github.com/prometheus/client_golang/prometheus"
3334
)

pkg/gw/metrics_test.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ limitations under the License.
1616
package gw
1717

1818
import (
19-
"github.com/prometheus/client_golang/prometheus"
2019
"net/http"
2120
"net/http/httptest"
2221
"os"
2322
"testing"
2423

24+
"github.com/prometheus/client_golang/prometheus"
25+
26+
"github.com/codenotary/immudb/embedded/logger"
2527
"github.com/codenotary/immudb/pkg/api/schema"
26-
"github.com/codenotary/immudb/pkg/logger"
2728
"github.com/codenotary/immugw/pkg/json"
2829
"github.com/stretchr/testify/require"
2930
)
@@ -64,27 +65,27 @@ func TestLastAuditHandler(t *testing.T) {
6465
}
6566

6667
/*
67-
func TestLastAuditHandlerJSONError(t *testing.T) {
68-
req, err := http.NewRequest("GET", "/lastaudit", nil)
69-
require.NoError(t, err)
70-
rr := httptest.NewRecorder()
71-
72-
ms := metricServer{
73-
mc: &MetricsCollection{},
74-
srv: nil,
68+
func TestLastAuditHandlerJSONError(t *testing.T) {
69+
req, err := http.NewRequest("GET", "/lastaudit", nil)
70+
require.NoError(t, err)
71+
rr := httptest.NewRecorder()
72+
73+
ms := metricServer{
74+
mc: &MetricsCollection{},
75+
srv: nil,
76+
}
77+
78+
handlerWithJSONErr := http.HandlerFunc(ms.lastAuditHandler(newTestJSONWithMarshalErr()))
79+
handlerWithJSONErr.ServeHTTP(rr, req)
80+
require.Equal(
81+
t,
82+
http.StatusInternalServerError,
83+
rr.Code,
84+
"lastAuditHandler returned wrong status code: expected %v, actual %v",
85+
http.StatusInternalServerError,
86+
rr.Code)
87+
require.Contains(t, rr.Body.String(), "JSON marshal error")
7588
}
76-
77-
handlerWithJSONErr := http.HandlerFunc(ms.lastAuditHandler(newTestJSONWithMarshalErr()))
78-
handlerWithJSONErr.ServeHTTP(rr, req)
79-
require.Equal(
80-
t,
81-
http.StatusInternalServerError,
82-
rr.Code,
83-
"lastAuditHandler returned wrong status code: expected %v, actual %v",
84-
http.StatusInternalServerError,
85-
rr.Code)
86-
require.Contains(t, rr.Body.String(), "JSON marshal error")
87-
}
8889
*/
8990
func TestUpdateAuditResult(t *testing.T) {
9091
reg := prometheus.NewRegistry()

pkg/gw/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121
"testing"
2222
"time"
2323

24+
"github.com/codenotary/immudb/embedded/logger"
2425
"github.com/codenotary/immudb/pkg/client"
2526
"github.com/codenotary/immudb/pkg/client/homedir"
2627
"github.com/codenotary/immudb/pkg/client/tokenservice"
27-
"github.com/codenotary/immudb/pkg/logger"
2828
"github.com/codenotary/immudb/pkg/server"
2929
"github.com/codenotary/immudb/pkg/server/servertest"
3030
"github.com/stretchr/testify/assert"

pkg/gw/set_handler.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,12 @@ func (h *setHandler) Set(w http.ResponseWriter, req *http.Request, pathParams ma
9393
return
9494
}
9595

96-
if len(protoReq.KVs) > 1 {
97-
h.runtime.HTTPError(ctx, h.mux, outboundMarshaler, w, req, status.Error(codes.InvalidArgument, "set accept only one key value pair"))
98-
return
99-
}
100-
10196
if len(protoReq.KVs) == 0 {
10297
h.runtime.HTTPError(ctx, h.mux, outboundMarshaler, w, req, status.Error(codes.InvalidArgument, "set accept at least one key value pair"))
10398
return
10499
}
105100

106-
msg, err := client.Set(rctx, protoReq.KVs[0].Key, protoReq.KVs[0].Value)
101+
msg, err := client.SetAll(rctx, &protoReq)
107102
ctx = h.runtime.NewServerMetadataContext(rctx, metadata)
108103
if err != nil {
109104
h.runtime.HTTPError(ctx, h.mux, outboundMarshaler, w, req, mapSdkError(err))

pkg/gw/set_handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func setHandlerTestCases(mux *runtime.ServeMux, client immugwclient.Client, opts
6767
sh := NewSetHandler(mux, client, rt, json)
6868
icd, _ := immuclient.NewImmuClient(immuclient.DefaultOptions())
6969

70-
setWErr := func(context.Context, []byte, []byte) (*schema.TxHeader, error) {
70+
setAllWErr := func(context.Context, *schema.SetRequest) (*schema.TxHeader, error) {
7171
return nil, errors.New("set error")
7272
}
7373

@@ -177,7 +177,7 @@ func setHandlerTestCases(mux *runtime.ServeMux, client immugwclient.Client, opts
177177
},
178178
{
179179
"Set error",
180-
NewSetHandler(mux, immugwclient.NewMockClient(&clienttest.ImmuClientMock{ImmuClient: icd, SetF: setWErr}, opts), rt, json),
180+
NewSetHandler(mux, immugwclient.NewMockClient(&clienttest.ImmuClientMock{ImmuClient: icd, SetAllF: setAllWErr}, opts), rt, json),
181181
validPayload,
182182
func(t *testing.T, testCase string, status int, body map[string]interface{}) {
183183
requireResponseStatus(t, testCase, http.StatusInternalServerError, status)

0 commit comments

Comments
 (0)