From e8b2b01e7c697435f3d20657cdef0ecd54b62d14 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 15 Sep 2021 21:29:12 +0200 Subject: Rewrote navitia_api_client tests for consistency --- pkg/navitia_api_client/stops_test.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'pkg/navitia_api_client/stops_test.go') diff --git a/pkg/navitia_api_client/stops_test.go b/pkg/navitia_api_client/stops_test.go index c3a91f2..b04946f 100644 --- a/pkg/navitia_api_client/stops_test.go +++ b/pkg/navitia_api_client/stops_test.go @@ -3,11 +3,9 @@ package navitia_api_client import ( "net/http" "net/http/httptest" - "reflect" "testing" "git.adyxax.org/adyxax/trains/pkg/model" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -17,10 +15,10 @@ func TestGetStops(t *testing.T) { name string inputNewCLient string expected []model.Stop - expectedError interface{} + expectedError error }{ - {"invalid characters in token should fail", "}", nil, &HttpClientError{}}, - {"unreachable server should fail", "https://", nil, &HttpClientError{}}, + {"invalid characters in token should fail", "}", nil, HttpClientError{}}, + {"unreachable server should fail", "https://", nil, HttpClientError{}}, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { @@ -28,11 +26,11 @@ func TestGetStops(t *testing.T) { valid, err := client.GetStops() if tc.expectedError != nil { require.Error(t, err) - assert.Equalf(t, reflect.TypeOf(err), reflect.TypeOf(tc.expectedError), "Invalid error type. Got %s but expected %s", reflect.TypeOf(err), reflect.TypeOf(tc.expectedError)) - assert.Equal(t, tc.expected, valid) + requireErrorTypeMatch(t, err, tc.expectedError) + require.Equal(t, tc.expected, valid) } else { require.NoError(t, err) - assert.Equal(t, tc.expected, valid) + require.Equal(t, tc.expected, valid) } }) } @@ -41,9 +39,9 @@ func TestGetStops(t *testing.T) { name string inputFilename string expected []model.Stop - expectedError interface{} + expectedError error }{ - {"invalid json should fail", "test_data/invalid.json", nil, &JsonDecodeError{}}, + {"invalid json should fail", "test_data/invalid.json", nil, JsonDecodeError{}}, } for _, tc := range testCasesFilename { t.Run(tc.name, func(t *testing.T) { @@ -52,11 +50,11 @@ func TestGetStops(t *testing.T) { valid, err := client.GetStops() if tc.expectedError != nil { require.Error(t, err) - assert.Equalf(t, reflect.TypeOf(err), reflect.TypeOf(tc.expectedError), "Invalid error type. Got %s but expected %s", reflect.TypeOf(err), reflect.TypeOf(tc.expectedError)) - assert.Equal(t, tc.expected, valid) + requireErrorTypeMatch(t, err, tc.expectedError) + require.Equal(t, tc.expected, valid) } else { require.NoError(t, err) - assert.Equal(t, tc.expected, valid) + require.Equal(t, tc.expected, valid) } }) } -- cgit v1.2.3