mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-04 03:42:49 +02:00
databroker: add patch method (#4704)
Add a Patch() method to the databroker gRPC service. Update the storage.Backend interface to include the Patch() method now that all the storage.Backend implementations include it. Add a test to exercise the patch method under concurrent usage.
This commit is contained in:
parent
4842002ed7
commit
d5da872157
9 changed files with 760 additions and 337 deletions
|
@ -18,6 +18,7 @@ import (
|
|||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/durationpb"
|
||||
"google.golang.org/protobuf/types/known/fieldmaskpb"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
|
@ -84,6 +85,58 @@ func TestServer_Get(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestServer_Patch(t *testing.T) {
|
||||
cfg := newServerConfig()
|
||||
srv := newServer(cfg)
|
||||
|
||||
s := &session.Session{
|
||||
Id: "1",
|
||||
OauthToken: &session.OAuthToken{AccessToken: "access-token"},
|
||||
}
|
||||
data := protoutil.NewAny(s)
|
||||
_, err := srv.Put(context.Background(), &databroker.PutRequest{
|
||||
Records: []*databroker.Record{{
|
||||
Type: data.TypeUrl,
|
||||
Id: s.Id,
|
||||
Data: data,
|
||||
}},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
fm, err := fieldmaskpb.New(s, "accessed_at")
|
||||
require.NoError(t, err)
|
||||
|
||||
now := timestamppb.Now()
|
||||
s.AccessedAt = now
|
||||
s.OauthToken.AccessToken = "access-token-field-ignored"
|
||||
data = protoutil.NewAny(s)
|
||||
patchResponse, err := srv.Patch(context.Background(), &databroker.PatchRequest{
|
||||
Records: []*databroker.Record{{
|
||||
Type: data.TypeUrl,
|
||||
Id: s.Id,
|
||||
Data: data,
|
||||
}},
|
||||
FieldMask: fm,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
testutil.AssertProtoEqual(t, protoutil.NewAny(&session.Session{
|
||||
Id: "1",
|
||||
AccessedAt: now,
|
||||
OauthToken: &session.OAuthToken{AccessToken: "access-token"},
|
||||
}), patchResponse.GetRecord().GetData())
|
||||
|
||||
getResponse, err := srv.Get(context.Background(), &databroker.GetRequest{
|
||||
Type: data.TypeUrl,
|
||||
Id: s.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
testutil.AssertProtoEqual(t, protoutil.NewAny(&session.Session{
|
||||
Id: "1",
|
||||
AccessedAt: now,
|
||||
OauthToken: &session.OAuthToken{AccessToken: "access-token"},
|
||||
}), getResponse.GetRecord().GetData())
|
||||
}
|
||||
|
||||
func TestServer_Options(t *testing.T) {
|
||||
cfg := newServerConfig()
|
||||
srv := newServer(cfg)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue