Skip to content

Commit 40b54ee

Browse files
committed
Move test code into test file
1 parent 35add0e commit 40b54ee

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

backends/rapidpro/backend_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package rapidpro
22

33
import (
44
"context"
5+
"database/sql"
56
"encoding/base64"
67
"encoding/json"
78
"fmt"
@@ -1526,3 +1527,26 @@ func readMsgFromDB(b *backend, id courier.MsgID) *DBMsg {
15261527
m.channel = ch
15271528
return m
15281529
}
1530+
1531+
const selectMsgIDForID = `
1532+
SELECT m."id" FROM "msgs_msg" m INNER JOIN "channels_channel" c ON (m."channel_id" = c."id") WHERE (m."id" = $1 AND c."uuid" = $2 AND m."direction" = 'O')`
1533+
1534+
const selectMsgIDForExternalID = `
1535+
SELECT m."id" FROM "msgs_msg" m INNER JOIN "channels_channel" c ON (m."channel_id" = c."id") WHERE (m."external_id" = $1 AND c."uuid" = $2 AND m."direction" = 'O')`
1536+
1537+
func checkMsgExists(b *backend, status courier.MsgStatus) (err error) {
1538+
var id int64
1539+
1540+
if status.ID() != courier.NilMsgID {
1541+
err = b.db.QueryRow(selectMsgIDForID, status.ID(), status.ChannelUUID()).Scan(&id)
1542+
} else if status.ExternalID() != "" {
1543+
err = b.db.QueryRow(selectMsgIDForExternalID, status.ExternalID(), status.ChannelUUID()).Scan(&id)
1544+
} else {
1545+
return fmt.Errorf("no id or external id for status update")
1546+
}
1547+
1548+
if err == sql.ErrNoRows {
1549+
return courier.ErrMsgNotFound
1550+
}
1551+
return err
1552+
}

backends/rapidpro/status.go

-24
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package rapidpro
22

33
import (
44
"context"
5-
"database/sql"
65
"encoding/json"
76
"errors"
87
"fmt"
@@ -56,29 +55,6 @@ func writeMsgStatus(ctx context.Context, b *backend, status courier.MsgStatus) e
5655
return err
5756
}
5857

59-
const selectMsgIDForID = `
60-
SELECT m."id" FROM "msgs_msg" m INNER JOIN "channels_channel" c ON (m."channel_id" = c."id") WHERE (m."id" = $1 AND c."uuid" = $2 AND m."direction" = 'O')`
61-
62-
const selectMsgIDForExternalID = `
63-
SELECT m."id" FROM "msgs_msg" m INNER JOIN "channels_channel" c ON (m."channel_id" = c."id") WHERE (m."external_id" = $1 AND c."uuid" = $2 AND m."direction" = 'O')`
64-
65-
func checkMsgExists(b *backend, status courier.MsgStatus) (err error) {
66-
var id int64
67-
68-
if status.ID() != courier.NilMsgID {
69-
err = b.db.QueryRow(selectMsgIDForID, status.ID(), status.ChannelUUID()).Scan(&id)
70-
} else if status.ExternalID() != "" {
71-
err = b.db.QueryRow(selectMsgIDForExternalID, status.ExternalID(), status.ChannelUUID()).Scan(&id)
72-
} else {
73-
return fmt.Errorf("no id or external id for status update")
74-
}
75-
76-
if err == sql.ErrNoRows {
77-
return courier.ErrMsgNotFound
78-
}
79-
return err
80-
}
81-
8258
// the craziness below lets us update our status to 'F' and schedule retries without knowing anything about the message
8359
const sqlUpdateMsgByID = `
8460
UPDATE msgs_msg SET

0 commit comments

Comments
 (0)