gopkg.in/ubuntu-core/snappy.v0@v0.0.0-20210902073436-25a8614f10a6/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 . "gopkg.in/check.v1" 24 25 "github.com/snapcore/snapd/interfaces" 26 "github.com/snapcore/snapd/interfaces/ifacetest" 27 "github.com/snapcore/snapd/interfaces/kmod" 28 "github.com/snapcore/snapd/testutil" 29 ) 30 31 type kmodSuite struct { 32 ifacetest.BackendSuite 33 } 34 35 var _ = Suite(&kmodSuite{}) 36 37 func (s *kmodSuite) SetUpTest(c *C) { 38 s.Backend = &kmod.Backend{} 39 s.BackendSuite.SetUpTest(c) 40 } 41 42 func (s *kmodSuite) TearDownTest(c *C) { 43 s.BackendSuite.TearDownTest(c) 44 } 45 46 func (s *kmodSuite) TestModprobeCall(c *C) { 47 cmd := testutil.MockCommand(c, "modprobe", "") 48 defer cmd.Restore() 49 50 b, ok := s.Backend.(*kmod.Backend) 51 c.Assert(ok, Equals, true) 52 b.LoadModules([]string{ 53 "module1", 54 "module2", 55 }) 56 c.Assert(cmd.Calls(), DeepEquals, [][]string{ 57 {"modprobe", "--syslog", "module1"}, 58 {"modprobe", "--syslog", "module2"}, 59 }) 60 } 61 62 func (s *kmodSuite) TestNoModprobeCallWhenPreseeding(c *C) { 63 cmd := testutil.MockCommand(c, "modprobe", "") 64 defer cmd.Restore() 65 66 b := kmod.Backend{} 67 opts := &interfaces.SecurityBackendOptions{ 68 Preseed: true, 69 } 70 c.Assert(b.Initialize(opts), IsNil) 71 72 b.LoadModules([]string{"module1"}) 73 c.Assert(cmd.Calls(), HasLen, 0) 74 }