Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Shushlin <vshushlin@gitlab.com>2022-02-04 18:51:59 +0300
committerVladimir Shushlin <vshushlin@gitlab.com>2022-02-04 18:51:59 +0300
commitd4a251ae1bb492fee8af0d3d3619bdd3f5bfc1c0 (patch)
tree482c57a73dcad998a599ba58dab7df8ecaca8259
parentf2fd9a8e0b4778991adf054ef8f3a7244200a60d (diff)
parentf4abddf5dce3f96b7e25ab76135feffdc9f5f986 (diff)
Merge branch 'test/move-mocks' into 'master'
test: move mocks to their own package See merge request gitlab-org/gitlab-pages!671
-rw-r--r--.golangci.yml18
-rw-r--r--Makefile.build.mk8
-rw-r--r--internal/auth/auth_test.go16
-rw-r--r--internal/domain/domain_test.go4
-rw-r--r--internal/domain/mock/resolver_mock.go (renamed from internal/mocks/resolver.go)4
-rw-r--r--internal/handlers/handlers_test.go24
-rw-r--r--internal/handlers/mock/handler_mock.go (renamed from internal/mocks/mocks.go)4
-rw-r--r--internal/source/gitlab/gitlab_test.go6
-rw-r--r--internal/source/gitlab/mock/client_mock.go (renamed from internal/mocks/client.go)6
-rw-r--r--internal/source/gitlab/mock/client_stub.go (renamed from internal/mocks/api/client_stub.go)2
-rw-r--r--internal/source/mock/source_mock.go (renamed from internal/mocks/source.go)4
11 files changed, 48 insertions, 48 deletions
diff --git a/.golangci.yml b/.golangci.yml
index c9fc0444..3b472def 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -1,17 +1,17 @@
run:
- # which dirs to skip: issues from them won't be reported;
- # can use regexp here: generated.*, regexp is applied on full path;
- # default value is empty list, but default dirs are skipped independently
- # from this option's value (see skip-dirs-use-default).
- # "/" will be replaced by current OS file path separator to properly work
- # on Windows.
- skip-dirs:
- - internal/mocks
-
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: false
+ # Which files to skip: they will be analyzed, but issues from them won't be reported.
+ # Default value is empty list,
+ # but there is no need to include all autogenerated files,
+ # we confidently recognize autogenerated files.
+ # If it's not please let us know.
+ # "/" will be replaced by current OS file path separator to properly work on Windows.
+ skip-files:
+ - _mock\.go
+
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
diff --git a/Makefile.build.mk b/Makefile.build.mk
index 350a7b99..6ee9218c 100644
--- a/Makefile.build.mk
+++ b/Makefile.build.mk
@@ -22,10 +22,10 @@ cisetup: .GOPATH/.ok
awk '/_/ {print $$2}' ./tools/main.go | grep -v -e mockgen -e golangci | xargs -tI % go install ${V:+-v -x} -modfile=tools/go.mod -mod=mod %
generate-mocks: .GOPATH/.ok
- $Q bin/mockgen -source=internal/interface.go -destination=internal/mocks/mocks.go -package=mocks
- $Q bin/mockgen -source=internal/source/source.go -destination=internal/mocks/source.go -package=mocks
- $Q bin/mockgen -source=internal/mocks/api/client_stub.go -destination=internal/mocks/client.go -package=mocks
- $Q bin/mockgen -source=internal/domain/resolver.go -destination=internal/mocks/resolver.go -package=mocks
+ $Q bin/mockgen -source=internal/interface.go -destination=internal/handlers/mock/handler_mock.go -package=mock
+ $Q bin/mockgen -source=internal/source/source.go -destination=internal/source/mock/source_mock.go -package=mock
+ $Q bin/mockgen -source=internal/source/gitlab/mock/client_stub.go -destination=internal/source/gitlab/mock/client_mock.go -package=mock
+ $Q bin/mockgen -source=internal/domain/resolver.go -destination=internal/domain/mock/resolver_mock.go -package=mock
build: .GOPATH/.ok
$Q GOBIN=$(BINDIR) go install $(if $V,-v) -ldflags="$(VERSION_FLAGS)" -tags "${GO_BUILD_TAGS}" -buildmode exe $(IMPORT_PATH)
diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go
index d55c5a46..47e424c1 100644
--- a/internal/auth/auth_test.go
+++ b/internal/auth/auth_test.go
@@ -15,8 +15,8 @@ import (
"github.com/gorilla/sessions"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitlab-pages/internal/mocks"
"gitlab.com/gitlab-org/gitlab-pages/internal/request"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/source/mock"
)
func createTestAuth(t *testing.T, internalServer string, publicServer string) *Auth {
@@ -86,7 +86,7 @@ func TestTryAuthenticate(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockSource := mocks.NewMockSource(mockCtrl)
+ mockSource := mock.NewMockSource(mockCtrl)
require.False(t, auth.TryAuthenticate(result, r, mockSource))
}
@@ -102,7 +102,7 @@ func TestTryAuthenticateWithError(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockSource := mocks.NewMockSource(mockCtrl)
+ mockSource := mock.NewMockSource(mockCtrl)
require.True(t, auth.TryAuthenticate(result, r, mockSource))
require.Equal(t, http.StatusUnauthorized, result.Code)
}
@@ -124,7 +124,7 @@ func TestTryAuthenticateWithCodeButInvalidState(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockSource := mocks.NewMockSource(mockCtrl)
+ mockSource := mock.NewMockSource(mockCtrl)
require.True(t, auth.TryAuthenticate(result, r, mockSource))
require.Equal(t, http.StatusUnauthorized, result.Code)
}
@@ -149,7 +149,7 @@ func TestTryAuthenticateRemoveTokenFromRedirect(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockSource := mocks.NewMockSource(mockCtrl)
+ mockSource := mock.NewMockSource(mockCtrl)
require.True(t, auth.TryAuthenticate(result, r, mockSource))
require.Equal(t, http.StatusFound, result.Code)
@@ -168,7 +168,7 @@ func TestTryAuthenticateWithDomainAndState(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockSource := mocks.NewMockSource(mockCtrl)
+ mockSource := mock.NewMockSource(mockCtrl)
require.True(t, auth.TryAuthenticate(result, r, mockSource))
require.Equal(t, http.StatusFound, result.Code)
redirect, err := url.Parse(result.Header().Get("Location"))
@@ -228,7 +228,7 @@ func testTryAuthenticateWithCodeAndState(t *testing.T, https bool) {
mockCtrl := gomock.NewController(t)
- mockSource := mocks.NewMockSource(mockCtrl)
+ mockSource := mock.NewMockSource(mockCtrl)
require.True(t, auth.TryAuthenticate(result, r, mockSource))
res := result.Result()
@@ -518,7 +518,7 @@ func TestCheckResponseForInvalidTokenWhenNotInvalidToken(t *testing.T) {
func TestDomainAllowed(t *testing.T) {
auth := createTestAuth(t, "", "")
mockCtrl := gomock.NewController(t)
- mockSource := mocks.NewMockSource(mockCtrl)
+ mockSource := mock.NewMockSource(mockCtrl)
testCases := []struct {
name string
diff --git a/internal/domain/domain_test.go b/internal/domain/domain_test.go
index 408ddf38..3496a6da 100644
--- a/internal/domain/domain_test.go
+++ b/internal/domain/domain_test.go
@@ -9,8 +9,8 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-pages/internal/domain"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/domain/mock"
"gitlab.com/gitlab-org/gitlab-pages/internal/fixture"
- "gitlab.com/gitlab-org/gitlab-pages/internal/mocks"
"gitlab.com/gitlab-org/gitlab-pages/internal/serving"
"gitlab.com/gitlab-org/gitlab-pages/internal/serving/disk/local"
"gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers"
@@ -208,7 +208,7 @@ func TestServeNamespaceNotFound(t *testing.T) {
func mockResolver(t *testing.T, project *serving.LookupPath, subpath string, err error) domain.Resolver {
mockCtrl := gomock.NewController(t)
- mockResolver := mocks.NewMockResolver(mockCtrl)
+ mockResolver := mock.NewMockResolver(mockCtrl)
mockResolver.EXPECT().
Resolve(gomock.Any()).
diff --git a/internal/mocks/resolver.go b/internal/domain/mock/resolver_mock.go
index 14b86a9c..8231b2b4 100644
--- a/internal/mocks/resolver.go
+++ b/internal/domain/mock/resolver_mock.go
@@ -1,8 +1,8 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: internal/domain/resolver.go
-// Package mocks is a generated GoMock package.
-package mocks
+// Package mock is a generated GoMock package.
+package mock
import (
http "net/http"
diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go
index dd940251..22027ad0 100644
--- a/internal/handlers/handlers_test.go
+++ b/internal/handlers/handlers_test.go
@@ -10,19 +10,19 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitlab-pages/internal/mocks"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/handlers/mock"
)
func TestNotHandleArtifactRequestReturnsFalse(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockArtifact := mocks.NewMockArtifact(mockCtrl)
+ mockArtifact := mock.NewMockArtifact(mockCtrl)
mockArtifact.EXPECT().
TryMakeRequest(gomock.Any(), gomock.Any(), gomock.Any(), "", gomock.Any()).
Return(false).
Times(1)
- mockAuth := mocks.NewMockAuth(mockCtrl)
+ mockAuth := mock.NewMockAuth(mockCtrl)
mockAuth.EXPECT().
GetTokenIfExists(gomock.Any(), gomock.Any()).
Return("", nil).
@@ -41,13 +41,13 @@ func TestNotHandleArtifactRequestReturnsFalse(t *testing.T) {
func TestHandleArtifactRequestedReturnsTrue(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockArtifact := mocks.NewMockArtifact(mockCtrl)
+ mockArtifact := mock.NewMockArtifact(mockCtrl)
mockArtifact.EXPECT().
TryMakeRequest(gomock.Any(), gomock.Any(), gomock.Any(), "", gomock.Any()).
Return(true).
Times(1)
- mockAuth := mocks.NewMockAuth(mockCtrl)
+ mockAuth := mock.NewMockAuth(mockCtrl)
mockAuth.EXPECT().
GetTokenIfExists(gomock.Any(), gomock.Any()).
Return("", nil).
@@ -64,7 +64,7 @@ func TestHandleArtifactRequestedReturnsTrue(t *testing.T) {
func TestNotFoundWithTokenIsNotHandled(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockAuth := mocks.NewMockAuth(mockCtrl)
+ mockAuth := mock.NewMockAuth(mockCtrl)
mockAuth.EXPECT().CheckResponseForInvalidToken(gomock.Any(), gomock.Any(), gomock.Any()).
Return(false)
@@ -101,7 +101,7 @@ func TestForbiddenWithTokenIsNotHandled(t *testing.T) {
t.Run(tn, func(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockAuth := mocks.NewMockAuth(mockCtrl)
+ mockAuth := mock.NewMockAuth(mockCtrl)
if tc.Token == "" {
mockAuth.EXPECT().IsAuthSupported().Return(true)
mockAuth.EXPECT().RequireAuth(gomock.Any(), gomock.Any()).Return(true)
@@ -125,7 +125,7 @@ func TestForbiddenWithTokenIsNotHandled(t *testing.T) {
func TestNotFoundWithoutTokenIsNotHandledWhenNotAuthSupport(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockAuth := mocks.NewMockAuth(mockCtrl)
+ mockAuth := mock.NewMockAuth(mockCtrl)
mockAuth.EXPECT().IsAuthSupported().Return(false)
handlers := New(mockAuth, nil)
@@ -140,7 +140,7 @@ func TestNotFoundWithoutTokenIsNotHandledWhenNotAuthSupport(t *testing.T) {
func TestNotFoundWithoutTokenIsHandled(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockAuth := mocks.NewMockAuth(mockCtrl)
+ mockAuth := mock.NewMockAuth(mockCtrl)
mockAuth.EXPECT().IsAuthSupported().Return(true)
mockAuth.EXPECT().RequireAuth(gomock.Any(), gomock.Any()).Times(1).Return(true)
@@ -156,7 +156,7 @@ func TestNotFoundWithoutTokenIsHandled(t *testing.T) {
func TestInvalidTokenResponseIsHandled(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockAuth := mocks.NewMockAuth(mockCtrl)
+ mockAuth := mock.NewMockAuth(mockCtrl)
mockAuth.EXPECT().CheckResponseForInvalidToken(gomock.Any(), gomock.Any(), gomock.Any()).
Return(true)
@@ -173,12 +173,12 @@ func TestInvalidTokenResponseIsHandled(t *testing.T) {
func TestHandleArtifactRequestButGetTokenFails(t *testing.T) {
mockCtrl := gomock.NewController(t)
- mockArtifact := mocks.NewMockArtifact(mockCtrl)
+ mockArtifact := mock.NewMockArtifact(mockCtrl)
mockArtifact.EXPECT().
TryMakeRequest(gomock.Any(), gomock.Any(), gomock.Any(), "", gomock.Any()).
Times(0)
- mockAuth := mocks.NewMockAuth(mockCtrl)
+ mockAuth := mock.NewMockAuth(mockCtrl)
mockAuth.EXPECT().GetTokenIfExists(gomock.Any(), gomock.Any()).Return("", errors.New("error when retrieving token"))
handlers := New(mockAuth, mockArtifact)
diff --git a/internal/mocks/mocks.go b/internal/handlers/mock/handler_mock.go
index b18bede4..11548221 100644
--- a/internal/mocks/mocks.go
+++ b/internal/handlers/mock/handler_mock.go
@@ -1,8 +1,8 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: internal/interface.go
-// Package mocks is a generated GoMock package.
-package mocks
+// Package mock is a generated GoMock package.
+package mock
import (
http "net/http"
diff --git a/internal/source/gitlab/gitlab_test.go b/internal/source/gitlab/gitlab_test.go
index d7fbf454..e7f80387 100644
--- a/internal/source/gitlab/gitlab_test.go
+++ b/internal/source/gitlab/gitlab_test.go
@@ -12,9 +12,9 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitlab-pages/internal/mocks"
"gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/api"
"gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/client"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/mock"
)
func TestGetDomain(t *testing.T) {
@@ -171,10 +171,10 @@ func TestResolveLookupPathsOrderDoesNotMatter(t *testing.T) {
}
}
-func NewMockClient(t *testing.T, file string, mockedLookup *api.Lookup) *mocks.MockClientStub {
+func NewMockClient(t *testing.T, file string, mockedLookup *api.Lookup) *mock.MockClientStub {
mockCtrl := gomock.NewController(t)
- mockClient := mocks.NewMockClientStub(mockCtrl)
+ mockClient := mock.NewMockClientStub(mockCtrl)
mockClient.EXPECT().
Resolve(gomock.Any(), gomock.Any()).
DoAndReturn(func(ctx context.Context, domain string) *api.Lookup {
diff --git a/internal/mocks/client.go b/internal/source/gitlab/mock/client_mock.go
index 22b0757e..6f78b01b 100644
--- a/internal/mocks/client.go
+++ b/internal/source/gitlab/mock/client_mock.go
@@ -1,8 +1,8 @@
// Code generated by MockGen. DO NOT EDIT.
-// Source: internal/mocks/api/client_stub.go
+// Source: internal/source/gitlab/mock/client_stub.go
-// Package mocks is a generated GoMock package.
-package mocks
+// Package mock is a generated GoMock package.
+package mock
import (
context "context"
diff --git a/internal/mocks/api/client_stub.go b/internal/source/gitlab/mock/client_stub.go
index f1a20754..5b201da2 100644
--- a/internal/mocks/api/client_stub.go
+++ b/internal/source/gitlab/mock/client_stub.go
@@ -1,4 +1,4 @@
-package mocks
+package mock
import "gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab/api"
diff --git a/internal/mocks/source.go b/internal/source/mock/source_mock.go
index 5412310f..6ec884f1 100644
--- a/internal/mocks/source.go
+++ b/internal/source/mock/source_mock.go
@@ -1,8 +1,8 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: internal/source/source.go
-// Package mocks is a generated GoMock package.
-package mocks
+// Package mock is a generated GoMock package.
+package mock
import (
context "context"