1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-10 04:07:18 +02:00
lazygit/pkg/integration/components/assertion_helper.go

52 lines
1.2 KiB
Go
Raw Normal View History

2022-12-27 06:22:31 +02:00
package components
import (
"os"
2022-12-27 06:22:31 +02:00
"time"
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
)
type assertionHelper struct {
gui integrationTypes.GuiDriver
}
// milliseconds we'll wait when an assertion fails.
func retryWaitTimes() []int {
return []int{0}
if os.Getenv("LONG_WAIT_BEFORE_FAIL") == "true" {
// CI has limited hardware, may be throttled, runs tests in parallel, etc, so we
// 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 {
2023-02-26 02:49:15 +02:00
return []int{0, 1, 1, 1, 1, 1, 5, 10, 20, 40, 100, 200}
}
}
2022-12-27 06:22:31 +02:00
func (self *assertionHelper) matchString(matcher *TextMatcher, context string, getValue func() string) {
2022-12-27 06:22:31 +02:00
self.assertWithRetries(func() (bool, string) {
value := getValue()
return matcher.context(context).test(value)
})
}
func (self *assertionHelper) assertWithRetries(test func() (bool, string)) {
var message string
for _, waitTime := range retryWaitTimes() {
2022-12-27 06:22:31 +02:00
time.Sleep(time.Duration(waitTime) * time.Millisecond)
var ok bool
ok, message = test()
if ok {
return
}
}
self.fail(message)
}
func (self *assertionHelper) fail(message string) {
self.gui.Fail(message)
}