github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/interfaces/backends/backends_test.go (about) 1 /* 2 * Copyright (C) 2017 Canonical Ltd 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License version 3 as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 * 16 */ 17 18 package backends_test 19 20 import ( 21 "testing" 22 23 . "gopkg.in/check.v1" 24 25 "github.com/snapcore/snapd/interfaces/backends" 26 apparmor_sandbox "github.com/snapcore/snapd/sandbox/apparmor" 27 "github.com/snapcore/snapd/testutil" 28 ) 29 30 func Test(t *testing.T) { 31 TestingT(t) 32 } 33 34 type backendsSuite struct{} 35 36 var _ = Suite(&backendsSuite{}) 37 38 func (s *backendsSuite) TestIsAppArmorEnabled(c *C) { 39 for _, level := range []apparmor_sandbox.LevelType{apparmor_sandbox.Unsupported, apparmor_sandbox.Unusable, apparmor_sandbox.Partial, apparmor_sandbox.Full} { 40 restore := apparmor_sandbox.MockLevel(level) 41 defer restore() 42 43 all := backends.Backends() 44 names := make([]string, len(all)) 45 for i, backend := range all { 46 names[i] = string(backend.Name()) 47 } 48 switch level { 49 case apparmor_sandbox.Unsupported, apparmor_sandbox.Unusable: 50 c.Assert(names, Not(testutil.Contains), "apparmor") 51 case apparmor_sandbox.Partial, apparmor_sandbox.Full: 52 c.Assert(names, testutil.Contains, "apparmor") 53 } 54 55 } 56 } 57 58 func (s *backendsSuite) TestEssentialOrdering(c *C) { 59 restore := apparmor_sandbox.MockLevel(apparmor_sandbox.Full) 60 defer restore() 61 62 all := backends.Backends() 63 aaIndex := -1 64 sdIndex := -1 65 for i, backend := range all { 66 switch backend.Name() { 67 case "apparmor": 68 aaIndex = i 69 case "systemd": 70 sdIndex = i 71 } 72 } 73 c.Assert(aaIndex, testutil.IntNotEqual, -1) 74 c.Assert(sdIndex, testutil.IntNotEqual, -1) 75 c.Assert(sdIndex, testutil.IntLessThan, aaIndex) 76 }