Add extension normalization command

This commit is contained in:
Rogee
2025-10-30 10:31:53 +08:00
parent f66c59fd57
commit 6a353b5086
35 changed files with 2306 additions and 2 deletions

View File

@@ -0,0 +1,52 @@
package integration
import (
"bytes"
"os"
"path/filepath"
"testing"
renamercmd "github.com/rogeecn/renamer/cmd"
)
func TestExtensionAutomationUndo(t *testing.T) {
t.Parallel()
tmp := t.TempDir()
createFile(t, filepath.Join(tmp, "config.yaml"))
createFile(t, filepath.Join(tmp, "notes.yml"))
var applyOut bytes.Buffer
apply := renamercmd.NewRootCommand()
apply.SetOut(&applyOut)
apply.SetErr(&applyOut)
apply.SetArgs([]string{"extension", ".yaml", ".yml", ".yml", "--yes", "--path", tmp})
if err := apply.Execute(); err != nil {
t.Fatalf("automation apply failed: %v\noutput: %s", err, applyOut.String())
}
if _, err := os.Stat(filepath.Join(tmp, "config.yml")); err != nil {
t.Fatalf("expected config.yml after apply: %v", err)
}
if _, err := os.Stat(filepath.Join(tmp, "config.yaml")); !os.IsNotExist(err) {
t.Fatalf("expected config.yaml renamed, err=%v", err)
}
var undoOut bytes.Buffer
undo := renamercmd.NewRootCommand()
undo.SetOut(&undoOut)
undo.SetErr(&undoOut)
undo.SetArgs([]string{"undo", "--path", tmp})
if err := undo.Execute(); err != nil {
t.Fatalf("undo failed: %v\noutput: %s", err, undoOut.String())
}
if _, err := os.Stat(filepath.Join(tmp, "config.yaml")); err != nil {
t.Fatalf("expected config.yaml after undo: %v", err)
}
if _, err := os.Stat(filepath.Join(tmp, "config.yml")); !os.IsNotExist(err) {
t.Fatalf("expected config.yml removed after undo, err=%v", err)
}
}