-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Financial-Times/10pc/image-set-changes
ImageSet republishing changes
- Loading branch information
Showing
10 changed files
with
247 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/Financial-Times/uuid-utils-go" | ||
) | ||
|
||
type imageSetUUIDResolver interface { | ||
GetImageSetsModelUUID(setUUID, tid string) (found bool, modelUUID string, err error) | ||
} | ||
|
||
type uuidImageSetResolver struct { | ||
} | ||
|
||
func newUUIDImageSetResolver() imageSetUUIDResolver { | ||
return &uuidImageSetResolver{} | ||
} | ||
|
||
func (r *uuidImageSetResolver) GetImageSetsModelUUID(setUUID, tid string) (found bool, modelUUID string, err error) { | ||
requestedUUID, _ := uuidutils.NewUUIDFromString(setUUID) | ||
derivedUUID, _ := uuidutils.NewUUIDDeriverWith(uuidutils.IMAGE_SET).From(requestedUUID) | ||
return true, derivedUUID.String(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUuidImageSetResolver(t *testing.T) { | ||
r := newUUIDImageSetResolver() | ||
|
||
imageSetUUID := "9f365884-0c25-11e8-24ad-bec2279df517" | ||
|
||
found, imageModelUUID, err := r.GetImageSetsModelUUID(imageSetUUID, "tid_test") | ||
assert.True(t, found, "found image model UUID") | ||
assert.Equal(t, "9f365884-0c25-11e8-bacb-2958fde95e5e", imageModelUUID, "image model UUID") | ||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type notifyingSequentialRepublisher struct { | ||
uuidRepublisher uuidRepublisher | ||
} | ||
|
||
func newNotifyingSequentialRepublisher(uuidRepublisher uuidRepublisher) bulkRepublisher { | ||
return ¬ifyingSequentialRepublisher{ | ||
uuidRepublisher: uuidRepublisher, | ||
} | ||
} | ||
|
||
func (r *notifyingSequentialRepublisher) Republish(uuids []string, publishScope string, tidPrefix string) ([]*okMsg, []error) { | ||
var msgs []*okMsg | ||
var errs []error | ||
|
||
for _, uuid := range uuids { | ||
tmsgs, terrs := r.uuidRepublisher.Republish(uuid, tidPrefix, publishScope) | ||
|
||
for _, msg := range tmsgs { | ||
log.Info(msg) | ||
msgs = append(msgs, msg) | ||
} | ||
for _, err := range terrs { | ||
log.Error(err) | ||
errs = append(errs, err) | ||
} | ||
} | ||
|
||
return msgs, errs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestSequentialRepublishSingle_Ok(t *testing.T) { | ||
mockedUUIDRepublisher := new(mockUUIDRepublisher) | ||
msg := okMsg{ | ||
uuid: "19cf2763-90b1-40db-90e7-e813425ebe81", | ||
tid: "prefix1", | ||
collectionName: "collection1", | ||
collectionOriginSystemID: "originSystemId1", | ||
sizeBytes: 1024, | ||
notifierAppName: "cms-notifier", | ||
} | ||
mockedUUIDRepublisher.On("Republish", "19cf2763-90b1-40db-90e7-e813425ebe81", "prefix1", scopeBoth).Return([]*okMsg{&msg}, []error{}) | ||
|
||
pRepublisher := newNotifyingSequentialRepublisher(mockedUUIDRepublisher) | ||
|
||
pRepublisher.Republish([]string{"19cf2763-90b1-40db-90e7-e813425ebe81"}, scopeBoth, "prefix1") | ||
|
||
mock.AssertExpectationsForObjects(t, mockedUUIDRepublisher) | ||
} | ||
|
||
func TestRepublishMultiple_Ok(t *testing.T) { | ||
mockedUUIDRepublisher := new(mockUUIDRepublisher) | ||
nOk := 10 | ||
nErr := 5 | ||
uuids := []string{} | ||
for i := 0; i < nOk; i++ { | ||
uuids = append(uuids, "19cf2763-90b1-40db-90e7-e813425ebe81") | ||
} | ||
for i := 0; i < nErr; i++ { | ||
uuids = append(uuids, "70357268-04f7-4149-bb17-217d3eb56d49") | ||
} | ||
msg1 := okMsg{ | ||
uuid: "19cf2763-90b1-40db-90e7-e813425ebe81", | ||
tid: "prefix1tid_123", | ||
collectionName: "collection1", | ||
collectionOriginSystemID: "originSystemId1", | ||
sizeBytes: 1024, | ||
notifierAppName: "cms-notifier", | ||
} | ||
msg2 := okMsg{ | ||
uuid: "19cf2763-90b1-40db-90e7-e813425ebe81", | ||
tid: "prefix1tid_456", | ||
collectionName: "collection2", | ||
collectionOriginSystemID: "originSystemId1", | ||
sizeBytes: 1024, | ||
notifierAppName: "cms-notifier", | ||
} | ||
err1 := fmt.Errorf("test some error publishing 1") | ||
err2 := fmt.Errorf("test some error publishing 2") | ||
mockedUUIDRepublisher.On("Republish", "19cf2763-90b1-40db-90e7-e813425ebe81", "prefix1", scopeBoth).Times(nOk).Return([]*okMsg{&msg1, &msg2}, []error{}) | ||
mockedUUIDRepublisher.On("Republish", "70357268-04f7-4149-bb17-217d3eb56d49", "prefix1", scopeBoth).Times(nErr).Return([]*okMsg{}, []error{err1, err2}) | ||
pRepublisher := newNotifyingSequentialRepublisher(mockedUUIDRepublisher) | ||
|
||
actualMsgs, actualErrs := pRepublisher.Republish(uuids, scopeBoth, "prefix1") | ||
|
||
mock.AssertExpectationsForObjects(t, mockedUUIDRepublisher) | ||
assert.Equal(t, 2*nOk, len(actualMsgs)) | ||
var msg1equal, msg2equal int | ||
for _, actualMsg := range actualMsgs { | ||
if msg1 == *actualMsg { | ||
msg1equal++ | ||
} else if msg2 == *actualMsg { | ||
msg2equal++ | ||
} | ||
} | ||
assert.Equal(t, nOk, msg1equal) | ||
assert.Equal(t, nOk, msg2equal) | ||
assert.Equal(t, 2*nErr, len(actualErrs)) | ||
var err1equal, err2equal int | ||
for _, actualErr := range actualErrs { | ||
if err1 == actualErr { | ||
err1equal++ | ||
} else if err2 == actualErr { | ||
err2equal++ | ||
} | ||
} | ||
assert.Equal(t, nErr, err1equal) | ||
assert.Equal(t, nErr, err2equal) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.