gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/steam_support_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2022 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  	"gitee.com/mysnapcore/mysnapd/interfaces"
    26  	"gitee.com/mysnapcore/mysnapd/interfaces/apparmor"
    27  	"gitee.com/mysnapcore/mysnapd/interfaces/builtin"
    28  	"gitee.com/mysnapcore/mysnapd/interfaces/seccomp"
    29  	"gitee.com/mysnapcore/mysnapd/snap"
    30  	"gitee.com/mysnapcore/mysnapd/testutil"
    31  )
    32  
    33  type SteamSupportInterfaceSuite struct {
    34  	iface    interfaces.Interface
    35  	slotInfo *snap.SlotInfo
    36  	slot     *interfaces.ConnectedSlot
    37  	plugInfo *snap.PlugInfo
    38  	plug     *interfaces.ConnectedPlug
    39  }
    40  
    41  const steamSupportCoreYaml = `name: core
    42  version: 0
    43  type: os
    44  slots:
    45    steam-support:
    46  `
    47  
    48  const steamSupportConsumerYaml = `name: consumer
    49  version: 0
    50  apps:
    51    app:
    52      plugs: [steam-support]
    53  `
    54  
    55  var _ = Suite(&SteamSupportInterfaceSuite{
    56  	iface: builtin.MustInterface("steam-support"),
    57  })
    58  
    59  func (s *SteamSupportInterfaceSuite) SetUpTest(c *C) {
    60  	s.plug, s.plugInfo = MockConnectedPlug(c, steamSupportConsumerYaml, nil, "steam-support")
    61  	s.slot, s.slotInfo = MockConnectedSlot(c, steamSupportCoreYaml, nil, "steam-support")
    62  }
    63  
    64  func (s *SteamSupportInterfaceSuite) TestName(c *C) {
    65  	c.Assert(s.iface.Name(), Equals, "steam-support")
    66  }
    67  
    68  func (s *SteamSupportInterfaceSuite) TestSanitizeSlot(c *C) {
    69  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
    70  }
    71  
    72  func (s *SteamSupportInterfaceSuite) TestSanitizePlug(c *C) {
    73  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    74  }
    75  
    76  func (s *SteamSupportInterfaceSuite) TestAppArmorSpec(c *C) {
    77  
    78  	spec := &apparmor.Specification{}
    79  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    80  	c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"})
    81  	c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "mount options=(rw, rbind) /tmp/newroot/ -> /tmp/newroot/,\n")
    82  }
    83  
    84  func (s *SteamSupportInterfaceSuite) TestSecCompSpec(c *C) {
    85  	spec := &seccomp.Specification{}
    86  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    87  	c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, "# Allow Steam to set up \"pressure-vessel\" containers to run games in.\nmount\numount2\npivot_root\n")
    88  }
    89  
    90  func (s *SteamSupportInterfaceSuite) TestInterfaces(c *C) {
    91  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
    92  }