Files

42 lines
1.1 KiB
Go
Raw Permalink Normal View History

// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
// SPDX-License-Identifier: MIT
package nfs4server
import (
"bytes"
"log"
"os"
"strings"
"testing"
"time"
"sourcedock.dev/petrbalvin/nfs/internal/nfs4"
)
// TestOpName covers the log names of the common operations and the
// numeric fallback.
func TestOpName(t *testing.T) {
for op, want := range map[uint32]string{
nfs4.OpGetattr: "GETATTR", nfs4.OpReaddir: "READDIR",
nfs4.OpReclaimComplete: "RECLAIM_COMPLETE", nfs4.OpGetxattr: "GETXATTR",
999: "OP999",
} {
if got := opName(op); got != want {
t.Fatalf("opName(%d) = %q, want %q", op, got, want)
}
}
}
// TestLogOp covers the log line shape: operation, status, duration.
func TestLogOp(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
t.Cleanup(func() { log.SetOutput(os.Stderr) })
logOp(nfs4.OpWrite, nfs4.ErrOK, 1500*time.Microsecond)
line := buf.String()
if !strings.Contains(line, "WRITE status 0") || !strings.Contains(line, "1.5") {
t.Fatalf("log line %q misses the operation, the status or the duration", line)
}
}