github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/lib/cgutil/editor_test.go (about)

     1  //go:build linux
     2  
     3  package cgutil
     4  
     5  import (
     6  	"os"
     7  	"path/filepath"
     8  	"testing"
     9  
    10  	"github.com/hashicorp/nomad/client/testutil"
    11  	"github.com/hashicorp/nomad/helper/uuid"
    12  	"github.com/shoenig/test/must"
    13  )
    14  
    15  func createCG(t *testing.T) (string, func()) {
    16  	name := uuid.Short() + ".scope"
    17  	path := filepath.Join(CgroupRoot, name)
    18  	err := os.Mkdir(path, 0o755)
    19  	must.NoError(t, err)
    20  
    21  	return name, func() {
    22  		_ = os.Remove(path)
    23  	}
    24  }
    25  
    26  func TestCG_editor(t *testing.T) {
    27  	testutil.CgroupsCompatibleV2(t)
    28  
    29  	cg, rm := createCG(t)
    30  	t.Cleanup(rm)
    31  
    32  	edits := &editor{cg}
    33  	writeErr := edits.write("cpu.weight.nice", "13")
    34  	must.NoError(t, writeErr)
    35  
    36  	b, readErr := edits.read("cpu.weight.nice")
    37  	must.NoError(t, readErr)
    38  	must.Eq(t, "13", b)
    39  }