Add vsock-backed VM port inspection
Let the host ask the guest vsock agent to run ss so open ports can be surfaced without SSHing in manually. Add a narrow /ports agent endpoint, a daemon vm.ports RPC that enriches listeners with <hostname>.vm endpoints and best-effort HTTP links, and a concurrent 'banger vm ports' CLI table for one or more VMs. Update the guest package contract to include ss for rebuilt Debian images, allow the guest agent package in the shell-out policy, and cover the new parsing/RPC/CLI flow in tests. Verified with GOCACHE=/tmp/banger-gocache go test ./... outside the sandbox, make build, bash -n customize.sh make-rootfs-void.sh verify.sh, and ./banger vm ports --help.
This commit is contained in:
parent
3ed78fdcfc
commit
c298ed2fc1
11 changed files with 1029 additions and 23 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package vsockagent
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
|
@ -9,6 +10,12 @@ import (
|
|||
"log/slog"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
sdkvsock "github.com/firecracker-microvm/firecracker-go-sdk/vsock"
|
||||
|
|
@ -18,6 +25,7 @@ import (
|
|||
const (
|
||||
Port uint32 = 42070
|
||||
HealthPath = "/healthz"
|
||||
PortsPath = "/ports"
|
||||
HealthyStatus = "ok"
|
||||
GuestBinaryName = "banger-vsock-agent"
|
||||
GuestInstallPath = "/usr/local/bin/" + GuestBinaryName
|
||||
|
|
@ -38,10 +46,28 @@ WantedBy=multi-user.target
|
|||
modulesLoadConfig = "vsock\nvmw_vsock_virtio_transport\n"
|
||||
)
|
||||
|
||||
var (
|
||||
portCollector = CollectPorts
|
||||
processRe = regexp.MustCompile(`"([^"]+)",pid=(\d+)`)
|
||||
)
|
||||
|
||||
type HealthResponse struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type PortListener struct {
|
||||
Proto string `json:"proto"`
|
||||
BindAddress string `json:"bind_address"`
|
||||
Port int `json:"port"`
|
||||
PID int `json:"pid,omitempty"`
|
||||
Process string `json:"process,omitempty"`
|
||||
Command string `json:"command,omitempty"`
|
||||
}
|
||||
|
||||
type PortsResponse struct {
|
||||
Listeners []PortListener `json:"listeners"`
|
||||
}
|
||||
|
||||
func NewHandler() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc(HealthPath, func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -52,30 +78,24 @@ func NewHandler() http.Handler {
|
|||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(HealthResponse{Status: HealthyStatus})
|
||||
})
|
||||
mux.HandleFunc(PortsPath, func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
listeners, err := portCollector(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(PortsResponse{Listeners: listeners})
|
||||
})
|
||||
return mux
|
||||
}
|
||||
|
||||
func Health(ctx context.Context, logger *slog.Logger, socketPath string) error {
|
||||
transport := &http.Transport{
|
||||
DisableKeepAlives: true,
|
||||
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
|
||||
return sdkvsock.DialContext(
|
||||
ctx,
|
||||
socketPath,
|
||||
Port,
|
||||
sdkvsock.WithRetryTimeout(3*time.Second),
|
||||
sdkvsock.WithRetryInterval(100*time.Millisecond),
|
||||
sdkvsock.WithLogger(newLogger(logger)),
|
||||
)
|
||||
},
|
||||
}
|
||||
defer transport.CloseIdleConnections()
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://vsock"+HealthPath, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := (&http.Client{Transport: transport}).Do(req)
|
||||
resp, err := doRequest(ctx, logger, socketPath, HealthPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -97,6 +117,35 @@ func Health(ctx context.Context, logger *slog.Logger, socketPath string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func Ports(ctx context.Context, logger *slog.Logger, socketPath string) ([]PortListener, error) {
|
||||
resp, err := doRequest(ctx, logger, socketPath, PortsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
|
||||
return nil, fmt.Errorf("unexpected ports status %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
var payload PortsResponse
|
||||
if err := json.NewDecoder(resp.Body).Decode(&payload); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return payload.Listeners, nil
|
||||
}
|
||||
|
||||
func CollectPorts(ctx context.Context) ([]PortListener, error) {
|
||||
cmd := exec.CommandContext(ctx, "ss", "-H", "-lntup")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
if len(output) > 0 {
|
||||
return nil, fmt.Errorf("run ss: %w: %s", err, bytes.TrimSpace(output))
|
||||
}
|
||||
return nil, fmt.Errorf("run ss: %w", err)
|
||||
}
|
||||
return parsePortListeners(output, readProcessCommandLine)
|
||||
}
|
||||
|
||||
func ServiceUnit() string {
|
||||
return serviceUnit
|
||||
}
|
||||
|
|
@ -156,3 +205,233 @@ func (h slogHook) Fire(entry *logrus.Entry) error {
|
|||
func IsServerClosed(err error) bool {
|
||||
return errors.Is(err, http.ErrServerClosed)
|
||||
}
|
||||
|
||||
func doRequest(ctx context.Context, logger *slog.Logger, socketPath, path string) (*http.Response, error) {
|
||||
transport := &http.Transport{
|
||||
DisableKeepAlives: true,
|
||||
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
|
||||
return sdkvsock.DialContext(
|
||||
ctx,
|
||||
socketPath,
|
||||
Port,
|
||||
sdkvsock.WithRetryTimeout(3*time.Second),
|
||||
sdkvsock.WithRetryInterval(100*time.Millisecond),
|
||||
sdkvsock.WithLogger(newLogger(logger)),
|
||||
)
|
||||
},
|
||||
}
|
||||
client := &http.Client{Transport: transport}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://vsock"+path, nil)
|
||||
if err != nil {
|
||||
transport.CloseIdleConnections()
|
||||
return nil, err
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
transport.CloseIdleConnections()
|
||||
return nil, err
|
||||
}
|
||||
return wrappedResponse(resp, transport), nil
|
||||
}
|
||||
|
||||
type responseCloser struct {
|
||||
io.ReadCloser
|
||||
transport *http.Transport
|
||||
}
|
||||
|
||||
func (c responseCloser) Close() error {
|
||||
err := c.ReadCloser.Close()
|
||||
c.transport.CloseIdleConnections()
|
||||
return err
|
||||
}
|
||||
|
||||
func wrappedResponse(resp *http.Response, transport *http.Transport) *http.Response {
|
||||
if resp == nil || resp.Body == nil || transport == nil {
|
||||
return resp
|
||||
}
|
||||
resp.Body = responseCloser{ReadCloser: resp.Body, transport: transport}
|
||||
return resp
|
||||
}
|
||||
|
||||
func parsePortListeners(raw []byte, readCmdline func(int) string) ([]PortListener, error) {
|
||||
lines := strings.Split(strings.TrimSpace(string(raw)), "\n")
|
||||
listeners := make([]PortListener, 0, len(lines))
|
||||
wildcards := make(map[string]struct{})
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
parsed, err := parseSSLine(line, readCmdline)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, listener := range parsed {
|
||||
if isLoopbackAddress(listener.BindAddress) {
|
||||
continue
|
||||
}
|
||||
if isWildcardAddress(listener.BindAddress) {
|
||||
key := wildcardKey(listener)
|
||||
if _, ok := wildcards[key]; ok {
|
||||
continue
|
||||
}
|
||||
wildcards[key] = struct{}{}
|
||||
}
|
||||
listeners = append(listeners, listener)
|
||||
}
|
||||
}
|
||||
sort.Slice(listeners, func(i, j int) bool {
|
||||
if listeners[i].Proto != listeners[j].Proto {
|
||||
return listeners[i].Proto < listeners[j].Proto
|
||||
}
|
||||
if listeners[i].Port != listeners[j].Port {
|
||||
return listeners[i].Port < listeners[j].Port
|
||||
}
|
||||
if listeners[i].PID != listeners[j].PID {
|
||||
return listeners[i].PID < listeners[j].PID
|
||||
}
|
||||
return listeners[i].BindAddress < listeners[j].BindAddress
|
||||
})
|
||||
return listeners, nil
|
||||
}
|
||||
|
||||
func parseSSLine(line string, readCmdline func(int) string) ([]PortListener, error) {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) < 6 {
|
||||
return nil, fmt.Errorf("parse ss line: expected at least 6 fields, got %d in %q", len(fields), line)
|
||||
}
|
||||
proto := strings.ToLower(strings.TrimSpace(fields[0]))
|
||||
if proto != "tcp" && proto != "udp" {
|
||||
return nil, nil
|
||||
}
|
||||
bindAddress, port, err := parseBindAddress(fields[4])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse ss local address %q: %w", fields[4], err)
|
||||
}
|
||||
if bindAddress != "*" && net.ParseIP(bindAddress) == nil {
|
||||
return nil, nil
|
||||
}
|
||||
processInfo := strings.Join(fields[6:], " ")
|
||||
entries := parseProcessEntries(processInfo)
|
||||
if len(entries) == 0 {
|
||||
return []PortListener{{
|
||||
Proto: proto,
|
||||
BindAddress: bindAddress,
|
||||
Port: port,
|
||||
}}, nil
|
||||
}
|
||||
listeners := make([]PortListener, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
command := strings.TrimSpace(readCmdline(entry.PID))
|
||||
if command == "" {
|
||||
command = entry.Process
|
||||
}
|
||||
listeners = append(listeners, PortListener{
|
||||
Proto: proto,
|
||||
BindAddress: bindAddress,
|
||||
Port: port,
|
||||
PID: entry.PID,
|
||||
Process: entry.Process,
|
||||
Command: command,
|
||||
})
|
||||
}
|
||||
return listeners, nil
|
||||
}
|
||||
|
||||
type processEntry struct {
|
||||
Process string
|
||||
PID int
|
||||
}
|
||||
|
||||
func parseProcessEntries(raw string) []processEntry {
|
||||
matches := processRe.FindAllStringSubmatch(raw, -1)
|
||||
if len(matches) == 0 {
|
||||
return nil
|
||||
}
|
||||
entries := make([]processEntry, 0, len(matches))
|
||||
for _, match := range matches {
|
||||
pid, err := strconv.Atoi(match[2])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
entries = append(entries, processEntry{
|
||||
Process: match[1],
|
||||
PID: pid,
|
||||
})
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
func parseBindAddress(raw string) (string, int, error) {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return "", 0, errors.New("empty address")
|
||||
}
|
||||
var host, portRaw string
|
||||
if strings.HasPrefix(raw, "[") {
|
||||
var err error
|
||||
host, portRaw, err = net.SplitHostPort(raw)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
} else {
|
||||
idx := strings.LastIndex(raw, ":")
|
||||
if idx <= 0 || idx == len(raw)-1 {
|
||||
return "", 0, fmt.Errorf("missing host:port in %q", raw)
|
||||
}
|
||||
host = raw[:idx]
|
||||
portRaw = raw[idx+1:]
|
||||
}
|
||||
if zoneIdx := strings.Index(host, "%"); zoneIdx >= 0 {
|
||||
host = host[:zoneIdx]
|
||||
}
|
||||
host = strings.Trim(host, "[]")
|
||||
if host == "" {
|
||||
host = "*"
|
||||
}
|
||||
port, err := strconv.Atoi(portRaw)
|
||||
if err != nil {
|
||||
return "", 0, err
|
||||
}
|
||||
return host, port, nil
|
||||
}
|
||||
|
||||
func readProcessCommandLine(pid int) string {
|
||||
if pid <= 0 {
|
||||
return ""
|
||||
}
|
||||
data, err := os.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
parts := strings.Split(string(data), "\x00")
|
||||
filtered := parts[:0]
|
||||
for _, part := range parts {
|
||||
part = strings.TrimSpace(part)
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, part)
|
||||
}
|
||||
return strings.Join(filtered, " ")
|
||||
}
|
||||
|
||||
func isLoopbackAddress(host string) bool {
|
||||
if host == "" || host == "*" {
|
||||
return false
|
||||
}
|
||||
ip := net.ParseIP(host)
|
||||
return ip != nil && ip.IsLoopback()
|
||||
}
|
||||
|
||||
func isWildcardAddress(host string) bool {
|
||||
switch host {
|
||||
case "*", "0.0.0.0", "::":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func wildcardKey(listener PortListener) string {
|
||||
return fmt.Sprintf("%s:%d:%d:%s", listener.Proto, listener.Port, listener.PID, listener.Process)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,12 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -37,6 +40,44 @@ func TestNewHandlerHealthz(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNewHandlerPorts(t *testing.T) {
|
||||
origCollector := portCollector
|
||||
t.Cleanup(func() {
|
||||
portCollector = origCollector
|
||||
})
|
||||
portCollector = func(context.Context) ([]PortListener, error) {
|
||||
return []PortListener{{
|
||||
Proto: "tcp",
|
||||
BindAddress: "0.0.0.0",
|
||||
Port: 8080,
|
||||
PID: 42,
|
||||
Process: "python3",
|
||||
Command: "python3 -m http.server 8080",
|
||||
}}, nil
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, PortsPath, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("NewRequest: %v", err)
|
||||
}
|
||||
rr := newTestResponseRecorder()
|
||||
NewHandler().ServeHTTP(rr, req)
|
||||
|
||||
if rr.status != http.StatusOK {
|
||||
t.Fatalf("status = %d, want %d", rr.status, http.StatusOK)
|
||||
}
|
||||
var payload PortsResponse
|
||||
if err := json.Unmarshal(rr.body.Bytes(), &payload); err != nil {
|
||||
t.Fatalf("Unmarshal: %v", err)
|
||||
}
|
||||
if len(payload.Listeners) != 1 {
|
||||
t.Fatalf("listeners = %d, want 1", len(payload.Listeners))
|
||||
}
|
||||
if got := payload.Listeners[0]; got.Command != "python3 -m http.server 8080" {
|
||||
t.Fatalf("listener = %+v, want command", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealth(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
@ -110,6 +151,168 @@ func TestHealth(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPorts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dir := t.TempDir()
|
||||
socketPath := filepath.Join(dir, "fc.vsock")
|
||||
listener, err := net.Listen("unix", socketPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Listen: %v", err)
|
||||
}
|
||||
defer listener.Close()
|
||||
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
done <- err
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
buf := make([]byte, 0, 256)
|
||||
tmp := make([]byte, 256)
|
||||
for {
|
||||
n, err := conn.Read(tmp)
|
||||
if err != nil {
|
||||
done <- err
|
||||
return
|
||||
}
|
||||
buf = append(buf, tmp[:n]...)
|
||||
if strings.Contains(string(buf), "\n") {
|
||||
break
|
||||
}
|
||||
}
|
||||
if got := string(buf); got != "CONNECT 42070\n" {
|
||||
done <- unexpectedStringError(got)
|
||||
return
|
||||
}
|
||||
if _, err := conn.Write([]byte("OK 55\n")); err != nil {
|
||||
done <- err
|
||||
return
|
||||
}
|
||||
|
||||
buf = buf[:0]
|
||||
for {
|
||||
n, err := conn.Read(tmp)
|
||||
if err != nil {
|
||||
done <- err
|
||||
return
|
||||
}
|
||||
buf = append(buf, tmp[:n]...)
|
||||
if strings.Contains(string(buf), "\r\n\r\n") {
|
||||
break
|
||||
}
|
||||
}
|
||||
req := string(buf)
|
||||
if !strings.Contains(req, "GET /ports HTTP/1.1\r\n") {
|
||||
done <- unexpectedStringError(req)
|
||||
return
|
||||
}
|
||||
body := `{"listeners":[{"proto":"tcp","bind_address":"0.0.0.0","port":8080,"pid":42,"process":"python3","command":"python3 -m http.server 8080"}]}`
|
||||
resp := "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: " + strconv.Itoa(len(body)) + "\r\n\r\n" + body
|
||||
_, err = conn.Write([]byte(resp))
|
||||
done <- err
|
||||
}()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
listeners, err := Ports(ctx, nil, socketPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Ports: %v", err)
|
||||
}
|
||||
if len(listeners) != 1 || listeners[0].Port != 8080 || listeners[0].Command != "python3 -m http.server 8080" {
|
||||
t.Fatalf("listeners = %+v, want parsed port listener", listeners)
|
||||
}
|
||||
if err := <-done; err != nil {
|
||||
t.Fatalf("server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePortListenersFiltersLoopbackAndDedupesWildcards(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
raw := strings.Join([]string{
|
||||
`tcp LISTEN 0 4096 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=12,fd=3))`,
|
||||
`tcp LISTEN 0 4096 [::]:22 [::]:* users:(("sshd",pid=12,fd=4))`,
|
||||
`udp UNCONN 0 0 127.0.0.53%lo:53 0.0.0.0:* users:(("stubby",pid=99,fd=3))`,
|
||||
`tcp LISTEN 0 4096 172.16.0.2:8080 0.0.0.0:* users:(("python3",pid=44,fd=6))`,
|
||||
}, "\n")
|
||||
readCmdline := func(pid int) string {
|
||||
switch pid {
|
||||
case 12:
|
||||
return "/usr/sbin/sshd -D"
|
||||
case 44:
|
||||
return "python3 -m http.server 8080"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
listeners, err := parsePortListeners([]byte(raw), readCmdline)
|
||||
if err != nil {
|
||||
t.Fatalf("parsePortListeners: %v", err)
|
||||
}
|
||||
want := []PortListener{
|
||||
{
|
||||
Proto: "tcp",
|
||||
BindAddress: "0.0.0.0",
|
||||
Port: 22,
|
||||
PID: 12,
|
||||
Process: "sshd",
|
||||
Command: "/usr/sbin/sshd -D",
|
||||
},
|
||||
{
|
||||
Proto: "tcp",
|
||||
BindAddress: "172.16.0.2",
|
||||
Port: 8080,
|
||||
PID: 44,
|
||||
Process: "python3",
|
||||
Command: "python3 -m http.server 8080",
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(listeners, want) {
|
||||
t.Fatalf("listeners = %#v, want %#v", listeners, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePortListenersFallsBackToProcessName(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
raw := `tcp LISTEN 0 128 0.0.0.0:5432 0.0.0.0:* users:(("postgres",pid=77,fd=5))`
|
||||
listeners, err := parsePortListeners([]byte(raw), func(int) string { return "" })
|
||||
if err != nil {
|
||||
t.Fatalf("parsePortListeners: %v", err)
|
||||
}
|
||||
if len(listeners) != 1 {
|
||||
t.Fatalf("listeners = %d, want 1", len(listeners))
|
||||
}
|
||||
if listeners[0].Command != "postgres" {
|
||||
t.Fatalf("command = %q, want process fallback", listeners[0].Command)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewHandlerPortsReturnsServerErrorOnCollectorFailure(t *testing.T) {
|
||||
origCollector := portCollector
|
||||
t.Cleanup(func() {
|
||||
portCollector = origCollector
|
||||
})
|
||||
portCollector = func(context.Context) ([]PortListener, error) {
|
||||
return nil, errors.New("ss missing")
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, PortsPath, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("NewRequest: %v", err)
|
||||
}
|
||||
rr := newTestResponseRecorder()
|
||||
NewHandler().ServeHTTP(rr, req)
|
||||
if rr.status != http.StatusInternalServerError {
|
||||
t.Fatalf("status = %d, want %d", rr.status, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
type testResponseRecorder struct {
|
||||
headers http.Header
|
||||
body bytes.Buffer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue