diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2022-04-05 04:30:42 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2022-04-05 04:30:42 +0300 |
commit | 5321248fd47127cc71f719aaafefc364379a9c56 (patch) | |
tree | 24b222b5f2639457ab2c74199c916dd72ca76694 | |
parent | 8b79c056065c776fef0da08bf4a3de6e4da99aad (diff) | |
parent | 524b1783131079915e1fa22b7c8523e5aa4e728b (diff) |
Merge branch 'refactor/specialized-require' into 'master'
test: replace require.Equal with specialized assertions
See merge request gitlab-org/gitlab-pages!685
-rw-r--r-- | internal/auth/auth_test.go | 8 | ||||
-rw-r--r-- | internal/handlers/handlers_test.go | 6 | ||||
-rw-r--r-- | internal/httptransport/transport_test.go | 14 | ||||
-rw-r--r-- | internal/source/gitlab/cache/cache_test.go | 16 | ||||
-rw-r--r-- | internal/source/gitlab/client/client_test.go | 6 | ||||
-rw-r--r-- | test/acceptance/auth_test.go | 4 | ||||
-rw-r--r-- | test/acceptance/serving_test.go | 4 |
7 files changed, 29 insertions, 29 deletions
diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 9f38877a..586c3839 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -453,9 +453,9 @@ func TestGenerateKeys(t *testing.T) { require.NotEqual(t, fmt.Sprint(keys[0]), fmt.Sprint(keys[2])) require.NotEqual(t, fmt.Sprint(keys[1]), fmt.Sprint(keys[2])) - require.Equal(t, len(keys[0]), 32) - require.Equal(t, len(keys[1]), 32) - require.Equal(t, len(keys[2]), 32) + require.Len(t, keys[0], 32) + require.Len(t, keys[1], 32) + require.Len(t, keys[2], 32) } func TestGetTokenIfExistsWhenTokenExists(t *testing.T) { @@ -487,7 +487,7 @@ func TestGetTokenIfExistsWhenTokenDoesNotExist(t *testing.T) { token, err := auth.GetTokenIfExists(result, r) require.Equal(t, "", token) - require.Equal(t, nil, err) + require.NoError(t, err) } func TestCheckResponseForInvalidTokenWhenInvalidToken(t *testing.T) { diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index 22027ad0..e6dc95db 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -35,7 +35,7 @@ func TestNotHandleArtifactRequestReturnsFalse(t *testing.T) { require.NoError(t, err) r := &http.Request{URL: reqURL} - require.Equal(t, false, handlers.HandleArtifactRequest("host", result, r)) + require.False(t, handlers.HandleArtifactRequest("host", result, r)) } func TestHandleArtifactRequestedReturnsTrue(t *testing.T) { @@ -58,7 +58,7 @@ func TestHandleArtifactRequestedReturnsTrue(t *testing.T) { result := httptest.NewRecorder() r := httptest.NewRequest(http.MethodGet, "/something", nil) - require.Equal(t, true, handlers.HandleArtifactRequest("host", result, r)) + require.True(t, handlers.HandleArtifactRequest("host", result, r)) } func TestNotFoundWithTokenIsNotHandled(t *testing.T) { @@ -186,5 +186,5 @@ func TestHandleArtifactRequestButGetTokenFails(t *testing.T) { result := httptest.NewRecorder() r := httptest.NewRequest(http.MethodGet, "/something", nil) - require.Equal(t, true, handlers.HandleArtifactRequest("host", result, r)) + require.True(t, handlers.HandleArtifactRequest("host", result, r)) } diff --git a/internal/httptransport/transport_test.go b/internal/httptransport/transport_test.go index a51e7a02..7ebc2c98 100644 --- a/internal/httptransport/transport_test.go +++ b/internal/httptransport/transport_test.go @@ -124,11 +124,11 @@ func (mrt *mockRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) } func TestInternalTransportShouldHaveCustomConnectionPoolSettings(t *testing.T) { - require.EqualValues(t, 100, DefaultTransport.MaxIdleConns) - require.EqualValues(t, 100, DefaultTransport.MaxIdleConnsPerHost) - require.EqualValues(t, 0, DefaultTransport.MaxConnsPerHost) - require.EqualValues(t, 90*time.Second, DefaultTransport.IdleConnTimeout) - require.EqualValues(t, 10*time.Second, DefaultTransport.TLSHandshakeTimeout) - require.EqualValues(t, 15*time.Second, DefaultTransport.ResponseHeaderTimeout) - require.EqualValues(t, 15*time.Second, DefaultTransport.ExpectContinueTimeout) + require.Equal(t, 100, DefaultTransport.MaxIdleConns) + require.Equal(t, 100, DefaultTransport.MaxIdleConnsPerHost) + require.Equal(t, 0, DefaultTransport.MaxConnsPerHost) + require.Equal(t, 90*time.Second, DefaultTransport.IdleConnTimeout) + require.Equal(t, 10*time.Second, DefaultTransport.TLSHandshakeTimeout) + require.Equal(t, 15*time.Second, DefaultTransport.ResponseHeaderTimeout) + require.Equal(t, 15*time.Second, DefaultTransport.ExpectContinueTimeout) } diff --git a/internal/source/gitlab/cache/cache_test.go b/internal/source/gitlab/cache/cache_test.go index 8b37ffc6..267c9b29 100644 --- a/internal/source/gitlab/cache/cache_test.go +++ b/internal/source/gitlab/cache/cache_test.go @@ -104,7 +104,7 @@ type entryConfig struct { func TestResolve(t *testing.T) { t.Run("when item is not cached", func(t *testing.T) { withTestCache(resolverConfig{buffered: true}, nil, func(cache *Cache, resolver *clientMock) { - require.Equal(t, 0, len(resolver.lookups)) + require.Empty(t, resolver.lookups) resolver.domain <- "my.gitlab.com" lookup := cache.Resolve(context.Background(), "my.gitlab.com") @@ -130,7 +130,7 @@ func TestResolve(t *testing.T) { go receiver() go receiver() - require.Equal(t, 0, len(resolver.lookups)) + require.Empty(t, resolver.lookups) resolver.domain <- "my.gitlab.com" wg.Wait() @@ -145,7 +145,7 @@ func TestResolve(t *testing.T) { lookup := cache.Resolve(context.Background(), "my.gitlab.com") require.Equal(t, "my.gitlab.com", lookup.Name) - require.Equal(t, 0, len(resolver.lookups)) + require.Empty(t, resolver.lookups) }) }) }) @@ -159,7 +159,7 @@ func TestResolve(t *testing.T) { lookup <- cache.Resolve(context.Background(), "my.gitlab.com") }() - require.Equal(t, 0, len(resolver.lookups)) + require.Empty(t, resolver.lookups) resolver.domain <- "my.gitlab.com" <-lookup @@ -175,7 +175,7 @@ func TestResolve(t *testing.T) { lookup := cache.Resolve(context.Background(), "my.gitlab.com") require.Equal(t, "my.gitlab.com", lookup.Name) - require.Equal(t, 0, len(resolver.lookups)) + require.Empty(t, resolver.lookups) resolver.domain <- "my.gitlab.com" @@ -191,7 +191,7 @@ func TestResolve(t *testing.T) { cache.Resolve(context.Background(), "my.gitlab.com") cache.Resolve(context.Background(), "my.gitlab.com") - require.Equal(t, 0, len(resolver.lookups)) + require.Empty(t, resolver.lookups) resolver.domain <- "my.gitlab.com" @@ -208,7 +208,7 @@ func TestResolve(t *testing.T) { withTestCache(resolverConfig{failure: err}, &cc, func(cache *Cache, resolver *clientMock) { lookup := cache.Resolve(context.Background(), "my.gitlab.com") - require.Equal(t, 3, len(resolver.lookups)) + require.Len(t, resolver.lookups, 3) require.EqualError(t, lookup.Error, "500 error") }) }) @@ -220,7 +220,7 @@ func TestResolve(t *testing.T) { withTestCache(resolverConfig{}, &cc, func(cache *Cache, resolver *clientMock) { lookup := cache.Resolve(context.Background(), "my.gitlab.com") - require.Equal(t, 0, len(resolver.lookups)) + require.Empty(t, resolver.lookups) require.ErrorIs(t, lookup.Error, context.DeadlineExceeded) }) }) diff --git a/internal/source/gitlab/client/client_test.go b/internal/source/gitlab/client/client_test.go index 01e382d1..1a6572db 100644 --- a/internal/source/gitlab/client/client_test.go +++ b/internal/source/gitlab/client/client_test.go @@ -131,7 +131,7 @@ func TestNewInvalidConfiguration(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := NewClient(tt.args.baseURL, tt.args.secretKey, tt.args.connectionTimeout, tt.args.jwtTokenExpiry) require.Nil(t, got) - require.NotNil(t, err) + require.Error(t, err) require.Contains(t, err.Error(), tt.wantErrMsg) }) } @@ -225,8 +225,8 @@ func TestGetVirtualDomainAuthenticatedRequest(t *testing.T) { lookupPath := lookup.Domain.LookupPaths[0] require.Equal(t, 123, lookupPath.ProjectID) - require.Equal(t, false, lookupPath.AccessControl) - require.Equal(t, true, lookupPath.HTTPSOnly) + require.False(t, lookupPath.AccessControl) + require.True(t, lookupPath.HTTPSOnly) require.Equal(t, "/myproject/", lookupPath.Prefix) require.Equal(t, "file", lookupPath.Source.Type) diff --git a/test/acceptance/auth_test.go b/test/acceptance/auth_test.go index dbc7b900..022afcbd 100644 --- a/test/acceptance/auth_test.go +++ b/test/acceptance/auth_test.go @@ -38,7 +38,7 @@ func TestWhenAuthIsEnabledPrivateWillRedirectToAuthorize(t *testing.T) { testhelpers.Close(t, rsp.Body) require.Equal(t, http.StatusFound, rsp.StatusCode) - require.Equal(t, 1, len(rsp.Header["Location"])) + require.Len(t, rsp.Header["Location"], 1) url, err := url.Parse(rsp.Header.Get("Location")) require.NoError(t, err) rsp, err = GetRedirectPage(t, httpsListener, url.Host, url.Path+"?"+url.RawQuery) @@ -46,7 +46,7 @@ func TestWhenAuthIsEnabledPrivateWillRedirectToAuthorize(t *testing.T) { testhelpers.Close(t, rsp.Body) require.Equal(t, http.StatusFound, rsp.StatusCode) - require.Equal(t, 1, len(rsp.Header["Location"])) + require.Len(t, rsp.Header["Location"], 1) url, err = url.Parse(rsp.Header.Get("Location")) require.NoError(t, err) diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go index bab69357..1808b5e7 100644 --- a/test/acceptance/serving_test.go +++ b/test/acceptance/serving_test.go @@ -279,7 +279,7 @@ func TestHttpToHttpsRedirectEnabled(t *testing.T) { require.NoError(t, err) testhelpers.Close(t, rsp.Body) require.Equal(t, http.StatusTemporaryRedirect, rsp.StatusCode) - require.Equal(t, 1, len(rsp.Header["Location"])) + require.Len(t, rsp.Header["Location"], 1) require.Equal(t, "https://group.gitlab-example.com/project/", rsp.Header.Get("Location")) rsp, err = GetPageFromListener(t, httpsListener, "group.gitlab-example.com", "project/") @@ -455,7 +455,7 @@ func TestQueryStringPersistedInSlashRewrite(t *testing.T) { testhelpers.Close(t, rsp.Body) require.Equal(t, http.StatusFound, rsp.StatusCode) - require.Equal(t, 1, len(rsp.Header["Location"])) + require.Len(t, rsp.Header["Location"], 1) require.Equal(t, "//group.gitlab-example.com/project/?q=test", rsp.Header.Get("Location")) rsp, err = GetPageFromListener(t, httpsListener, "group.gitlab-example.com", "project/?q=test") |