mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
cleanup integration test code
This commit is contained in:
@ -18,7 +18,7 @@ func retryWaitTimes() []int {
|
||||
// give it more leeway compared to when we're running things locally.
|
||||
return []int{0, 1, 1, 1, 1, 1, 5, 10, 20, 40, 100, 200, 500, 1000, 2000, 4000}
|
||||
} else {
|
||||
return []int{0, 1, 1, 1, 1, 1, 5, 10, 20, 40, 100}
|
||||
return []int{0, 1, 1, 1, 1, 1, 5, 10, 20, 40, 100, 200}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
package components
|
||||
|
||||
// for running common actions
|
||||
type Actions struct {
|
||||
type Common struct {
|
||||
t *TestDriver
|
||||
}
|
||||
|
||||
func (self *Actions) ContinueMerge() {
|
||||
self.t.Views().current().Press(self.t.keys.Universal.CreateRebaseOptionsMenu)
|
||||
func (self *Common) ContinueMerge() {
|
||||
self.t.GlobalPress(self.t.keys.Universal.CreateRebaseOptionsMenu)
|
||||
|
||||
self.t.ExpectPopup().Menu().
|
||||
Title(Equals("Rebase Options")).
|
||||
@ -14,32 +14,32 @@ func (self *Actions) ContinueMerge() {
|
||||
Confirm()
|
||||
}
|
||||
|
||||
func (self *Actions) ContinueRebase() {
|
||||
func (self *Common) ContinueRebase() {
|
||||
self.ContinueMerge()
|
||||
}
|
||||
|
||||
func (self *Actions) AcknowledgeConflicts() {
|
||||
func (self *Common) AcknowledgeConflicts() {
|
||||
self.t.ExpectPopup().Confirmation().
|
||||
Title(Equals("Auto-merge failed")).
|
||||
Content(Contains("Conflicts!")).
|
||||
Confirm()
|
||||
}
|
||||
|
||||
func (self *Actions) ContinueOnConflictsResolved() {
|
||||
func (self *Common) ContinueOnConflictsResolved() {
|
||||
self.t.ExpectPopup().Confirmation().
|
||||
Title(Equals("continue")).
|
||||
Content(Contains("all merge conflicts resolved. Continue?")).
|
||||
Confirm()
|
||||
}
|
||||
|
||||
func (self *Actions) ConfirmDiscardLines() {
|
||||
func (self *Common) ConfirmDiscardLines() {
|
||||
self.t.ExpectPopup().Confirmation().
|
||||
Title(Equals("Unstage lines")).
|
||||
Content(Contains("Are you sure you want to delete the selected lines")).
|
||||
Confirm()
|
||||
}
|
||||
|
||||
func (self *Actions) SelectPatchOption(matcher *Matcher) {
|
||||
func (self *Common) SelectPatchOption(matcher *Matcher) {
|
||||
self.t.GlobalPress(self.t.keys.Universal.CreatePatchOptionsMenu)
|
||||
|
||||
self.t.ExpectPopup().Menu().Title(Equals("Patch Options")).Select(matcher).Confirm()
|
@ -31,7 +31,7 @@ func (self *MenuDriver) Cancel() {
|
||||
}
|
||||
|
||||
func (self *MenuDriver) Select(option *Matcher) *MenuDriver {
|
||||
self.getViewDriver().NavigateToListItem(option)
|
||||
self.getViewDriver().NavigateToLine(option)
|
||||
|
||||
return self
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ package components
|
||||
import "path/filepath"
|
||||
|
||||
// convenience struct for easily getting directories within our test directory.
|
||||
// We have one test directory for each test, found in test/integration.
|
||||
// We have one test directory for each test, found in test/results.
|
||||
type Paths struct {
|
||||
// e.g. test/integration/test_name
|
||||
// e.g. test/results/test_name
|
||||
root string
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,6 @@ func (self *PromptDriver) ConfirmSuggestion(matcher *Matcher) {
|
||||
self.t.press(self.t.keys.Universal.TogglePanel)
|
||||
self.t.Views().Suggestions().
|
||||
IsFocused().
|
||||
NavigateToListItem(matcher).
|
||||
NavigateToLine(matcher).
|
||||
PressEnter()
|
||||
}
|
||||
|
@ -11,14 +11,16 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
)
|
||||
|
||||
// this is the integration runner for the new and improved integration interface
|
||||
|
||||
const (
|
||||
TEST_NAME_ENV_VAR = "TEST_NAME"
|
||||
SANDBOX_ENV_VAR = "SANDBOX"
|
||||
GIT_CONFIG_GLOBAL_ENV_VAR = "GIT_CONFIG_GLOBAL"
|
||||
)
|
||||
|
||||
// This function lets you run tests either from within `go test` or from a regular binary.
|
||||
// The reason for having two separate ways of testing is that `go test` isn't great at
|
||||
// showing what's actually happening during the test, but it's still good at running
|
||||
// tests in telling you about their results.
|
||||
func RunTests(
|
||||
tests []*IntegrationTest,
|
||||
logf func(format string, formatArgs ...interface{}),
|
||||
@ -34,7 +36,7 @@ func RunTests(
|
||||
return err
|
||||
}
|
||||
|
||||
testDir := filepath.Join(projectRootDir, "test", "integration_new")
|
||||
testDir := filepath.Join(projectRootDir, "test", "results")
|
||||
|
||||
if err := buildLazygit(); err != nil {
|
||||
return err
|
||||
|
@ -38,6 +38,15 @@ func (self *Shell) RunCommand(cmdStr string) *Shell {
|
||||
return self
|
||||
}
|
||||
|
||||
// Help files are located at test/files from the root the lazygit repo.
|
||||
// E.g. You may want to create a pre-commit hook file there, then call this
|
||||
// function to copy it into your test repo.
|
||||
func (self *Shell) CopyHelpFile(source string, destination string) *Shell {
|
||||
self.RunCommand(fmt.Sprintf("cp ../../../../../files/%s %s", source, destination))
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Shell) runCommandWithOutput(cmdStr string) (string, error) {
|
||||
args := str.ToArgv(cmdStr)
|
||||
cmd := secureexec.Command(args[0], args[1:]...)
|
||||
@ -190,13 +199,27 @@ func (self *Shell) SetConfig(key string, value string) *Shell {
|
||||
// creates a clone of the repo in a sibling directory and adds the clone
|
||||
// as a remote, then fetches it.
|
||||
func (self *Shell) CloneIntoRemote(name string) *Shell {
|
||||
self.RunCommand(fmt.Sprintf("git clone --bare . ../%s", name))
|
||||
self.Clone(name)
|
||||
self.RunCommand(fmt.Sprintf("git remote add %s ../%s", name, name))
|
||||
self.RunCommand(fmt.Sprintf("git fetch %s", name))
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Shell) CloneIntoSubmodule(submoduleName string) *Shell {
|
||||
self.Clone("other_repo")
|
||||
self.RunCommand(fmt.Sprintf("git submodule add ../other_repo %s", submoduleName))
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
// clones repo into a sibling directory
|
||||
func (self *Shell) Clone(repoName string) *Shell {
|
||||
self.RunCommand(fmt.Sprintf("git clone --bare . ../%s", repoName))
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
// e.g. branch: 'master', upstream: 'origin/master'
|
||||
func (self *Shell) SetBranchUpstream(branch string, upstream string) *Shell {
|
||||
self.RunCommand(fmt.Sprintf("git branch --set-upstream-to=%s %s", upstream, branch))
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
// Test describes an integration tests that will be run against the lazygit gui.
|
||||
// IntegrationTest describes an integration test that will be run against the lazygit gui.
|
||||
|
||||
// our unit tests will use this description to avoid a panic caused by attempting
|
||||
// to get the test's name via it's file's path.
|
||||
|
@ -48,8 +48,8 @@ func (self *TestDriver) typeContent(content string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *TestDriver) Actions() *Actions {
|
||||
return &Actions{t: self}
|
||||
func (self *TestDriver) Common() *Common {
|
||||
return &Common{t: self}
|
||||
}
|
||||
|
||||
// for when you want to allow lazygit to process something before continuing
|
||||
|
@ -11,6 +11,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// this file is for testing our test code (meta, I know)
|
||||
|
||||
type fakeGuiDriver struct {
|
||||
failureMessage string
|
||||
pressedKeys []string
|
||||
|
@ -63,6 +63,7 @@ func (self *ViewDriver) Title(expected *Matcher) *ViewDriver {
|
||||
|
||||
// asserts that the view has lines matching the given matchers. One matcher must be passed for each line.
|
||||
// If you only care about the top n lines, use the TopLines method instead.
|
||||
// If you only care about a subset of lines, use the ContainsLines method instead.
|
||||
func (self *ViewDriver) Lines(matchers ...*Matcher) *ViewDriver {
|
||||
self.validateMatchersPassed(matchers)
|
||||
self.LineCount(len(matchers))
|
||||
@ -81,6 +82,7 @@ func (self *ViewDriver) TopLines(matchers ...*Matcher) *ViewDriver {
|
||||
return self.assertLines(0, matchers...)
|
||||
}
|
||||
|
||||
// asserts that somewhere in the view there are consequetive lines matching the given matchers.
|
||||
func (self *ViewDriver) ContainsLines(matchers ...*Matcher) *ViewDriver {
|
||||
self.validateMatchersPassed(matchers)
|
||||
self.validateEnoughLines(matchers)
|
||||
@ -131,7 +133,7 @@ func (self *ViewDriver) ContainsLines(matchers ...*Matcher) *ViewDriver {
|
||||
return self
|
||||
}
|
||||
|
||||
// asserts on the lines that are selected in the view.
|
||||
// asserts on the lines that are selected in the view. Don't use the `IsSelected` matcher with this because it's redundant.
|
||||
func (self *ViewDriver) SelectedLines(matchers ...*Matcher) *ViewDriver {
|
||||
self.validateMatchersPassed(matchers)
|
||||
self.validateEnoughLines(matchers)
|
||||
@ -373,7 +375,7 @@ func (self *ViewDriver) PressEscape() *ViewDriver {
|
||||
// If this changes in future, we'll need to update this code to first attempt to find the item
|
||||
// in the current page and failing that, jump to the top of the view and iterate through all of it,
|
||||
// looking for the item.
|
||||
func (self *ViewDriver) NavigateToListItem(matcher *Matcher) *ViewDriver {
|
||||
func (self *ViewDriver) NavigateToLine(matcher *Matcher) *ViewDriver {
|
||||
self.IsFocused()
|
||||
|
||||
view := self.getView()
|
||||
|
@ -13,16 +13,6 @@ type Views struct {
|
||||
t *TestDriver
|
||||
}
|
||||
|
||||
// not exporting this because I want the test to always be explicit about what
|
||||
// view it's dealing with.
|
||||
func (self *Views) current() *ViewDriver {
|
||||
return &ViewDriver{
|
||||
context: "current view",
|
||||
getView: func() *gocui.View { return self.t.gui.CurrentContext().GetView() },
|
||||
t: self.t,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Views) Main() *ViewDriver {
|
||||
return &ViewDriver{
|
||||
context: "main view",
|
||||
|
Reference in New Issue
Block a user