diff --git a/.golangci.yml b/.golangci.yml index 493e930..ec4a45a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -29,6 +29,8 @@ linters: ignore-string-values: - "get" - "list" + lll: + line-length: 180 exclusions: # Typical presets to exclude: https://golangci-lint.run/docs/linters/false-positives/#exclusion-presets diff --git a/pkg/cfg/config_test.go b/pkg/cfg/config_test.go index f017152..81563c7 100644 --- a/pkg/cfg/config_test.go +++ b/pkg/cfg/config_test.go @@ -86,24 +86,29 @@ func (c *gitconfigValid) Get(key string) string { } func testConfigEmpty(t *testing.T) { + t.Helper() Init(&gitconfigEmpty{}) } func testConfigOnlyInGitconfig(t *testing.T) { + t.Helper() Init(&gitconfigValid{}) } func testConfigOnlyInEnvVar(t *testing.T) { + t.Helper() Init(&gitconfigEmpty{}) t.Setenv(envVarName, fromEnv) } func testConfigInGitconfigAndEnvVar(t *testing.T) { + t.Helper() Init(&gitconfigValid{}) t.Setenv(envVarName, fromEnv) } func testConfigInFlag(t *testing.T) { + t.Helper() Init(&gitconfigValid{}) t.Setenv(envVarName, fromEnv) diff --git a/pkg/git/config_test.go b/pkg/git/config_test.go index e700395..1af7f14 100644 --- a/pkg/git/config_test.go +++ b/pkg/git/config_test.go @@ -65,12 +65,16 @@ func TestGitConfig(t *testing.T) { } func makeConfigEmpty(t *testing.T) *cfgStub { + t.Helper() + return &cfgStub{ Repo: test.RepoWithEmptyConfig(t), } } func makeConfigValid(t *testing.T) *cfgStub { + t.Helper() + return &cfgStub{ Repo: test.RepoWithValidConfig(t), } diff --git a/pkg/git/finder_test.go b/pkg/git/finder_test.go index e5d1b14..b35a65d 100644 --- a/pkg/git/finder_test.go +++ b/pkg/git/finder_test.go @@ -72,6 +72,7 @@ func TestExists(t *testing.T) { } func makeSingleRepo(t *testing.T) string { + t.Helper() root := test.TempDir(t, "") test.RepoEmptyInDir(t, root) @@ -80,6 +81,7 @@ func makeSingleRepo(t *testing.T) string { } func makeNestedRepo(t *testing.T) string { + t.Helper() // a repo with single nested repo should still be counted as one beacause finder doesn't traverse inside nested repos root := test.TempDir(t, "") @@ -90,6 +92,7 @@ func makeNestedRepo(t *testing.T) string { } func makeMultipleNestedRepos(t *testing.T) string { + t.Helper() root := test.TempDir(t, "") // create two repos inside root - should be counted as 2 diff --git a/pkg/git/repo_test.go b/pkg/git/repo_test.go index baf2d31..f377f14 100644 --- a/pkg/git/repo_test.go +++ b/pkg/git/repo_test.go @@ -411,6 +411,7 @@ func TestRemote(t *testing.T) { } func createTestDirTree(t *testing.T) string { + t.Helper() root := test.TempDir(t, "") err := os.MkdirAll(filepath.Join(root, "a", "b", "c"), os.ModePerm) err = os.MkdirAll(filepath.Join(root, "a", "x", "y"), os.ModePerm) diff --git a/pkg/git/test/helpers.go b/pkg/git/test/helpers.go index 12cd8b2..1be8afa 100644 --- a/pkg/git/test/helpers.go +++ b/pkg/git/test/helpers.go @@ -14,6 +14,8 @@ import ( // TempDir creates a temporary directory inside the parent dir. // If parent is empty, it will use a system default temp dir (usually /tmp). func TempDir(t *testing.T, parent string) string { + t.Helper() + dir, err := ioutil.TempDir(parent, "git-get-repo-") checkFatal(t, err) @@ -87,6 +89,8 @@ func (r *Repo) fetch() { } func checkFatal(t *testing.T, err error) { + t.Helper() + if err != nil { t.Fatalf("failed making test repo: %+v", err) } @@ -94,6 +98,7 @@ func checkFatal(t *testing.T, err error) { // removeTestDir removes a test directory. func removeTestDir(t *testing.T, dir string) { + t.Helper() // Skip cleanup on Windows to avoid file locking issues in CI // The CI runner environment is destroyed after tests anyway if runtime.GOOS == "windows" { diff --git a/pkg/git/test/testrepos.go b/pkg/git/test/testrepos.go index f4aae50..c25434c 100644 --- a/pkg/git/test/testrepos.go +++ b/pkg/git/test/testrepos.go @@ -19,11 +19,13 @@ func (r *Repo) Path() string { // RepoEmpty creates an empty git repo. func RepoEmpty(t *testing.T) *Repo { + t.Helper() return RepoEmptyInDir(t, "") } // RepoEmptyInDir creates an empty git repo inside a given parent dir. func RepoEmptyInDir(t *testing.T, parent string) *Repo { + t.Helper() r := &Repo{ path: TempDir(t, parent), t: t, @@ -36,6 +38,7 @@ func RepoEmptyInDir(t *testing.T, parent string) *Repo { // RepoWithUntracked creates a git repo with a single untracked file. func RepoWithUntracked(t *testing.T) *Repo { + t.Helper() r := RepoEmpty(t) r.writeFile("README.md", "I'm a readme file") @@ -44,6 +47,7 @@ func RepoWithUntracked(t *testing.T) *Repo { // RepoWithStaged creates a git repo with a single staged file. func RepoWithStaged(t *testing.T) *Repo { + t.Helper() r := RepoEmpty(t) r.writeFile("README.md", "I'm a readme file") r.stageFile("README.md") @@ -53,6 +57,7 @@ func RepoWithStaged(t *testing.T) *Repo { // RepoWithCommit creates a git repo with a single commit. func RepoWithCommit(t *testing.T) *Repo { + t.Helper() r := RepoEmpty(t) r.writeFile("README.md", "I'm a readme file") r.stageFile("README.md") @@ -63,6 +68,7 @@ func RepoWithCommit(t *testing.T) *Repo { // RepoWithUncommittedAndUntracked creates a git repo with one staged but uncommitted file and one untracked file. func RepoWithUncommittedAndUntracked(t *testing.T) *Repo { + t.Helper() r := RepoEmpty(t) r.writeFile("README.md", "I'm a readme file") r.stageFile("README.md") @@ -75,6 +81,7 @@ func RepoWithUncommittedAndUntracked(t *testing.T) *Repo { // RepoWithBranch creates a git repo with a new branch. func RepoWithBranch(t *testing.T) *Repo { + t.Helper() r := RepoWithCommit(t) r.branch("feature/branch") r.checkout("feature/branch") @@ -84,6 +91,7 @@ func RepoWithBranch(t *testing.T) *Repo { // RepoWithTag creates a git repo with a new tag. func RepoWithTag(t *testing.T) *Repo { + t.Helper() r := RepoWithCommit(t) r.tag("v0.0.1") r.checkout("v0.0.1") @@ -93,6 +101,7 @@ func RepoWithTag(t *testing.T) *Repo { // RepoWithBranchWithUpstream creates a git repo by cloning another repo and checking out a remote branch. func RepoWithBranchWithUpstream(t *testing.T) *Repo { + t.Helper() origin := RepoWithCommit(t) origin.branch("feature/branch") @@ -104,6 +113,7 @@ func RepoWithBranchWithUpstream(t *testing.T) *Repo { // RepoWithBranchWithoutUpstream creates a git repo by cloning another repo and checking out a new local branch. func RepoWithBranchWithoutUpstream(t *testing.T) *Repo { + t.Helper() origin := RepoWithCommit(t) r := origin.clone() @@ -115,6 +125,7 @@ func RepoWithBranchWithoutUpstream(t *testing.T) *Repo { // RepoWithBranchAhead creates a git repo with a branch being ahead of a remote branch by 1 commit. func RepoWithBranchAhead(t *testing.T) *Repo { + t.Helper() origin := RepoWithCommit(t) origin.branch("feature/branch") @@ -130,6 +141,7 @@ func RepoWithBranchAhead(t *testing.T) *Repo { // RepoWithBranchBehind creates a git repo with a branch being behind a remote branch by 1 commit. func RepoWithBranchBehind(t *testing.T) *Repo { + t.Helper() origin := RepoWithCommit(t) origin.branch("feature/branch") origin.checkout("feature/branch") @@ -148,6 +160,7 @@ func RepoWithBranchBehind(t *testing.T) *Repo { // RepoWithBranchAheadAndBehind creates a git repo with a branch being 2 commits ahead and 1 behind a remote branch. func RepoWithBranchAheadAndBehind(t *testing.T) *Repo { + t.Helper() origin := RepoWithCommit(t) origin.branch("feature/branch") origin.checkout("feature/branch") @@ -174,6 +187,7 @@ func RepoWithBranchAheadAndBehind(t *testing.T) *Repo { // RepoWithEmptyConfig creates a git repo with empty .git/config file. func RepoWithEmptyConfig(t *testing.T) *Repo { + t.Helper() r := RepoEmpty(t) r.writeFile(filepath.Join(".git", "config"), "") @@ -182,6 +196,7 @@ func RepoWithEmptyConfig(t *testing.T) *Repo { // RepoWithValidConfig creates a git repo with valid content in .git/config file. func RepoWithValidConfig(t *testing.T) *Repo { + t.Helper() r := RepoEmpty(t) gitconfig := `