github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/interfaces/builtin/contacts_service_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2018 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/release"
    29  	"github.com/snapcore/snapd/snap"
    30  	"github.com/snapcore/snapd/testutil"
    31  )
    32  
    33  type ContactsServiceInterfaceSuite struct {
    34  	iface    interfaces.Interface
    35  	slot     *interfaces.ConnectedSlot
    36  	slotInfo *snap.SlotInfo
    37  	plug     *interfaces.ConnectedPlug
    38  	plugInfo *snap.PlugInfo
    39  }
    40  
    41  var _ = Suite(&ContactsServiceInterfaceSuite{
    42  	iface: builtin.MustInterface("contacts-service"),
    43  })
    44  
    45  func (s *ContactsServiceInterfaceSuite) SetUpTest(c *C) {
    46  	const coreYaml = `name: core
    47  version: 0
    48  type: os
    49  slots:
    50   contacts-service:
    51    interface: contacts-service
    52  `
    53  	s.slot, s.slotInfo = MockConnectedSlot(c, coreYaml, nil, "contacts-service")
    54  
    55  	var consumerYaml = `name: consumer
    56  version: 0
    57  apps:
    58   app:
    59    plugs: [contacts-service]
    60  `
    61  	s.plug, s.plugInfo = MockConnectedPlug(c, consumerYaml, nil, "contacts-service")
    62  }
    63  
    64  func (s *ContactsServiceInterfaceSuite) TestName(c *C) {
    65  	c.Assert(s.iface.Name(), Equals, "contacts-service")
    66  }
    67  
    68  func (s *ContactsServiceInterfaceSuite) TestSanitize(c *C) {
    69  	c.Assert(interfaces.BeforePreparePlug(s.iface, s.plugInfo), IsNil)
    70  	c.Assert(interfaces.BeforePrepareSlot(s.iface, s.slotInfo), IsNil)
    71  }
    72  
    73  func (s *ContactsServiceInterfaceSuite) TestAppArmorConnectedPlug(c *C) {
    74  	spec := &apparmor.Specification{}
    75  	c.Assert(spec.AddConnectedPlug(s.iface, s.plug, s.slot), IsNil)
    76  	c.Assert(spec.SecurityTags(), HasLen, 1)
    77  	c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `interface=org.gnome.evolution.dataserver.Source`)
    78  	c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `interface=org.gnome.evolution.dataserver.AddressBook`)
    79  	c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `interface=org.gnome.evolution.dataserver.AddressBookFactory`)
    80  	c.Check(spec.SnippetForTag("snap.consumer.app"), testutil.Contains, `interface=org.gnome.evolution.dataserver.AddressBookView`)
    81  }
    82  
    83  func (s *ContactsServiceInterfaceSuite) TestStaticInfo(c *C) {
    84  	si := interfaces.StaticInfoOf(s.iface)
    85  	c.Check(si.ImplicitOnCore, Equals, false)
    86  	c.Check(si.ImplicitOnClassic, Equals, !(release.ReleaseInfo.ID == "ubuntu" && release.ReleaseInfo.VersionID == "14.04"))
    87  	c.Check(si.Summary, Equals, "allows communication with Evolution Data Service Address Book")
    88  	c.Check(si.BaseDeclarationSlots, testutil.Contains, "contacts-service")
    89  }
    90  
    91  func (s *ContactsServiceInterfaceSuite) TestInterfaces(c *C) {
    92  	c.Check(builtin.Interfaces(), testutil.DeepContains, s.iface)
    93  }