github.com/hpcng/singularity@v3.1.1+incompatible/pkg/util/sysctl/sysctl_linux_test.go (about) 1 // Copyright (c) 2018, Sylabs Inc. All rights reserved. 2 // This software is licensed under a 3-clause BSD license. Please consult the 3 // LICENSE.md file distributed with the sources of this project regarding your 4 // rights to use or distribute this software. 5 6 package sysctl 7 8 import ( 9 "testing" 10 11 "github.com/sylabs/singularity/internal/pkg/test" 12 ) 13 14 func TestGetSet(t *testing.T) { 15 test.EnsurePrivilege(t) 16 17 value, err := Get("net.ipv4.ip_forward") 18 if err != nil { 19 t.Error(err) 20 } 21 22 if value != "0" && value != "1" { 23 t.Fatalf("non expected value 0 or 1: %s", value) 24 } 25 26 if err := Set("net.ipv4.ip_forward", value); err != nil { 27 t.Error(err) 28 } 29 30 value, err = Get("net.ipv4.ip_forward2") 31 if err == nil { 32 t.Errorf("shoud have failed, key doesn't exists") 33 } 34 35 if err := Set("net.ipv4.ip_forward2", value); err == nil { 36 t.Errorf("shoud have failed, key doesn't exists") 37 } 38 }