Skip to content

Commit

Permalink
Update apt-get before trying to install postgresql client
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Aug 22, 2022
1 parent e611798 commit 7461066
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ jobs:
postgresql password: temba

- name: Install Linux packages
run: sudo apt install -y --no-install-recommends postgresql-client
run: |
sudo apt-get update
sudo apt install -y --no-install-recommends postgresql-client
- name: Initialize database
# we create our test database with a different user so that we can drop everything owned by this user between tests
Expand Down
29 changes: 11 additions & 18 deletions core/models/channel_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import (
"github.com/stretchr/testify/require"
)

func TestChannelLogs(t *testing.T) {
func TestChannelLogsOutgoing(t *testing.T) {
ctx, rt, db, _ := testsuite.Get()

defer db.MustExec(`DELETE FROM channels_channellog`)

defer httpx.SetRequestor(httpx.DefaultRequestor)
httpx.SetRequestor(httpx.NewMockRequestor(map[string][]*httpx.MockResponse{
"http://rapidpro.io": {httpx.NewMockResponse(200, nil, []byte("OK"))},
"http://rapidpro.io/bad": {httpx.NewMockResponse(400, nil, []byte("Oops"))},
"http://rapidpro.io/new": {httpx.NewMockResponse(200, nil, []byte("OK"))},
"http://ivr.com/start": {httpx.NewMockResponse(200, nil, []byte("OK"))},
"http://ivr.com/hangup": {httpx.NewMockResponse(400, nil, []byte("Oops"))},
}))

oa, err := models.GetOrgAssets(ctx, rt, testdata.Org1.ID)
Expand All @@ -31,26 +30,20 @@ func TestChannelLogs(t *testing.T) {
channel := oa.ChannelByID(testdata.TwilioChannel.ID)
require.NotNil(t, channel)

req1, _ := httpx.NewRequest("GET", "http://rapidpro.io", nil, nil)
req1, _ := httpx.NewRequest("GET", "http://ivr.com/start", nil, nil)
trace1, err := httpx.DoTrace(http.DefaultClient, req1, nil, nil, -1)
require.NoError(t, err)
log1 := models.NewChannelLog(channel.ID(), nil, models.ChannelLogTypeIVRIncoming, trace1)
log1 := models.NewChannelLog(channel.ID(), nil, models.ChannelLogTypeIVRStart, trace1)

req2, _ := httpx.NewRequest("GET", "http://rapidpro.io/bad", nil, nil)
req2, _ := httpx.NewRequest("GET", "http://ivr.com/hangup", nil, nil)
trace2, err := httpx.DoTrace(http.DefaultClient, req2, nil, nil, -1)
require.NoError(t, err)
log2 := models.NewChannelLog(channel.ID(), nil, models.ChannelLogTypeIVRCallback, trace2)
log2 := models.NewChannelLog(channel.ID(), nil, models.ChannelLogTypeIVRHangup, trace2)

req3, _ := httpx.NewRequest("GET", "http://rapidpro.io/new", nil, map[string]string{"X-Forwarded-Path": "/old"})
trace3, err := httpx.DoTrace(http.DefaultClient, req3, nil, nil, -1)
err = models.InsertChannelLogs(ctx, db, []*models.ChannelLog{log1, log2})
require.NoError(t, err)
log3 := models.NewChannelLog(channel.ID(), nil, models.ChannelLogTypeIVRStatus, trace3)

err = models.InsertChannelLogs(ctx, db, []*models.ChannelLog{log1, log2, log3})
require.NoError(t, err)

assertdb.Query(t, db, `SELECT count(*) FROM channels_channellog`).Returns(3)
assertdb.Query(t, db, `SELECT count(*) FROM channels_channellog WHERE http_logs -> 0 ->> 'url' = 'http://rapidpro.io' AND is_error = FALSE AND channel_id = $1`, channel.ID()).Returns(1)
assertdb.Query(t, db, `SELECT count(*) FROM channels_channellog WHERE http_logs -> 0 ->> 'url' = 'http://rapidpro.io/bad' AND is_error = TRUE AND channel_id = $1`, channel.ID()).Returns(1)
assertdb.Query(t, db, `SELECT count(*) FROM channels_channellog WHERE http_logs -> 0 ->> 'url' = 'https://rapidpro.io/old' AND is_error = FALSE AND channel_id = $1`, channel.ID()).Returns(1)
assertdb.Query(t, db, `SELECT count(*) FROM channels_channellog`).Returns(2)
assertdb.Query(t, db, `SELECT count(*) FROM channels_channellog WHERE log_type = 'ivr_start' AND http_logs -> 0 ->> 'url' = 'http://ivr.com/start' AND is_error = FALSE AND channel_id = $1`, channel.ID()).Returns(1)
assertdb.Query(t, db, `SELECT count(*) FROM channels_channellog WHERE log_type = 'ivr_hangup' AND http_logs -> 0 ->> 'url' = 'http://ivr.com/hangup' AND is_error = TRUE AND channel_id = $1`, channel.ID()).Returns(1)
}

0 comments on commit 7461066

Please # to comment.