From cc11788404e68fcf7f5356bcc275f331c13fc36e Mon Sep 17 00:00:00 2001 From: ishaan Date: Thu, 16 Jul 2026 13:11:08 +0530 Subject: testify tests for utils, editor, and crud --- internal/editor/editor_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 internal/editor/editor_test.go (limited to 'internal/editor') diff --git a/internal/editor/editor_test.go b/internal/editor/editor_test.go new file mode 100644 index 0000000..86bc095 --- /dev/null +++ b/internal/editor/editor_test.go @@ -0,0 +1,47 @@ +package editor + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestOpenWithEditor_PlainCommand(t *testing.T) { + err := OpenWithEditor("/dev/null", "true") + require.NoError(t, err) +} + +func TestOpenWithEditor_PercentS(t *testing.T) { + dir := t.TempDir() + path := filepath.Join(dir, "testfile") + require.NoError(t, os.WriteFile(path, []byte("content"), 0600)) + + err := OpenWithEditor(path, "true %s") + require.NoError(t, err) +} + +func TestOpenWithEditor_QuotedPercentS(t *testing.T) { + dir := t.TempDir() + path := filepath.Join(dir, "testfile") + require.NoError(t, os.WriteFile(path, []byte("content"), 0600)) + + err := OpenWithEditor(path, "true '%s'") + require.NoError(t, err) +} + +func TestOpenWithEditor_PathWithSpaces(t *testing.T) { + dir := t.TempDir() + path := filepath.Join(dir, "file with spaces") + require.NoError(t, os.WriteFile(path, []byte("content"), 0600)) + + err := OpenWithEditor(path, "true %s") + require.NoError(t, err) +} + +func TestOpenWithEditor_InvalidCommand(t *testing.T) { + err := OpenWithEditor("/tmp/fake", "/nonexistent/cmd") + assert.Error(t, err) +} -- cgit v1.3