github.com/kubiko/snapd@v0.0.0-20201013125620-d4f3094d9ddf/interfaces/builtin/kernel_module_observe_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  /*
     3   * Copyright (C) 2018 Canonical Ltd
     4   *
     5   * This program is free software: you can redistribute it and/or modify
     6   * it under the terms of the GNU General Public License version 3 as
     7   * published by the Free Software Foundation.
     8   *
     9   * This program is distributed in the hope that it will be useful,
    10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12   * GNU General Public License for more details.
    13   *
    14   * You should have received a copy of the GNU General Public License
    15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16   *
    17   */
    18  
    19  package builtin_test
    20  
    21  import (
    22  	"github.com/snapcore/snapd/interfaces"
    23  	"github.com/snapcore/snapd/interfaces/apparmor"
    24  	"github.com/snapcore/snapd/interfaces/builtin"
    25  	"github.com/snapcore/snapd/snap"
    26  	"github.com/snapcore/snapd/testutil"
    27  	. "gopkg.in/check.v1"
    28  )
    29  
    30  type KernelModuleObserveInterfaceSuite struct {
    31  	iface    interfaces.Interface
    32  	slotInfo *snap.SlotInfo
    33  	slot     *interfaces.ConnectedSlot
    34  	plugInfo *snap.PlugInfo
    35  	plug     *interfaces.ConnectedPlug
    36  }
    37  
    38  var _ = Suite(&KernelModuleObserveInterfaceSuite{
    39  	iface: builtin.MustInterface("kernel-module-observe"),
    40  })
    41  
    42  const kernelmodobsConsumerYaml = `name: consumer
    43  version: 0
    44  apps:
    45   app:
    46    plugs: [kernel-module-observe]
    47  `
    48  
    49  const kernelmodobsCoreYaml = `name: core
    50  version: 0
    51  type: os
    52  slots:
    53    kernel-module-observe:
    54  `
    55  
    56  func (s *KernelModuleObserveInterfaceSuite) SetUpTest(c *C) {
    57  	s.plug, s.plugInfo = MockConnectedPlug(c, kernelmodobsConsumerYaml, nil, "kernel-module-observe")
    58  	s.slot, s.slotInfo = MockConnectedSlot(c, kernelmodobsCoreYaml, nil, "kernel-module-observe")
    59  }
    60  
    61  func (s *KernelModuleObserveInterfaceSuite) TestName(c *C) {
    62  	c.Assert(s.iface.Name(), Equals, "kernel-module-observe")
    63  }
    64  
    65  func (s *KernelModuleObserveInterfaceSuite) TestSanitizeSlot(c *C) {
    66  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
    67  }
    68  
    69  func (s *KernelModuleObserveInterfaceSuite) TestSanitizePlug(c *C) {
    70  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    71  }
    72  
    73  func (s *KernelModuleObserveInterfaceSuite) TestAppArmorSpec(c *C) {
    74  	spec := &apparmor.Specification{}
    75  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    76  	c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"})
    77  	c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "# Description: Allow querying of kernel modules")
    78  }
    79  
    80  func (s *KernelModuleObserveInterfaceSuite) TestStaticInfo(c *C) {
    81  	si := interfaces.StaticInfoOf(s.iface)
    82  	c.Assert(si.ImplicitOnCore, Equals, true)
    83  	c.Assert(si.ImplicitOnClassic, Equals, true)
    84  	c.Assert(si.Summary, Equals, `allows querying of kernel modules`)
    85  	c.Assert(si.BaseDeclarationSlots, testutil.Contains, "kernel-module-observe")
    86  }
    87  
    88  func (s *KernelModuleObserveInterfaceSuite) TestAutoConnect(c *C) {
    89  	c.Assert(s.iface.AutoConnect(s.plugInfo, s.slotInfo), Equals, true)
    90  }
    91  
    92  func (s *KernelModuleObserveInterfaceSuite) TestInterfaces(c *C) {
    93  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
    94  }