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

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016-2017 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  	"fmt"
    24  
    25  	. "gopkg.in/check.v1"
    26  
    27  	"gitee.com/mysnapcore/mysnapd/dirs"
    28  	"gitee.com/mysnapcore/mysnapd/interfaces"
    29  	"gitee.com/mysnapcore/mysnapd/interfaces/apparmor"
    30  	"gitee.com/mysnapcore/mysnapd/interfaces/builtin"
    31  	"gitee.com/mysnapcore/mysnapd/interfaces/kmod"
    32  	"gitee.com/mysnapcore/mysnapd/interfaces/udev"
    33  	"gitee.com/mysnapcore/mysnapd/snap"
    34  	"gitee.com/mysnapcore/mysnapd/testutil"
    35  )
    36  
    37  type PppInterfaceSuite struct {
    38  	iface    interfaces.Interface
    39  	slotInfo *snap.SlotInfo
    40  	slot     *interfaces.ConnectedSlot
    41  	plugInfo *snap.PlugInfo
    42  	plug     *interfaces.ConnectedPlug
    43  }
    44  
    45  var _ = Suite(&PppInterfaceSuite{
    46  	iface: builtin.MustInterface("ppp"),
    47  })
    48  
    49  const pppConsumerYaml = `name: consumer
    50  version: 0
    51  apps:
    52   app:
    53    plugs: [ppp]
    54  `
    55  
    56  const pppCoreYaml = `name: core
    57  version: 0
    58  type: os
    59  slots:
    60    ppp:
    61  `
    62  
    63  func (s *PppInterfaceSuite) SetUpTest(c *C) {
    64  	s.plug, s.plugInfo = MockConnectedPlug(c, pppConsumerYaml, nil, "ppp")
    65  	s.slot, s.slotInfo = MockConnectedSlot(c, pppCoreYaml, nil, "ppp")
    66  }
    67  
    68  func (s *PppInterfaceSuite) TestName(c *C) {
    69  	c.Assert(s.iface.Name(), Equals, "ppp")
    70  }
    71  
    72  func (s *PppInterfaceSuite) TestSanitizeSlot(c *C) {
    73  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
    74  }
    75  
    76  func (s *PppInterfaceSuite) TestSanitizePlug(c *C) {
    77  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    78  }
    79  
    80  func (s *PppInterfaceSuite) TestAppArmorSpec(c *C) {
    81  	spec := &apparmor.Specification{}
    82  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    83  	c.Assert(spec.SecurityTags(), DeepEquals, []string{"snap.consumer.app"})
    84  	c.Assert(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `/dev/ppp rw,`)
    85  }
    86  
    87  func (s *PppInterfaceSuite) TestKModSpec(c *C) {
    88  	spec := &kmod.Specification{}
    89  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    90  	c.Assert(spec.Modules(), DeepEquals, map[string]bool{
    91  		"ppp_generic": true,
    92  	})
    93  }
    94  
    95  func (s *PppInterfaceSuite) TestUDevSpec(c *C) {
    96  	spec := &udev.Specification{}
    97  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    98  	c.Assert(spec.Snippets(), HasLen, 3)
    99  	c.Assert(spec.Snippets(), testutil.Contains, `# ppp
   100  KERNEL=="ppp", TAG+="snap_consumer_app"`)
   101  	c.Assert(spec.Snippets(), testutil.Contains, fmt.Sprintf(`TAG=="snap_consumer_app", RUN+="%v/snap-device-helper $env{ACTION} snap_consumer_app $devpath $major:$minor"`, dirs.DistroLibExecDir))
   102  }
   103  
   104  func (s *PppInterfaceSuite) TestStaticInfo(c *C) {
   105  	si := interfaces.StaticInfoOf(s.iface)
   106  	c.Assert(si.ImplicitOnCore, Equals, true)
   107  	c.Assert(si.ImplicitOnClassic, Equals, true)
   108  	c.Assert(si.Summary, Equals, `allows operating as the ppp service`)
   109  	c.Assert(si.BaseDeclarationSlots, testutil.Contains, "ppp")
   110  }
   111  
   112  func (s *PppInterfaceSuite) TestAutoConnect(c *C) {
   113  	c.Assert(s.iface.AutoConnect(s.plugInfo, s.slotInfo), Equals, true)
   114  }
   115  
   116  func (s *PppInterfaceSuite) TestInterfaces(c *C) {
   117  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
   118  }