feat: CLI-Skeleton mit version/serve/check und Makefile
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NBHF4R9EAejDJUMdwr6C68
This commit is contained in:
parent
bb84607bf8
commit
fbfff90b38
8 changed files with 196 additions and 0 deletions
43
cmd/vpnportal/main_test.go
Normal file
43
cmd/vpnportal/main_test.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
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())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue