github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/interfaces/kmod/kmod_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package kmod_test 21 22 import ( 23 "github.com/snapcore/snapd/interfaces" 24 "github.com/snapcore/snapd/interfaces/ifacetest" 25 "github.com/snapcore/snapd/interfaces/kmod" 26 "github.com/snapcore/snapd/testutil" 27 . "gopkg.in/check.v1" 28 ) 29 30 type kmodSuite struct { 31 ifacetest.BackendSuite 32 } 33 34 var _ = Suite(&kmodSuite{}) 35 36 func (s *kmodSuite) SetUpTest(c *C) { 37 s.Backend = &kmod.Backend{} 38 s.BackendSuite.SetUpTest(c) 39 } 40 41 func (s *kmodSuite) TearDownTest(c *C) { 42 s.BackendSuite.TearDownTest(c) 43 } 44 45 func (s *kmodSuite) TestModprobeCall(c *C) { 46 cmd := testutil.MockCommand(c, "modprobe", "") 47 defer cmd.Restore() 48 49 b, ok := s.Backend.(*kmod.Backend) 50 c.Assert(ok, Equals, true) 51 b.LoadModules([]string{ 52 "module1", 53 "module2", 54 }) 55 c.Assert(cmd.Calls(), DeepEquals, [][]string{ 56 {"modprobe", "--syslog", "module1"}, 57 {"modprobe", "--syslog", "module2"}, 58 }) 59 } 60 61 func (s *kmodSuite) TestNoModprobeCallWhenPreseeding(c *C) { 62 cmd := testutil.MockCommand(c, "modprobe", "") 63 defer cmd.Restore() 64 65 b := kmod.Backend{} 66 opts := &interfaces.SecurityBackendOptions{ 67 Preseed: true, 68 } 69 c.Assert(b.Initialize(opts), IsNil) 70 71 b.LoadModules([]string{"module1"}) 72 c.Assert(cmd.Calls(), HasLen, 0) 73 }