package cmd import ( "os" "path/filepath" "testing" "gxlin.org/zk/pkg" ) func TestRename(t *testing.T) { tmpDir := t.TempDir() backlinkedFilename := filepath.Join(tmpDir, "backlinked.md") sourceFilename := filepath.Join(tmpDir, "source.md") targetFilename := filepath.Join(tmpDir, "target.md") os.WriteFile(backlinkedFilename, []byte("[Title](source.md)"), 0644) os.WriteFile(sourceFilename, []byte("Hello World"), 0644) pkg.DocCollection = pkg.NewDocs(tmpDir) rename(sourceFilename, targetFilename) targetFileContent, err := os.ReadFile(targetFilename) if err != nil { t.Error(err) } else if string(targetFileContent) != "Hello World" { t.Errorf("File content or matched after moved") } backlinkedFileContent, err := os.ReadFile(backlinkedFilename) if err != nil { t.Error(err) } else if string(backlinkedFileContent) != "[Title](target.md)" { t.Errorf( "The link in backlinked file doesn't match. File content:\n%s", string(backlinkedFileContent)) } }