Skip to content

Commit

Permalink
test/fix: fix tests that failed due to multiple appearence of version…
Browse files Browse the repository at this point in the history
… componant in path
  • Loading branch information
sarathsp06 committed Jun 15, 2020
1 parent c2d85f0 commit 2a8a507
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 20 deletions.
5 changes: 4 additions & 1 deletion contact/contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ func TestListPagination(t *testing.T) {
}

for _, tc := range tt {
List(client, tc.options)
_, err := List(client, tc.options)
if err != nil {
t.Fatalf("unexpected error listing contacts: %s", err)
}

if query := mbtest.Request.URL.RawQuery; query != tc.expected {
t.Fatalf("expected %s, got %s", tc.expected, query)
Expand Down
6 changes: 4 additions & 2 deletions group/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ func TestListPagination(t *testing.T) {
}

for _, tc := range tt {
List(client, tc.options)

_, err := List(client, tc.options)
if err != nil {
t.Fatalf("unexpected error listing groups: %s", err)
}
if query := mbtest.Request.URL.RawQuery; query != tc.expected {
t.Fatalf("got %s, expected %s", tc.expected, query)
}
Expand Down
2 changes: 1 addition & 1 deletion number/number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestUpdate(t *testing.T) {

mbtest.AssertEndpointCalled(t, http.MethodPatch, "/v1/phone-numbers/31612345670")
mbtest.AssertTestdata(t, "numberUpdateRequestObject.json", mbtest.Request.Body)

if !reflect.DeepEqual(number.Tags, []string{"tag1", "tag2", "tag3"}) {
t.Errorf("Unexpected number tags: %s, expected: ['tag1', 'tag2', 'tag3']", number.Tags)
}
Expand Down
2 changes: 1 addition & 1 deletion signature/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (v *Validator) ValidRequest(r *http.Request) error {
return fmt.Errorf("Unknown host: %s", r.Host)
}
b, _ := ioutil.ReadAll(r.Body)
if v.validTimestamp(ts) == false || v.validSignature(ts, r.URL.RawQuery, b, rs) == false {
if !v.validTimestamp(ts) || !v.validSignature(ts, r.URL.RawQuery, b, rs) {
return fmt.Errorf("Unknown host: %s", r.Host)
}
r.Body = ioutil.NopCloser(bytes.NewBuffer(b))
Expand Down
3 changes: 1 addition & 2 deletions signature/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ func TestCalculateSignature(t *testing.T) {
t.Errorf("Error calculating signature: %s, expected: %s", s, tt.es)
}
drs, _ := base64.StdEncoding.DecodeString(tt.es)
e := bool(bytes.Compare(s, drs) == 0)
if e != tt.e {
if bytes.Equal(s, drs) != tt.e {
t.Errorf("Unexpected signature: %s, test case: %s", s, tt.name)
}
}
Expand Down
4 changes: 3 additions & 1 deletion sms/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ func TestListScheduled(t *testing.T) {
if !strings.Contains(r.URL.String(), expectedStatusFilter) {
t.Errorf("API call should contain filter by status (%v), but is is not %v", expectedStatusFilter, r.URL.String())
}
w.Write(mbtest.Testdata(t, "messageListScheduledObject.json"))
if _, err := w.Write(mbtest.Testdata(t, "messageListScheduledObject.json")); err != nil {
t.Fatalf("unexpected error responding to list scheduled request")
}
})
transport, teardown := mbtest.HTTPTestTransport(h)
defer teardown()
Expand Down
6 changes: 3 additions & 3 deletions voice/callflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestCallFlowJSONMarshal(t *testing.T) {
Length: time.Second * 10,
},
&CallFlowRecordStep{
CallFlowStepBase: CallFlowStepBase{
CallFlowStepBase: CallFlowStepBase{
ID: "3",
},
MaxLength: 10,
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestCallFlowJSONUnmarshal(t *testing.T) {
Length: time.Second * 10,
},
&CallFlowRecordStep{
CallFlowStepBase: CallFlowStepBase{
CallFlowStepBase: CallFlowStepBase{
ID: "3",
},
MaxLength: 10,
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestCreateCallFlow(t *testing.T) {
Length: time.Second,
},
&CallFlowRecordStep{
CallFlowStepBase: CallFlowStepBase{
CallFlowStepBase: CallFlowStepBase{
ID: "3",
},
MaxLength: 10,
Expand Down
2 changes: 1 addition & 1 deletion voice/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"
"testing"

"github.com/messagebird/go-rest-api"
messagebird "github.com/messagebird/go-rest-api"
)

func testRequest(status int, body []byte) (*messagebird.Client, func()) {
Expand Down
6 changes: 3 additions & 3 deletions voice/recording.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func ReadRecording(c *messagebird.Client, callID, legID, id string) (*Recording,
Data []*Recording `json:"data"`
})

if err := c.Request(json, http.MethodGet, fmt.Sprintf("%s/v1/calls/%s/legs/%s/recordings/%s",
if err := c.Request(json, http.MethodGet, fmt.Sprintf("%s/calls/%s/legs/%s/recordings/%s",
apiRoot, callID, legID, id), nil); err != nil {
return nil, err
}
Expand All @@ -82,7 +82,7 @@ func ReadRecording(c *messagebird.Client, callID, legID, id string) (*Recording,

// Recordings returns a Paginator which iterates over Recordings.
func Recordings(c *messagebird.Client, callID, legID string) *Paginator {
return newPaginator(c, fmt.Sprintf("%s/v1/calls/%s/legs/%s/recordings", apiRoot, callID,
return newPaginator(c, fmt.Sprintf("%s/calls/%s/legs/%s/recordings", apiRoot, callID,
legID), reflect.TypeOf(Recording{}))
}

Expand Down Expand Up @@ -111,7 +111,7 @@ func (rec *Recording) Transcriptions(client *messagebird.Client, callID string)

// Delete deletes a recording.
func Delete(client *messagebird.Client, callID, legID, recordingID string) error {
return client.Request(nil, http.MethodDelete, fmt.Sprintf("%s/v1/calls/%s/legs/%s/recordings/%s", apiRoot, callID, legID, recordingID), nil)
return client.Request(nil, http.MethodDelete, fmt.Sprintf("%s/calls/%s/legs/%s/recordings/%s", apiRoot, callID, legID, recordingID), nil)
}

// DownloadFile streams the recorded WAV file.
Expand Down
3 changes: 1 addition & 2 deletions voice/recording_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ func TestRecordingGetFile(t *testing.T) {

func TestDelete(t *testing.T) {
mbtest.WillReturn([]byte(""), http.StatusNoContent)
client := mbtest.Client(t)
client := mbtest.Client(t)
if err := Delete(client, "callid", "legid", "recid"); err != nil {
t.Errorf("unexpected error while deleting recording: %s", err)
}

mbtest.AssertEndpointCalled(t, http.MethodDelete, "/v1/calls/callid/legs/legid/recordings/recid")
}


func TestReadRecording(t *testing.T) {
mbtest.WillReturnTestdata(t, "recordingObject.json", http.StatusOK)
client := mbtest.Client(t)
Expand Down
2 changes: 1 addition & 1 deletion voice/transcription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ func TestCreateTranscription(t *testing.T) {
t.Fatal(err)
}

mbtest.AssertEndpointCalled(t, http.MethodPost, fmt.Sprintf("/calls/%s/legs/%s/recordings/%s/transcriptions", callID, legID, recordingID))
mbtest.AssertEndpointCalled(t, http.MethodPost, fmt.Sprintf("/v1/calls/%s/legs/%s/recordings/%s/transcriptions", callID, legID, recordingID))
}
4 changes: 2 additions & 2 deletions voice/voice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ func TestErrorResponseError(t *testing.T) {
err := ErrorResponse{
[]Error{
{
Code: 1,
Code: 1,
Message: "foo",
},
{
Code: 2,
Code: 2,
Message: "bar",
},
},
Expand Down

0 comments on commit 2a8a507

Please sign in to comment.