From 2aa53614d2970fba5674d439a0fec0e531fd6d93 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 16 Oct 2025 10:11:52 -0300 Subject: [PATCH] test: add tests for the dirs cmd (#1243) Signed-off-by: Carlos Alexandro Becker --- internal/cmd/dirs_test.go | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 internal/cmd/dirs_test.go diff --git a/internal/cmd/dirs_test.go b/internal/cmd/dirs_test.go new file mode 100644 index 0000000000000000000000000000000000000000..2d68f45481a61b4ee9cf9ddc31b8d86d8a69a51f --- /dev/null +++ b/internal/cmd/dirs_test.go @@ -0,0 +1,46 @@ +package cmd + +import ( + "bytes" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" +) + +func init() { + os.Setenv("XDG_CONFIG_HOME", "/tmp/fakeconfig") + os.Setenv("XDG_DATA_HOME", "/tmp/fakedata") +} + +func TestDirs(t *testing.T) { + var b bytes.Buffer + dirsCmd.SetOut(&b) + dirsCmd.SetErr(&b) + dirsCmd.SetIn(bytes.NewReader(nil)) + dirsCmd.Run(dirsCmd, nil) + expected := filepath.FromSlash("/tmp/fakeconfig/crush") + "\n" + + filepath.FromSlash("/tmp/fakedata/crush") + "\n" + require.Equal(t, expected, b.String()) +} + +func TestConfigDir(t *testing.T) { + var b bytes.Buffer + configDirCmd.SetOut(&b) + configDirCmd.SetErr(&b) + configDirCmd.SetIn(bytes.NewReader(nil)) + configDirCmd.Run(configDirCmd, nil) + expected := filepath.FromSlash("/tmp/fakeconfig/crush") + "\n" + require.Equal(t, expected, b.String()) +} + +func TestDataDir(t *testing.T) { + var b bytes.Buffer + dataDirCmd.SetOut(&b) + dataDirCmd.SetErr(&b) + dataDirCmd.SetIn(bytes.NewReader(nil)) + dataDirCmd.Run(dataDirCmd, nil) + expected := filepath.FromSlash("/tmp/fakedata/crush") + "\n" + require.Equal(t, expected, b.String()) +}