package main import ( "fmt" "net/http" "net/http/httptest" "os" "path/filepath" ) func main() { fmt.Println("Testing file output...") allPassed := true // Test 1: Write output to file fmt.Print("Test 1: Write output to file... ") // Create a test server server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") fmt.Fprint(w, "
This content should be in a file.
") })) defer server.Close() // Create temporary directory for test files tempDir, err := createTempDir("mdget-test-output-") if err != nil { fmt.Printf("❌ Failed to create temp dir: %v\n", err) os.Exit(1) } defer cleanup(tempDir) outputFile := filepath.Join(tempDir, "output.md") // Run mdget with output file output, err := runMdget("--output", outputFile, server.URL) if !assertError("File output", err, false) { allPassed = false } else { // Check if file was created content, err := readFile(outputFile) if err != nil { fmt.Printf("❌ Failed to read output file: %v\n", err) allPassed = false } else if !assertContains("File content", content, "# File Test") { allPassed = false } else if !assertContains("File content paragraph", content, "This content should be in a file") { allPassed = false } else if !assertNotContains("File should not contain HTML tags", content, "") { allPassed = false } else { fmt.Println("✅") } } // Test 2: Output to stdout when no --output flag fmt.Print("Test 2: Output to stdout (no --output flag)... ") server2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") fmt.Fprint(w, "