Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NBHF4R9EAejDJUMdwr6C68
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRunVersion(t *testing.T) {
|
|
var out, errOut bytes.Buffer
|
|
code := run([]string{"version"}, &out, &errOut)
|
|
if code != 0 {
|
|
t.Fatalf("exit code = %d, want 0 (stderr: %s)", code, errOut.String())
|
|
}
|
|
got := out.String()
|
|
for _, want := range []string{"vpnportal", "commit", "built"} {
|
|
if !strings.Contains(got, want) {
|
|
t.Errorf("output %q missing %q", got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRunUnknownCommand(t *testing.T) {
|
|
var out, errOut bytes.Buffer
|
|
if code := run([]string{"frobnicate"}, &out, &errOut); code != 2 {
|
|
t.Fatalf("exit code = %d, want 2", code)
|
|
}
|
|
if !strings.Contains(errOut.String(), "frobnicate") {
|
|
t.Errorf("stderr should name the unknown command, got %q", errOut.String())
|
|
}
|
|
}
|
|
|
|
func TestRunNoArgsDefaultsToServe(t *testing.T) {
|
|
var out, errOut bytes.Buffer
|
|
// serve ohne --config muss mit Fehler abbrechen, nicht mit "unknown command"
|
|
code := run(nil, &out, &errOut)
|
|
if code == 2 {
|
|
t.Fatalf("no args must default to serve, not unknown-command")
|
|
}
|
|
if !strings.Contains(errOut.String(), "config") {
|
|
t.Errorf("stderr should complain about missing config, got %q", errOut.String())
|
|
}
|
|
}
|