github.com/rigado/snapd@v2.42.5-go-mod+incompatible/interfaces/builtin/jack1_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2019 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 builtin_test
    21  
    22  import (
    23  	. "gopkg.in/check.v1"
    24  
    25  	"github.com/snapcore/snapd/interfaces"
    26  	"github.com/snapcore/snapd/interfaces/apparmor"
    27  	"github.com/snapcore/snapd/interfaces/builtin"
    28  	"github.com/snapcore/snapd/snap"
    29  	"github.com/snapcore/snapd/snap/snaptest"
    30  	"github.com/snapcore/snapd/testutil"
    31  )
    32  
    33  type jack1InterfaceSuite struct {
    34  	iface    interfaces.Interface
    35  	slotInfo *snap.SlotInfo
    36  	slot     *interfaces.ConnectedSlot
    37  	plugInfo *snap.PlugInfo
    38  	plug     *interfaces.ConnectedPlug
    39  }
    40  
    41  var _ = Suite(&jack1InterfaceSuite{
    42  	iface: builtin.MustInterface("jack1"),
    43  })
    44  
    45  func (s *jack1InterfaceSuite) SetUpTest(c *C) {
    46  	var mockPlugSnapInfoYaml = `name: other
    47  version: 1.0
    48  apps:
    49   app:
    50    command: foo
    51    plugs: [jack1]
    52  `
    53  	s.slotInfo = &snap.SlotInfo{
    54  		Snap:      &snap.Info{SuggestedName: "core", SnapType: snap.TypeOS},
    55  		Name:      "jack1",
    56  		Interface: "jack1",
    57  	}
    58  	s.slot = interfaces.NewConnectedSlot(s.slotInfo, nil, nil)
    59  	snapInfo := snaptest.MockInfo(c, mockPlugSnapInfoYaml, nil)
    60  	s.plugInfo = snapInfo.Plugs["jack1"]
    61  	s.plug = interfaces.NewConnectedPlug(s.plugInfo, nil, nil)
    62  }
    63  
    64  func (s *jack1InterfaceSuite) TestName(c *C) {
    65  	c.Assert(s.iface.Name(), Equals, "jack1")
    66  }
    67  
    68  func (s *jack1InterfaceSuite) TestSanitizeSlot(c *C) {
    69  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
    70  }
    71  
    72  func (s *jack1InterfaceSuite) TestSanitizePlug(c *C) {
    73  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    74  }
    75  
    76  func (s *jack1InterfaceSuite) TestAppArmorSpec(c *C) {
    77  	spec := &apparmor.Specification{}
    78  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    79  	c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.other.app"})
    80  	c.Assert(spec.SnippetForTag("snap.other.app"), testutil.Contains, "owner /dev/shm/jack-[0-9]*/*/* rw")
    81  }
    82  
    83  func (s *jack1InterfaceSuite) TestInterfaces(c *C) {
    84  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
    85  }
    86  
    87  func (s *jack1InterfaceSuite) TestStaticInfo(c *C) {
    88  	si := interfaces.StaticInfoOf(s.iface)
    89  	c.Assert(si.ImplicitOnCore, Equals, false)
    90  	c.Assert(si.ImplicitOnClassic, Equals, true)
    91  	c.Assert(si.Summary, Equals, `allows interacting with a JACK1 server`)
    92  	c.Assert(si.BaseDeclarationSlots, testutil.Contains, "jack1")
    93  }