1package cmd23import (4 "bytes"5 "encoding/json"6 "os"7 "path/filepath"8 "testing"910 "github.com/FelineStateMachine/puzzletea/export/pack"11 "github.com/FelineStateMachine/puzzletea/puzzle"12 "github.com/spf13/cobra"13)1415func TestExportCmdRunsSpecFile(t *testing.T) {16 restore := snapshotCommandGlobals(t)17 defer restore()1819 dir := t.TempDir()20 specPath := filepath.Join(dir, "spec.json")21 pdfPath := filepath.Join(dir, "sample.pdf")22 jsonlPath := filepath.Join(dir, "sample.jsonl")2324 spec := packexport.Spec{25 Title: "CLI Export",26 Volume: 1,27 SheetLayout: "half-letter",28 PDFOutputPath: pdfPath,29 JSONLOutputPath: jsonlPath,30 Counts: map[puzzle.GameID]map[puzzle.ModeID]int{31 puzzle.CanonicalGameID("Sudoku"): {32 puzzle.CanonicalModeID("Easy"): 1,33 },34 },35 }36 data, err := json.Marshal(spec)37 if err != nil {38 t.Fatal(err)39 }40 if err := os.WriteFile(specPath, data, 0o644); err != nil {41 t.Fatal(err)42 }4344 exportSpecPath = specPath45 var out bytes.Buffer46 cmd := &cobra.Command{}47 cmd.SetOut(&out)4849 if err := exportCmd.RunE(cmd, nil); err != nil {50 t.Fatalf("exportCmd.RunE returned error: %v", err)51 }52 if out.String() == "" {53 t.Fatal("expected command output")54 }55 if _, err := os.Stat(pdfPath); err != nil {56 t.Fatalf("expected pdf output: %v", err)57 }58 if _, err := os.Stat(jsonlPath); err != nil {59 t.Fatalf("expected jsonl output: %v", err)60 }61}