Skip to content

Commit

Permalink
Merge pull request #768 from nyaruka/latest_gocommon
Browse files Browse the repository at this point in the history
Update to latest gocommon
  • Loading branch information
rowanseymour authored Aug 2, 2024
2 parents ab5c5d9 + f0954df commit 72b9661
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 22 deletions.
3 changes: 2 additions & 1 deletion attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"testing"
"time"

"github.com/nyaruka/courier"
"github.com/nyaruka/courier/test"
Expand Down Expand Up @@ -39,7 +40,7 @@ func TestFetchAndStoreAttachment(t *testing.T) {
}))

defer uuids.SetGenerator(uuids.DefaultGenerator)
uuids.SetGenerator(uuids.NewSeededGenerator(1234))
uuids.SetGenerator(uuids.NewSeededGenerator(1234, time.Now))

ctx := context.Background()
mb := test.NewMockBackend()
Expand Down
2 changes: 1 addition & 1 deletion backends/rapidpro/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ func (b *backend) WriteChannelLog(ctx context.Context, clog *courier.ChannelLog)
// SaveAttachment saves an attachment to backend storage
func (b *backend) SaveAttachment(ctx context.Context, ch courier.Channel, contentType string, data []byte, extension string) (string, error) {
// create our filename
filename := string(uuids.New())
filename := string(uuids.NewV4())
if extension != "" {
filename = fmt.Sprintf("%s.%s", filename, extension)
}
Expand Down
4 changes: 2 additions & 2 deletions backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ func (ts *BackendTestSuite) TestSaveAttachment() {
knChannel := ts.getChannel("KN", "dbc126ed-66bc-4e28-b67b-81dc3327c95d")

defer uuids.SetGenerator(uuids.DefaultGenerator)
uuids.SetGenerator(uuids.NewSeededGenerator(1234))
uuids.SetGenerator(uuids.NewSeededGenerator(1234, time.Now))

newURL, err := ts.b.SaveAttachment(ctx, knChannel, "image/jpeg", testJPG, "jpg")
ts.NoError(err)
Expand Down Expand Up @@ -1204,7 +1204,7 @@ func (ts *BackendTestSuite) TestWriteMsgWithAttachments() {
ctx := context.Background()

defer uuids.SetGenerator(uuids.DefaultGenerator)
uuids.SetGenerator(uuids.NewSeededGenerator(1234))
uuids.SetGenerator(uuids.NewSeededGenerator(1234, time.Now))

knChannel := ts.getChannel("KN", "dbc126ed-66bc-4e28-b67b-81dc3327c95d")
clog := courier.NewChannelLog(courier.ChannelLogTypeUnknown, knChannel, nil)
Expand Down
2 changes: 1 addition & 1 deletion backends/rapidpro/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func contactForURN(ctx context.Context, b *backend, org OrgID, channel *Channel,

// didn't find it, we need to create it instead
contact.OrgID_ = org
contact.UUID_ = courier.ContactUUID(uuids.New())
contact.UUID_ = courier.ContactUUID(uuids.NewV4())
contact.CreatedOn_ = time.Now()
contact.ModifiedOn_ = time.Now()
contact.IsNew_ = true
Expand Down
2 changes: 1 addition & 1 deletion backends/rapidpro/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func newMsg(direction MsgDirection, channel courier.Channel, urn urns.URN, text

return &Msg{
OrgID_: dbChannel.OrgID(),
UUID_: courier.MsgUUID(uuids.New()),
UUID_: courier.MsgUUID(uuids.NewV4()),
Direction_: direction,
Status_: courier.MsgStatusPending,
Visibility_: MsgVisible,
Expand Down
6 changes: 3 additions & 3 deletions celery/celery.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const defaultBody = `[[], {}, {"chord": null, "callbacks": null, "errbacks": nul
// QueueEmptyTask queues a new empty task with the passed in task name for the passed in queue
func QueueEmptyTask(rc redis.Conn, queueName string, taskName string) error {
body := base64.StdEncoding.EncodeToString([]byte(defaultBody))
taskUUID := string(uuids.New())
deliveryTag := string(uuids.New())
taskUUID := string(uuids.NewV4())
deliveryTag := string(uuids.NewV4())

task := Task{
Body: body,
Expand All @@ -63,7 +63,7 @@ func QueueEmptyTask(rc redis.Conn, queueName string, taskName string) error {
Properties: TaskProperties{
BodyEncoding: "base64",
CorrelationID: taskUUID,
ReplyTo: string(uuids.New()),
ReplyTo: string(uuids.NewV4()),
DeliveryMode: 2,
DeliveryTag: deliveryTag,
DeliveryInfo: TaskDeliveryInfo{
Expand Down
2 changes: 1 addition & 1 deletion channel_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func NewChannelLog(t ChannelLogType, ch Channel, redactVals []string) *ChannelLo

func newChannelLog(t ChannelLogType, ch Channel, r *httpx.Recorder, attached bool, redactVals []string) *ChannelLog {
return &ChannelLog{
uuid: ChannelLogUUID(uuids.New()),
uuid: ChannelLogUUID(uuids.NewV4()),
type_: t,
channel: ch,
recorder: r,
Expand Down
2 changes: 1 addition & 1 deletion channel_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestChannelLog(t *testing.T) {
}))
defer httpx.SetRequestor(httpx.DefaultRequestor)

uuids.SetGenerator(uuids.NewSeededGenerator(1234))
uuids.SetGenerator(uuids.NewSeededGenerator(1234, time.Now))
defer uuids.SetGenerator(uuids.DefaultGenerator)

channel := test.NewMockChannel("fef91e9b-a6ed-44fb-b6ce-feed8af585a8", "NX", "1234", "US", []string{urns.Phone.Prefix}, nil)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9
github.com/nyaruka/ezconf v0.3.0
github.com/nyaruka/gocommon v1.56.4
github.com/nyaruka/gocommon v1.57.1
github.com/nyaruka/null/v3 v3.0.0
github.com/nyaruka/redisx v0.8.1
github.com/patrickmn/go-cache v2.1.0+incompatible
Expand All @@ -43,10 +43,10 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/jellydator/ttlcache/v3 v3.2.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4
github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down Expand Up @@ -122,8 +120,8 @@ github.com/naoina/toml v0.1.1 h1:PT/lllxVVN0gzzSqSlHEmP8MJB4MY2U7STGxiouV4X8=
github.com/naoina/toml v0.1.1/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
github.com/nyaruka/ezconf v0.3.0 h1:kGvJqVN8AHowb4HdaHAviJ0Z3yI5Pyekp1WqibFEaGk=
github.com/nyaruka/ezconf v0.3.0/go.mod h1:89GUW6EPRNLIxT7lC4LWnjWTgZeQwRoX7lBmc8ralAU=
github.com/nyaruka/gocommon v1.56.4 h1:wE6dnqpFBRRwNO5CLFVb4mnU/uf5g3AX9Ivh7WwxfZQ=
github.com/nyaruka/gocommon v1.56.4/go.mod h1:XDCG6LNrYCH7XfRBDmwue1WMqoJXyltmhTvmBQy2XIk=
github.com/nyaruka/gocommon v1.57.1 h1:s/9WLZAOUNg0dQHZkgpx8qQMUtNJ2mqzxQhdk1+UBn4=
github.com/nyaruka/gocommon v1.57.1/go.mod h1:wa++Yu/8PEP/HwfvXZrGlKZUCPSJAtSJHeuVsWtLOPM=
github.com/nyaruka/librato v1.1.1 h1:0nTYtJLl3Sn7lX3CuHsLf+nXy1k/tGV0OjVxLy3Et4s=
github.com/nyaruka/librato v1.1.1/go.mod h1:fme1Fu1PT2qvkaBZyw8WW+SrnFe2qeeCWpvqmAaKAKE=
github.com/nyaruka/null/v2 v2.0.3 h1:rdmMRQyVzrOF3Jff/gpU/7BDR9mQX0lcLl4yImsA3kw=
Expand Down
2 changes: 1 addition & 1 deletion handlers/clickmobile/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func TestOutgoing(t *testing.T) {
)

// mock time so we can have predictable MD5 hashes
dates.SetNowSource(dates.NewFixedNowSource(time.Date(2018, 4, 11, 18, 24, 30, 123456000, time.UTC)))
dates.SetNowFunc(dates.NewFixedNow(time.Date(2018, 4, 11, 18, 24, 30, 123456000, time.UTC)))

RunOutgoingTestCases(t, ch, newHandler(), outgoingCases, []string{"Password"}, nil)
}
2 changes: 1 addition & 1 deletion handlers/telesom/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestOutgoing(t *testing.T) {
)

// mock time so we can have predictable MD5 hashes
dates.SetNowSource(dates.NewFixedNowSource(time.Date(2018, 4, 11, 18, 24, 30, 123456000, time.UTC)))
dates.SetNowFunc(dates.NewFixedNow(time.Date(2018, 4, 11, 18, 24, 30, 123456000, time.UTC)))

RunOutgoingTestCases(t, defaultChannel, newHandler(), defaultSendTestCases, []string{"Password", "secret"}, nil)
}
2 changes: 1 addition & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func TestFetchAttachment(t *testing.T) {
httpx.SetRequestor(httpMocks)

defer uuids.SetGenerator(uuids.DefaultGenerator)
uuids.SetGenerator(uuids.NewSeededGenerator(1234))
uuids.SetGenerator(uuids.NewSeededGenerator(1234, time.Now))

logger := slog.Default()
config := courier.NewDefaultConfig()
Expand Down
4 changes: 2 additions & 2 deletions test/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (mb *MockBackend) GetChannelByAddress(ctx context.Context, cType courier.Ch
func (mb *MockBackend) GetContact(ctx context.Context, channel courier.Channel, urn urns.URN, authTokens map[string]string, name string, clog *courier.ChannelLog) (courier.Contact, error) {
contact, found := mb.contacts[urn]
if !found {
contact = &mockContact{channel, urn, authTokens, courier.ContactUUID(uuids.New())}
contact = &mockContact{channel, urn, authTokens, courier.ContactUUID(uuids.NewV4())}
mb.contacts[urn] = contact
}
return contact, nil
Expand Down Expand Up @@ -341,7 +341,7 @@ func (mb *MockBackend) SaveAttachment(ctx context.Context, ch courier.Channel, c

time.Sleep(time.Millisecond * 2)

return fmt.Sprintf("https://backend.com/attachments/%s.%s", uuids.New(), extension), nil
return fmt.Sprintf("https://backend.com/attachments/%s.%s", uuids.NewV4(), extension), nil
}

// ResolveMedia resolves the passed in media URL to a media object
Expand Down

0 comments on commit 72b9661

Please sign in to comment.