From 2a8a5072bd6f4212877b2dfa3036475562c7180e Mon Sep 17 00:00:00 2001 From: sarathsp06 Date: Mon, 15 Jun 2020 16:27:02 +0200 Subject: [PATCH 1/2] test/fix: fix tests that failed due to multiple appearence of version componant in path --- contact/contact_test.go | 5 ++++- group/group_test.go | 6 ++++-- number/number_test.go | 2 +- signature/signature.go | 2 +- signature/signature_test.go | 3 +-- sms/message_test.go | 4 +++- voice/callflow_test.go | 6 +++--- voice/main_test.go | 2 +- voice/recording.go | 6 +++--- voice/recording_test.go | 3 +-- voice/transcription_test.go | 2 +- voice/voice_test.go | 4 ++-- 12 files changed, 25 insertions(+), 20 deletions(-) diff --git a/contact/contact_test.go b/contact/contact_test.go index b298a27..75265db 100644 --- a/contact/contact_test.go +++ b/contact/contact_test.go @@ -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) diff --git a/group/group_test.go b/group/group_test.go index 318b64d..b8f1383 100644 --- a/group/group_test.go +++ b/group/group_test.go @@ -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) } diff --git a/number/number_test.go b/number/number_test.go index a76fa30..5c7402a 100644 --- a/number/number_test.go +++ b/number/number_test.go @@ -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) } diff --git a/signature/signature.go b/signature/signature.go index 3aee845..8dc5135 100644 --- a/signature/signature.go +++ b/signature/signature.go @@ -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)) diff --git a/signature/signature_test.go b/signature/signature_test.go index db220a5..3144456 100644 --- a/signature/signature_test.go +++ b/signature/signature_test.go @@ -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) } } diff --git a/sms/message_test.go b/sms/message_test.go index ae5fa11..81e54ad 100644 --- a/sms/message_test.go +++ b/sms/message_test.go @@ -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() diff --git a/voice/callflow_test.go b/voice/callflow_test.go index ad0db83..cac1438 100644 --- a/voice/callflow_test.go +++ b/voice/callflow_test.go @@ -57,7 +57,7 @@ func TestCallFlowJSONMarshal(t *testing.T) { Length: time.Second * 10, }, &CallFlowRecordStep{ - CallFlowStepBase: CallFlowStepBase{ + CallFlowStepBase: CallFlowStepBase{ ID: "3", }, MaxLength: 10, @@ -143,7 +143,7 @@ func TestCallFlowJSONUnmarshal(t *testing.T) { Length: time.Second * 10, }, &CallFlowRecordStep{ - CallFlowStepBase: CallFlowStepBase{ + CallFlowStepBase: CallFlowStepBase{ ID: "3", }, MaxLength: 10, @@ -186,7 +186,7 @@ func TestCreateCallFlow(t *testing.T) { Length: time.Second, }, &CallFlowRecordStep{ - CallFlowStepBase: CallFlowStepBase{ + CallFlowStepBase: CallFlowStepBase{ ID: "3", }, MaxLength: 10, diff --git a/voice/main_test.go b/voice/main_test.go index 043624f..28b828d 100644 --- a/voice/main_test.go +++ b/voice/main_test.go @@ -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()) { diff --git a/voice/recording.go b/voice/recording.go index 35a6710..ae6fc8d 100644 --- a/voice/recording.go +++ b/voice/recording.go @@ -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 } @@ -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{})) } @@ -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. diff --git a/voice/recording_test.go b/voice/recording_test.go index 47c2b78..4eb09b4 100644 --- a/voice/recording_test.go +++ b/voice/recording_test.go @@ -36,7 +36,7 @@ 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) } @@ -44,7 +44,6 @@ func TestDelete(t *testing.T) { 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) diff --git a/voice/transcription_test.go b/voice/transcription_test.go index 68fb603..6ba8f04 100644 --- a/voice/transcription_test.go +++ b/voice/transcription_test.go @@ -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)) } diff --git a/voice/voice_test.go b/voice/voice_test.go index 006c59e..d1edd7f 100644 --- a/voice/voice_test.go +++ b/voice/voice_test.go @@ -61,11 +61,11 @@ func TestErrorResponseError(t *testing.T) { err := ErrorResponse{ []Error{ { - Code: 1, + Code: 1, Message: "foo", }, { - Code: 2, + Code: 2, Message: "bar", }, }, From 2db5a6068b64336d8ab727fbd6b564d4f2626198 Mon Sep 17 00:00:00 2001 From: sarathsp06 Date: Mon, 15 Jun 2020 16:47:25 +0200 Subject: [PATCH 2/2] travis: bump up version and set import path --- .travis.yml | 3 ++- go.mod | 2 +- sms/message_test.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 52a0478..60717d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: go +go_import_path: github.com/messagebird/go-rest-api go: - - "1.12" - "1.13" + - "1.14" - stable - master matrix: diff --git a/go.mod b/go.mod index a90af91..92f422a 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/messagebird/go-rest-api -go 1.12 +go 1.13 \ No newline at end of file diff --git a/sms/message_test.go b/sms/message_test.go index 81e54ad..0afa4b6 100644 --- a/sms/message_test.go +++ b/sms/message_test.go @@ -316,7 +316,7 @@ func TestListScheduled(t *testing.T) { t.Errorf("API call should contain filter by status (%v), but is is not %v", expectedStatusFilter, r.URL.String()) } if _, err := w.Write(mbtest.Testdata(t, "messageListScheduledObject.json")); err != nil { - t.Fatalf("unexpected error responding to list scheduled request") + t.Fatalf("unexpected error responding to list scheduled request. err: %s", err) } }) transport, teardown := mbtest.HTTPTestTransport(h)