//go:build !windows package disk import ( "io" "os" "testing" "golang.org/x/sys/unix" "s1d3sw1ped/steamcache2/steamcache/metrics" ) func TestIsNoSpaceError(t *testing.T) { t.Parallel() if isNoSpaceError(nil) { t.Error("nil must not be ENOSPC") } if isNoSpaceError(io.EOF) { t.Error("EOF must not be ENOSPC") } if !isNoSpaceError(unix.ENOSPC) { t.Error("unix.ENOSPC should match") } wrapped := &os.PathError{Op: "write", Path: "x", Err: unix.ENOSPC} if !isNoSpaceError(wrapped) { t.Error("PathError wrapping ENOSPC should match") } } func TestDiskFS_ENOSPCCapacityPressure(t *testing.T) { t.Parallel() d, err := New(t.TempDir(), 1024, nil) if err != nil { t.Fatal(err) } met := metrics.NewMetrics() d.SetMetrics(met) d.recordIfNoSpace(io.EOF) if got := met.GetStats().CapacityPressureEvents; got != 0 { t.Fatalf("non-ENOSPC counted: %d", got) } d.recordIfNoSpace(unix.ENOSPC) if got := met.GetStats().CapacityPressureEvents; got != 1 { t.Fatalf("unix.ENOSPC: CapacityPressureEvents=%d, want 1", got) } if got := met.GetStats().Evictions; got != 0 { t.Fatalf("ENOSPC must not increment evictions, got %d", got) } d.recordIfNoSpace(&os.PathError{Op: "write", Path: "p", Err: unix.ENOSPC}) if got := met.GetStats().CapacityPressureEvents; got != 2 { t.Fatalf("wrapped ENOSPC: CapacityPressureEvents=%d, want 2", got) } }