mirror of https://github.com/dapr/go-sdk.git
added secret and secret tests
This commit is contained in:
parent
71008c5541
commit
63d675f6d0
|
@ -7,7 +7,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
@ -71,11 +70,10 @@ type testDaprServer struct {
|
|||
}
|
||||
|
||||
func (s *testDaprServer) InvokeService(ctx context.Context, req *pb.InvokeServiceRequest) (*commonv1pb.InvokeResponse, error) {
|
||||
r := &commonv1pb.InvokeResponse{
|
||||
return &commonv1pb.InvokeResponse{
|
||||
ContentType: req.Message.ContentType,
|
||||
Data: req.GetMessage().Data,
|
||||
}
|
||||
return r, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *testDaprServer) GetState(ctx context.Context, req *pb.GetStateRequest) (*pb.GetStateResponse, error) {
|
||||
|
@ -102,13 +100,16 @@ func (s *testDaprServer) PublishEvent(ctx context.Context, req *pb.PublishEventR
|
|||
}
|
||||
|
||||
func (s *testDaprServer) InvokeBinding(ctx context.Context, req *pb.InvokeBindingRequest) (*pb.InvokeBindingResponse, error) {
|
||||
r := &pb.InvokeBindingResponse{
|
||||
return &pb.InvokeBindingResponse{
|
||||
Data: req.Data,
|
||||
Metadata: req.Metadata,
|
||||
}
|
||||
return r, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *testDaprServer) GetSecret(ctx context.Context, req *pb.GetSecretRequest) (*pb.GetSecretResponse, error) {
|
||||
return nil, errors.New("method InvokeService not implemented")
|
||||
d := make(map[string]string, 0)
|
||||
d["test"] = "value"
|
||||
return &pb.GetSecretResponse{
|
||||
Data: d,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
pb "github.com/dapr/go-sdk/dapr/proto/runtime/v1"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// GetSecret gets secret by key from specified store
|
||||
func (c *Client) GetSecret(ctx context.Context, store, key string, meta map[string]string) (out map[string]string, err error) {
|
||||
if store == "" {
|
||||
return nil, errors.New("nil store")
|
||||
}
|
||||
if key == "" {
|
||||
return nil, errors.New("nil key")
|
||||
}
|
||||
|
||||
req := &pb.GetSecretRequest{
|
||||
Key: key,
|
||||
StoreName: store,
|
||||
Metadata: meta,
|
||||
}
|
||||
|
||||
resp, err := c.protoClient.GetSecret(authContext(ctx), req)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error invoking service")
|
||||
}
|
||||
|
||||
if resp != nil {
|
||||
out = resp.GetData()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func GetSecret(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client, closer := getTestClient(ctx)
|
||||
defer closer()
|
||||
|
||||
out, err := client.GetSecret(ctx, "store", "key1", nil)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, out)
|
||||
|
||||
in := make(map[string]string, 0)
|
||||
in["test"] = "value"
|
||||
|
||||
out, err = client.GetSecret(ctx, "store", "key1", in)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, out)
|
||||
}
|
Loading…
Reference in New Issue