Skip to content

Commit 2342280

Browse files
authored
Refactor: mv test internal/testutil; app_test for tests (#46)
1 parent 2e5a9e7 commit 2342280

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

internal/gitlab.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (s *GitLab) FetchProjectPage(ctx context.Context, page int, user *User, idA
6565
}
6666

6767
for _, proj := range projs {
68-
if !s.hasUserContributions(ctx, user, proj.ID) {
68+
if !s.HasUserContributions(ctx, user, proj.ID) {
6969
continue
7070
}
7171

@@ -81,7 +81,7 @@ func (s *GitLab) FetchProjectPage(ctx context.Context, page int, user *User, idA
8181
return projects, resp.NextPage, nil
8282
}
8383

84-
func (s *GitLab) hasUserContributions(ctx context.Context, user *User, projectID int) bool {
84+
func (s *GitLab) HasUserContributions(ctx context.Context, user *User, projectID int) bool {
8585
const perPage = 50
8686

8787
opt := &gitlab.ListContributorsOptions{

internal/gitlab_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app
1+
package app_test
22

33
import (
44
"context"
@@ -9,16 +9,17 @@ import (
99
"github.com/stretchr/testify/require"
1010
"github.com/xanzy/go-gitlab"
1111

12-
"github.com/alexandear/import-gitlab-commits/test"
12+
app "github.com/alexandear/import-gitlab-commits/internal"
13+
"github.com/alexandear/import-gitlab-commits/internal/testutil"
1314
)
1415

15-
func TestService_hasContributionsByUser(t *testing.T) {
16+
func TestGitLabHasUserContributions(t *testing.T) {
1617
git := initGit(t)
17-
s := NewGitLab(test.NewLog(t), git)
18+
s := app.NewGitLab(testutil.NewLog(t), git)
1819
user := newCurrentUser(t, git)
1920

20-
assert.False(t, s.hasUserContributions(context.Background(), user, 3))
21-
assert.True(t, s.hasUserContributions(context.Background(), user, 575))
21+
assert.False(t, s.HasUserContributions(context.Background(), user, 3))
22+
assert.True(t, s.HasUserContributions(context.Background(), user, 575))
2223
}
2324

2425
func initGit(t *testing.T) *gitlab.Client {
@@ -37,13 +38,13 @@ func initGit(t *testing.T) *gitlab.Client {
3738
return git
3839
}
3940

40-
func newCurrentUser(t *testing.T, gitlabClient *gitlab.Client) *User {
41+
func newCurrentUser(t *testing.T, gitlabClient *gitlab.Client) *app.User {
4142
t.Helper()
4243

4344
user, _, err := gitlabClient.Users.CurrentUser()
4445
require.NoError(t, err)
4546

46-
return &User{
47+
return &app.User{
4748
Name: user.Name,
4849
Email: user.Email,
4950
CreatedAt: *user.CreatedAt,

test/log.go renamed to internal/testutil/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package test
1+
package testutil
22

33
import (
44
"log"

main_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55

66
"github.com/stretchr/testify/assert"
77

8-
"github.com/alexandear/import-gitlab-commits/test"
8+
"github.com/alexandear/import-gitlab-commits/internal/testutil"
99
)
1010

1111
func TestExecute(t *testing.T) {
1212
t.Run("error when wrong GITLAB_TOKEN", func(t *testing.T) {
1313
t.Setenv("GITLAB_TOKEN", "")
1414

15-
err := Execute(test.NewLog(t))
15+
err := Execute(testutil.NewLog(t))
1616

1717
assert.ErrorContains(t, err, "GITLAB_TOKEN")
1818
})
@@ -21,7 +21,7 @@ func TestExecute(t *testing.T) {
2121
t.Setenv("GITLAB_TOKEN", "yourgitlabtoken")
2222
t.Setenv("GITLAB_BASE_URL", ":")
2323

24-
err := Execute(test.NewLog(t))
24+
err := Execute(testutil.NewLog(t))
2525

2626
assert.ErrorContains(t, err, "GITLAB_BASE_URL")
2727
})
@@ -31,7 +31,7 @@ func TestExecute(t *testing.T) {
3131
t.Setenv("GITLAB_BASE_URL", "https://gitlab.com")
3232
t.Setenv("COMMITTER_NAME", "")
3333

34-
err := Execute(test.NewLog(t))
34+
err := Execute(testutil.NewLog(t))
3535

3636
assert.ErrorContains(t, err, "COMMITTER_NAME")
3737
})
@@ -42,7 +42,7 @@ func TestExecute(t *testing.T) {
4242
t.Setenv("COMMITTER_NAME", "John Doe")
4343
t.Setenv("COMMITTER_EMAIL", "")
4444

45-
err := Execute(test.NewLog(t))
45+
err := Execute(testutil.NewLog(t))
4646

4747
assert.ErrorContains(t, err, "COMMITTER_EMAIL")
4848
})

0 commit comments

Comments
 (0)