knobs_linux_test.go 801 B

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