You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
func dedent(s string) string {
|
|
lines := strings.Split(s, "\n")
|
|
|
|
// Remove leading/trailing empty lines
|
|
for len(lines) > 0 && strings.TrimSpace(lines[0]) == "" {
|
|
lines = lines[1:]
|
|
}
|
|
for len(lines) > 0 && strings.TrimSpace(lines[len(lines)-1]) == "" {
|
|
lines = lines[:len(lines)-1]
|
|
}
|
|
|
|
// Use the next line to determine indentation pattern
|
|
indent := regexp.MustCompile(`^\s*`).FindString(lines[0])
|
|
for i, line := range lines {
|
|
lines[i] = strings.TrimPrefix(line, indent)
|
|
}
|
|
|
|
return strings.Join(lines, "\n")
|
|
}
|
|
|
|
func longMockOutput(lines int) string {
|
|
var b strings.Builder
|
|
b.WriteString("Running test-suite...\n\n")
|
|
for i := 1; i <= lines; i++ {
|
|
fmt.Fprintf(&b, "ok %02d package/name - test case %d passed\n", i%10, i)
|
|
}
|
|
b.WriteString("\nSUMMARY: 58 passed, 2 skipped, 0 failed\n")
|
|
return b.String()
|
|
}
|
|
|
|
func mockResultFor(input string) string {
|
|
// simple mock: echo input and add a few lines for realism
|
|
switch input {
|
|
case "whoami":
|
|
return "alice"
|
|
case "date":
|
|
return "Fri Aug 22 21:23:00 CEST 2025"
|
|
case "uptime":
|
|
return " 21:23:00 up 3 days, 4:12, 2 users, load average: 0.42, 0.50, 0.47"
|
|
default:
|
|
return fmt.Sprintf("Mock result for: %s\n\n%s", input, longMockOutput(20))
|
|
}
|
|
}
|