//go:build linux

package rlimit_test

import (
	"fmt"
	"testing"

	"github.com/alexfalkowski/go-linux/v2/internal/test"
	"github.com/alexfalkowski/go-linux/v2/rlimit"
)

func ExampleGet() {
	limits, err := rlimit.Get(rlimit.OpenFiles)
	if err != nil {
		panic(err)
	}

	fmt.Println(limits.Soft <= limits.Hard)
	// Output: true
}

// Run in a dedicated worker before starting the workload. The worker prints whether the previous soft limit was within its hard limit.
//
//	true
func ExampleSwap() {
	previous, err := rlimit.Swap(rlimit.CoreSize, rlimit.Limits{})
	if err != nil {
		panic(err)
	}

	fmt.Println(previous.Soft <= previous.Hard)
}

func TestExampleSwap(t *testing.T) {
	test.RequireExampleOutput(t, ExampleSwap, "true")
}
