Skip to content

Commit

Permalink
Change delegate actor to use upper 'ID', fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cjslep committed Jul 5, 2020
1 parent 574f226 commit ee53bc0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pub/base_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (b *baseActor) deliver(c context.Context, outbox *url.URL, asValue vocab.Ty
return
}
// Delegate generating new IDs for the activity and all new objects.
if err = b.delegate.AddNewIds(c, activity); err != nil {
if err = b.delegate.AddNewIDs(c, activity); err != nil {
return
}
// Post the activity to the actor's outbox and trigger side effects for
Expand Down
12 changes: 6 additions & 6 deletions pub/base_actor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func TestBaseActorSocialProtocol(t *testing.T) {
req := toAPRequest(toPostOutboxRequest(testCreateNoId))
delegate.EXPECT().AuthenticatePostOutbox(ctx, resp, req).Return(ctx, true, nil)
delegate.EXPECT().PostOutboxRequestBodyHook(ctx, req, toDeserializedForm(testCreateNoId)).Return(ctx, nil)
delegate.EXPECT().AddNewIds(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
delegate.EXPECT().AddNewIDs(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
withNewId(activity)
return nil
})
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestBaseActorSocialProtocol(t *testing.T) {
delegate.EXPECT().WrapInCreate(ctx, toDeserializedForm(testMyNote), mustParse(testMyOutboxIRI)).DoAndReturn(func(c context.Context, t vocab.Type, u *url.URL) (vocab.ActivityStreamsCreate, error) {
return wrappedInCreate(t), nil
})
delegate.EXPECT().AddNewIds(ctx, wrappedInCreate(toDeserializedForm(testMyNote))).DoAndReturn(func(c context.Context, activity Activity) error {
delegate.EXPECT().AddNewIDs(ctx, wrappedInCreate(toDeserializedForm(testMyNote))).DoAndReturn(func(c context.Context, activity Activity) error {
withNewId(activity)
return nil
})
Expand All @@ -244,7 +244,7 @@ func TestBaseActorSocialProtocol(t *testing.T) {
req := toAPRequest(toPostOutboxRequest(testCreateNoId))
delegate.EXPECT().AuthenticatePostOutbox(ctx, resp, req).Return(ctx, true, nil)
delegate.EXPECT().PostOutboxRequestBodyHook(ctx, req, toDeserializedForm(testCreateNoId)).Return(ctx, nil)
delegate.EXPECT().AddNewIds(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
delegate.EXPECT().AddNewIDs(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
withNewId(activity)
return nil
})
Expand All @@ -270,7 +270,7 @@ func TestBaseActorSocialProtocol(t *testing.T) {
req := toAPRequest(toPostOutboxRequest(testCreateNoId))
delegate.EXPECT().AuthenticatePostOutbox(ctx, resp, req).Return(ctx, true, nil)
delegate.EXPECT().PostOutboxRequestBodyHook(ctx, req, toDeserializedForm(testCreateNoId)).Return(ctx, nil)
delegate.EXPECT().AddNewIds(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
delegate.EXPECT().AddNewIDs(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
withNewId(activity)
return nil
})
Expand Down Expand Up @@ -705,7 +705,7 @@ func TestBaseActor(t *testing.T) {
req := toAPRequest(toPostOutboxRequest(testCreateNoId))
delegate.EXPECT().AuthenticatePostOutbox(ctx, resp, req).Return(ctx, true, nil)
delegate.EXPECT().PostOutboxRequestBodyHook(ctx, req, toDeserializedForm(testCreateNoId)).Return(ctx, nil)
delegate.EXPECT().AddNewIds(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
delegate.EXPECT().AddNewIDs(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
withNewId(activity)
return nil
})
Expand Down Expand Up @@ -733,7 +733,7 @@ func TestBaseActor(t *testing.T) {
req := toAPRequest(toPostOutboxRequest(testCreateNoId))
delegate.EXPECT().AuthenticatePostOutbox(ctx, resp, req).Return(ctx, true, nil)
delegate.EXPECT().PostOutboxRequestBodyHook(ctx, req, toDeserializedForm(testCreateNoId)).Return(ctx, nil)
delegate.EXPECT().AddNewIds(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
delegate.EXPECT().AddNewIDs(ctx, toDeserializedForm(testCreateNoId)).DoAndReturn(func(c context.Context, activity Activity) error {
withNewId(activity)
return nil
})
Expand Down
4 changes: 2 additions & 2 deletions pub/delegate_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ type DelegateActor interface {
// values that are simply not present, the 'rawJSON' map is ONLY needed
// for this narrow and specific use case.
PostOutbox(c context.Context, a Activity, outboxIRI *url.URL, rawJSON map[string]interface{}) (deliverable bool, e error)
// AddNewIds sets new URL ids on the activity. It also does so for all
// AddNewIDs sets new URL ids on the activity. It also does so for all
// 'object' properties if the Activity is a Create type.
//
// Only called if the Social API is enabled.
//
// If an error is returned, it is returned to the caller of PostOutbox.
AddNewIds(c context.Context, a Activity) error
AddNewIDs(c context.Context, a Activity) error
// Deliver sends a federated message. Called only if federation is
// enabled.
//
Expand Down
12 changes: 6 additions & 6 deletions pub/mock_database_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pub/mock_delegate_actor_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pub/side_effect_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (a *sideEffectActor) PostInbox(c context.Context, inboxIRI *url.URL, activi
wrapped.inboxIRI = inboxIRI
wrapped.newTransport = a.common.NewTransport
wrapped.deliver = a.Deliver
wrapped.addNewIds = a.AddNewIds
wrapped.addNewIds = a.AddNewIDs
res, err := streams.NewTypeResolver(wrapped.callbacks(other)...)
if err != nil {
return err
Expand Down Expand Up @@ -360,10 +360,10 @@ func (a *sideEffectActor) PostOutbox(c context.Context, activity Activity, outbo
return
}

// AddNewIds creates new 'id' entries on an activity and its objects if it is a
// AddNewIDs creates new 'id' entries on an activity and its objects if it is a
// Create activity.
func (a *sideEffectActor) AddNewIds(c context.Context, activity Activity) error {
id, err := a.db.NewId(c, activity)
func (a *sideEffectActor) AddNewIDs(c context.Context, activity Activity) error {
id, err := a.db.NewID(c, activity)
if err != nil {
return err
}
Expand All @@ -381,7 +381,7 @@ func (a *sideEffectActor) AddNewIds(c context.Context, activity Activity) error
if t == nil {
return fmt.Errorf("cannot add new id for object in Create: object is not embedded as a value literal")
}
id, err = a.db.NewId(c, t)
id, err = a.db.NewID(c, t)
if err != nil {
return err
}
Expand Down
22 changes: 11 additions & 11 deletions pub/side_effect_actor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,9 @@ func TestPostOutbox(t *testing.T) {
})
}

// TestAddNewIds ensures that new 'id' properties are set on an activity and all
// TestAddNewIDs ensures that new 'id' properties are set on an activity and all
// of its 'object' property values if it is a Create activity.
func TestAddNewIds(t *testing.T) {
func TestAddNewIDs(t *testing.T) {
ctx := context.Background()
setupFn := func(ctl *gomock.Controller) (c *MockCommonBehavior, fp *MockFederatingProtocol, sp *MockSocialProtocol, db *MockDatabase, cl *MockClock, a DelegateActor) {
setupData()
Expand All @@ -1006,9 +1006,9 @@ func TestAddNewIds(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()
_, _, _, db, _, a := setupFn(ctl)
db.EXPECT().NewId(ctx, testMyListenNoId).Return(mustParse(testNewActivityIRI2), nil)
db.EXPECT().NewID(ctx, testMyListenNoId).Return(mustParse(testNewActivityIRI2), nil)
// Run
err := a.AddNewIds(ctx, testMyListenNoId)
err := a.AddNewIDs(ctx, testMyListenNoId)
// Verify
assertEqual(t, err, nil)
resultId := testMyListenNoId.GetJSONLDId()
Expand All @@ -1020,9 +1020,9 @@ func TestAddNewIds(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()
_, _, _, db, _, a := setupFn(ctl)
db.EXPECT().NewId(ctx, testMyListen).Return(mustParse(testNewActivityIRI2), nil)
db.EXPECT().NewID(ctx, testMyListen).Return(mustParse(testNewActivityIRI2), nil)
// Run
err := a.AddNewIds(ctx, testMyListen)
err := a.AddNewIDs(ctx, testMyListen)
// Verify
assertEqual(t, err, nil)
resultId := testMyListen.GetJSONLDId()
Expand All @@ -1034,10 +1034,10 @@ func TestAddNewIds(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()
_, _, _, db, _, a := setupFn(ctl)
db.EXPECT().NewId(ctx, testMyCreate).Return(mustParse(testNewActivityIRI2), nil)
db.EXPECT().NewId(ctx, testMyNote).Return(mustParse(testNewActivityIRI3), nil)
db.EXPECT().NewID(ctx, testMyCreate).Return(mustParse(testNewActivityIRI2), nil)
db.EXPECT().NewID(ctx, testMyNote).Return(mustParse(testNewActivityIRI3), nil)
// Run
err := a.AddNewIds(ctx, testMyCreate)
err := a.AddNewIDs(ctx, testMyCreate)
// Verify
assertEqual(t, err, nil)
op := testMyCreate.GetActivityStreamsObject()
Expand All @@ -1054,9 +1054,9 @@ func TestAddNewIds(t *testing.T) {
ctl := gomock.NewController(t)
defer ctl.Finish()
_, _, _, db, _, a := setupFn(ctl)
db.EXPECT().NewId(ctx, testMyListenNoId).Return(mustParse(testNewActivityIRI2), nil)
db.EXPECT().NewID(ctx, testMyListenNoId).Return(mustParse(testNewActivityIRI2), nil)
// Run
err := a.AddNewIds(ctx, testMyListenNoId)
err := a.AddNewIDs(ctx, testMyListenNoId)
// Verify
assertEqual(t, err, nil)
op := testMyListenNoId.GetActivityStreamsObject()
Expand Down

0 comments on commit ee53bc0

Please sign in to comment.