github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/libnetwork/osl/kernel/knobs_linux_test.go (about)

     1  package kernel
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/sirupsen/logrus"
     7  	"gotest.tools/v3/assert"
     8  	is "gotest.tools/v3/assert/cmp"
     9  )
    10  
    11  func TestReadWriteKnobs(t *testing.T) {
    12  	for _, k := range []string{
    13  		"net.ipv4.neigh.default.gc_thresh1",
    14  		"net.ipv4.neigh.default.gc_thresh2",
    15  		"net.ipv4.neigh.default.gc_thresh3",
    16  	} {
    17  		// Check if the test is able to read the value
    18  		v, err := readSystemProperty(k)
    19  		if err != nil {
    20  			logrus.WithError(err).Warnf("Path %v not readable", k)
    21  			// the path is not there, skip this key
    22  			continue
    23  		}
    24  		// Test the write
    25  		assert.Check(t, writeSystemProperty(k, "10000"))
    26  		newV, err := readSystemProperty(k)
    27  		assert.NilError(t, err)
    28  		assert.Check(t, is.Equal(newV, "10000"))
    29  		// Restore value
    30  		assert.Check(t, writeSystemProperty(k, v))
    31  	}
    32  }