+18
-3
@@ -3,8 +3,10 @@ package root
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/versenilvis/iris/internal/config"
|
||||
)
|
||||
|
||||
func TestConfigCommands(t *testing.T) {
|
||||
@@ -14,14 +16,27 @@ func TestConfigCommands(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
// UserConfigDir follows HOME on macOS and XDG_CONFIG_HOME on Unix.
|
||||
// Override both so the command cannot read or write the user's real config.
|
||||
t.Setenv("HOME", tmpDir)
|
||||
t.Setenv("XDG_CONFIG_HOME", tmpDir)
|
||||
|
||||
ConfigInitCmd.Run(ConfigInitCmd, []string{})
|
||||
|
||||
configPath := filepath.Join(tmpDir, "iris", "config.toml")
|
||||
if _, err := os.Stat(configPath); err != nil {
|
||||
configPath, err := config.ConfigPath()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get config path: %v", err)
|
||||
}
|
||||
if _, statErr := os.Stat(configPath); statErr != nil {
|
||||
t.Errorf("expected config file to be created at %s, but it was not", configPath)
|
||||
}
|
||||
content, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to read config file: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(content), "shell-login = false") {
|
||||
t.Error("expected initialized config to include shell-login = false")
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
ConfigShowCmd.SetOut(buf)
|
||||
|
||||
Reference in New Issue
Block a user