Skip to content

Commit a6a6877

Browse files
committed
Move NewDummyCommon to pkg/common
It's too special for a utils package, and it als makes sense to put it right next to the thing that it is a dummy for.
1 parent 223978e commit a6a6877

File tree

12 files changed

+58
-52
lines changed

12 files changed

+58
-52
lines changed

pkg/commands/git_commands/commit_loader_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/go-errors/errors"
99
"github.com/jesseduffield/lazygit/pkg/commands/models"
1010
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
11+
"github.com/jesseduffield/lazygit/pkg/common"
1112
"github.com/jesseduffield/lazygit/pkg/config"
1213
"github.com/jesseduffield/lazygit/pkg/utils"
1314
"github.com/samber/lo"
@@ -296,7 +297,7 @@ func TestGetCommits(t *testing.T) {
296297

297298
for _, scenario := range scenarios {
298299
t.Run(scenario.testName, func(t *testing.T) {
299-
common := utils.NewDummyCommon()
300+
common := common.NewDummyCommon()
300301
common.AppState = &config.AppState{}
301302
common.AppState.GitLogOrder = scenario.logOrder
302303
cmd := oscommands.NewDummyCmdObjBuilder(scenario.runner)
@@ -516,7 +517,7 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
516517
}
517518
for _, scenario := range scenarios {
518519
t.Run(scenario.testName, func(t *testing.T) {
519-
common := utils.NewDummyCommon()
520+
common := common.NewDummyCommon()
520521

521522
builder := &CommitLoader{
522523
Common: common,

pkg/commands/git_commands/deps_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
1010
"github.com/jesseduffield/lazygit/pkg/common"
1111
"github.com/jesseduffield/lazygit/pkg/config"
12-
"github.com/jesseduffield/lazygit/pkg/utils"
1312
"github.com/spf13/afero"
1413
)
1514

@@ -32,7 +31,7 @@ func buildGitCommon(deps commonDeps) *GitCommon {
3231

3332
gitCommon.Common = deps.common
3433
if gitCommon.Common == nil {
35-
gitCommon.Common = utils.NewDummyCommonWithUserConfigAndAppState(deps.userConfig, deps.appState)
34+
gitCommon.Common = common.NewDummyCommonWithUserConfigAndAppState(deps.userConfig, deps.appState)
3635
}
3736

3837
if deps.fs != nil {

pkg/commands/git_commands/reflog_commit_loader_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/jesseduffield/lazygit/pkg/commands/models"
99
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
10+
"github.com/jesseduffield/lazygit/pkg/common"
1011
"github.com/jesseduffield/lazygit/pkg/utils"
1112
"github.com/samber/lo"
1213
"github.com/sanity-io/litter"
@@ -181,7 +182,7 @@ func TestGetReflogCommits(t *testing.T) {
181182
for _, scenario := range scenarios {
182183
t.Run(scenario.testName, func(t *testing.T) {
183184
builder := &ReflogCommitLoader{
184-
Common: utils.NewDummyCommon(),
185+
Common: common.NewDummyCommon(),
185186
cmd: oscommands.NewDummyCmdObjBuilder(scenario.runner),
186187
}
187188

pkg/commands/git_commands/stash_loader_test.go

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

66
"github.com/jesseduffield/lazygit/pkg/commands/models"
77
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
8-
"github.com/jesseduffield/lazygit/pkg/utils"
8+
"github.com/jesseduffield/lazygit/pkg/common"
99
"github.com/stretchr/testify/assert"
1010
)
1111

@@ -50,7 +50,7 @@ func TestGetStashEntries(t *testing.T) {
5050
t.Run(s.testName, func(t *testing.T) {
5151
cmd := oscommands.NewDummyCmdObjBuilder(s.runner)
5252

53-
loader := NewStashLoader(utils.NewDummyCommon(), cmd)
53+
loader := NewStashLoader(common.NewDummyCommon(), cmd)
5454

5555
assert.EqualValues(t, s.expectedStashEntries, loader.GetStashEntries(s.filterPath))
5656
})

pkg/commands/git_commands/tag_loader_test.go

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

66
"github.com/jesseduffield/lazygit/pkg/commands/models"
77
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
8-
"github.com/jesseduffield/lazygit/pkg/utils"
8+
"github.com/jesseduffield/lazygit/pkg/common"
99
"github.com/stretchr/testify/assert"
1010
)
1111

@@ -46,7 +46,7 @@ func TestGetTags(t *testing.T) {
4646
for _, scenario := range scenarios {
4747
t.Run(scenario.testName, func(t *testing.T) {
4848
loader := &TagLoader{
49-
Common: utils.NewDummyCommon(),
49+
Common: common.NewDummyCommon(),
5050
cmd: oscommands.NewDummyCmdObjBuilder(scenario.runner),
5151
}
5252

pkg/commands/oscommands/dummies.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
// NewDummyOSCommand creates a new dummy OSCommand for testing
1010
func NewDummyOSCommand() *OSCommand {
11-
osCmd := NewOSCommand(utils.NewDummyCommon(), config.NewDummyAppConfig(), dummyPlatform, NewNullGuiIO(utils.NewDummyLog()))
11+
osCmd := NewOSCommand(common.NewDummyCommon(), config.NewDummyAppConfig(), dummyPlatform, NewNullGuiIO(utils.NewDummyLog()))
1212

1313
return osCmd
1414
}
@@ -23,9 +23,9 @@ type OSCommandDeps struct {
2323
}
2424

2525
func NewDummyOSCommandWithDeps(deps OSCommandDeps) *OSCommand {
26-
common := deps.Common
27-
if common == nil {
28-
common = utils.NewDummyCommon()
26+
cmn := deps.Common
27+
if cmn == nil {
28+
cmn = common.NewDummyCommon()
2929
}
3030

3131
platform := deps.Platform
@@ -34,7 +34,7 @@ func NewDummyOSCommandWithDeps(deps OSCommandDeps) *OSCommand {
3434
}
3535

3636
return &OSCommand{
37-
Common: common,
37+
Common: cmn,
3838
Platform: platform,
3939
getenvFn: deps.GetenvFn,
4040
removeFileFn: deps.RemoveFileFn,
@@ -59,7 +59,7 @@ var dummyPlatform = &Platform{
5959
}
6060

6161
func NewDummyOSCommandWithRunner(runner *FakeCmdObjRunner) *OSCommand {
62-
osCommand := NewOSCommand(utils.NewDummyCommon(), config.NewDummyAppConfig(), dummyPlatform, NewNullGuiIO(utils.NewDummyLog()))
62+
osCommand := NewOSCommand(common.NewDummyCommon(), config.NewDummyAppConfig(), dummyPlatform, NewNullGuiIO(utils.NewDummyLog()))
6363
osCommand.Cmd = NewDummyCmdObjBuilder(runner)
6464

6565
return osCommand

pkg/common/dummies.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package common
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
"github.com/jesseduffield/lazygit/pkg/i18n"
6+
"github.com/jesseduffield/lazygit/pkg/utils"
7+
"github.com/spf13/afero"
8+
)
9+
10+
func NewDummyCommon() *Common {
11+
tr := i18n.EnglishTranslationSet()
12+
cmn := &Common{
13+
Log: utils.NewDummyLog(),
14+
Tr: tr,
15+
Fs: afero.NewOsFs(),
16+
}
17+
cmn.SetUserConfig(config.GetDefaultConfig())
18+
return cmn
19+
}
20+
21+
func NewDummyCommonWithUserConfigAndAppState(userConfig *config.UserConfig, appState *config.AppState) *Common {
22+
tr := i18n.EnglishTranslationSet()
23+
cmn := &Common{
24+
Log: utils.NewDummyLog(),
25+
Tr: tr,
26+
AppState: appState,
27+
// TODO: remove dependency on actual filesystem in tests and switch to using
28+
// in-memory for everything
29+
Fs: afero.NewOsFs(),
30+
}
31+
cmn.SetUserConfig(userConfig)
32+
return cmn
33+
}

pkg/gui/dummies.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ package gui
33
import (
44
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
55
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
6+
"github.com/jesseduffield/lazygit/pkg/common"
67
"github.com/jesseduffield/lazygit/pkg/config"
78
"github.com/jesseduffield/lazygit/pkg/updates"
8-
"github.com/jesseduffield/lazygit/pkg/utils"
99
)
1010

1111
func NewDummyUpdater() *updates.Updater {
1212
newAppConfig := config.NewDummyAppConfig()
13-
dummyUpdater, _ := updates.NewUpdater(utils.NewDummyCommon(), newAppConfig, oscommands.NewDummyOSCommand())
13+
dummyUpdater, _ := updates.NewUpdater(common.NewDummyCommon(), newAppConfig, oscommands.NewDummyOSCommand())
1414
return dummyUpdater
1515
}
1616

1717
// NewDummyGui creates a new dummy GUI for testing
1818
func NewDummyGui() *Gui {
1919
newAppConfig := config.NewDummyAppConfig()
20-
dummyGui, _ := NewGui(utils.NewDummyCommon(), newAppConfig, &git_commands.GitVersion{Major: 2, Minor: 0, Patch: 0}, NewDummyUpdater(), false, "", nil)
20+
dummyGui, _ := NewGui(common.NewDummyCommon(), newAppConfig, &git_commands.GitVersion{Major: 2, Minor: 0, Patch: 0}, NewDummyUpdater(), false, "", nil)
2121
return dummyGui
2222
}

pkg/gui/presentation/branches_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88

99
"github.com/gookit/color"
1010
"github.com/jesseduffield/lazygit/pkg/commands/models"
11+
"github.com/jesseduffield/lazygit/pkg/common"
1112
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
1213
"github.com/jesseduffield/lazygit/pkg/gui/types"
13-
"github.com/jesseduffield/lazygit/pkg/utils"
1414
"github.com/samber/lo"
1515
"github.com/stretchr/testify/assert"
1616
"github.com/xo/terminfo"
@@ -320,7 +320,7 @@ func Test_getBranchDisplayStrings(t *testing.T) {
320320
oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelNone)
321321
defer color.ForceSetColorLevel(oldColorLevel)
322322

323-
c := utils.NewDummyCommon()
323+
c := common.NewDummyCommon()
324324
SetCustomBranches(c.UserConfig().Gui.BranchColorPatterns, true)
325325

326326
for i, s := range scenarios {

pkg/gui/presentation/commits_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/jesseduffield/generics/set"
1111
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
1212
"github.com/jesseduffield/lazygit/pkg/commands/models"
13+
"github.com/jesseduffield/lazygit/pkg/common"
1314
"github.com/jesseduffield/lazygit/pkg/utils"
1415
"github.com/samber/lo"
1516
"github.com/stefanhaller/git-todo-parser/todo"
@@ -539,7 +540,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
539540
}
540541
}
541542

542-
common := utils.NewDummyCommon()
543+
common := common.NewDummyCommon()
543544

544545
for _, s := range scenarios {
545546
if !focusing || s.focus {

0 commit comments

Comments
 (0)