go-devops/cmd/docs/cmd_sync_test.go

81 lines
1.9 KiB
Go
Raw Normal View History

package docs
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestCopyZensicalReadme_Good(t *testing.T) {
srcDir := t.TempDir()
destDir := t.TempDir()
src := filepath.Join(srcDir, "README.md")
if err := os.WriteFile(src, []byte("# Hello\n\nBody text.\n"), 0o644); err != nil {
t.Fatalf("write source README: %v", err)
}
if err := copyZensicalReadme(src, destDir); err != nil {
t.Fatalf("copy README: %v", err)
}
output := filepath.Join(destDir, "index.md")
data, err := os.ReadFile(output)
if err != nil {
t.Fatalf("read output index.md: %v", err)
}
content := string(data)
if !strings.HasPrefix(content, "---\n") {
t.Fatalf("expected Hugo front matter at start, got: %q", content)
}
if !strings.Contains(content, "title: \"README\"") {
t.Fatalf("expected README title in front matter, got: %q", content)
}
if !strings.Contains(content, "Body text.") {
t.Fatalf("expected README body to be preserved, got: %q", content)
}
}
2026-04-01 07:03:38 +00:00
fix(devops): address CodeRabbit findings on PR #2 15+ findings dispositioned. AX-6-conformant — no testify reintroduced. Code fixes: - cmd/dev/service.go: no-op now returns OK:true, unchecked prompt type assertion guarded - cmd/workspace/config.go: relative parent traversal blocked + regression test, fmt.Errorf wrapping - cmd/dev/cmd_issues.go + cmd_reviews.go: import ordering - tests/cli/devops/main.go: raw WalkDir errors wrapped - tests/cli/devops/Taskfile.yaml: strict shell flags - cmd/vanity-import/Dockerfile + docs/development.md: Go 1.26 alignment - locales/embed.go: missing dappco.re/go/i18n checksum Test infra: - New local test helpers in cmd/dev, cmd/setup, devkit, snapshot - All testify usages already absent — local stdlib helpers preferred per AX-6 ban - Test naming aligned (Test{Filename}_{Function}_{Good,Bad,Ugly} per AX-10) Disposition replies (RESOLVED-COMMENT, no testify added): - cmd/dev/cmd_apply_test.go, cmd/setup/cmd_ci_test.go, snapshot_test.go, devkit/coverage_test.go: CodeRabbit testify suggestions get reasoning reply per AX-6 ban; local helpers are convention. - SonarCloud/GHAS: no PR checks/annotations found; code-scanning API returned no analysis, secret scanning disabled. Verification: gofmt clean, git diff --check clean, no testify imports. Targeted go vet + go test pass for cmd/workspace + devkit + snapshot. Full go vet ./... blocked by pre-existing dappco.re/go/scm codeberg.org/forgejo/go-sdk auth/replacement issue (out of scope). Closes findings on https://github.com/dAppCore/go-devops/pull/2 Co-authored-by: Codex <noreply@openai.com>
2026-04-27 15:07:24 +01:00
func TestResetOutputDir_ClearsExistingFiles_Good(t *testing.T) {
2026-04-01 07:03:38 +00:00
dir := t.TempDir()
stale := filepath.Join(dir, "stale.md")
if err := os.WriteFile(stale, []byte("old content"), 0o644); err != nil {
t.Fatalf("write stale file: %v", err)
}
if err := resetOutputDir(dir); err != nil {
t.Fatalf("reset output dir: %v", err)
}
if _, err := os.Stat(stale); !os.IsNotExist(err) {
t.Fatalf("expected stale file to be removed, got err=%v", err)
}
info, err := os.Stat(dir)
if err != nil {
t.Fatalf("stat output dir: %v", err)
}
if !info.IsDir() {
t.Fatalf("expected output dir to exist as a directory")
}
}
func TestGoHelpOutputName_Good(t *testing.T) {
cases := map[string]string{
"core": "go",
"core-admin": "admin",
"core-api": "api",
"go-example": "go-example",
"custom-repo": "custom-repo",
}
for input, want := range cases {
if got := goHelpOutputName(input); got != want {
t.Fatalf("goHelpOutputName(%q) = %q, want %q", input, got, want)
}
}
}