Add a test showing that lazygit doesn't start if state.yml is broken

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Stefan HallerandClaude Opus 5.5 committed 2026-11-15 08:10:58 +01:00
1 parent 61ef3c770f
commit 2d270f0e54
1 file changed
+38
+38
View File
@@ -0,0 +1,38 @@
package config
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
// useTempConfigDir points the config and state folder at a new temp dir and
// returns it.
func useTempConfigDir(t *testing.T) string {
t.Helper()
configDir := t.TempDir()
t.Setenv("CONFIG_DIR", configDir)
t.Setenv("LG_CONFIG_FILE", "")
return configDir
}
func newAppConfig(t *testing.T) (*AppConfig, error) {
t.Helper()
return NewAppConfig("lazygit", "unversioned", "", "", "", false, t.TempDir())
}
func TestStartupWithBrokenAppStateFile(t *testing.T) {
configDir := useTempConfigDir(t)
err := os.WriteFile(filepath.Join(configDir, stateFileName), make([]byte, 4096), 0o644)
assert.NoError(t, err)
_, err = newAppConfig(t)
/* EXPECTED:
assert.NoError(t, err)
ACTUAL: */
assert.ErrorContains(t, err, "control characters are not allowed")
}