ifacetest

package
v0.0.0-...-04c4c42 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2021 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const HookYaml = `
name: foo
version: 1
developer: acme
hooks:
    configure:
plugs:
    plug:
        interface: iface
`
View Source
const PlugNoAppsYaml = `
name: foo
version: 1
developer: acme
plugs:
    plug:
        interface: iface
`
View Source
const SambaYamlV1 = `
name: samba
version: 1
developer: acme
apps:
    smbd:
slots:
    slot:
        interface: iface
`

Tests for Setup() and Remove()

View Source
const SambaYamlV1NoSlot = `
name: samba
version: 1
developer: acme
apps:
    smbd:
`
View Source
const SambaYamlV1WithNmbd = `
name: samba
version: 1
developer: acme
apps:
    smbd:
    nmbd:
slots:
    slot:
        interface: iface
`
View Source
const SambaYamlV1WithNmbdNoSlot = `
name: samba
version: 1
developer: acme
apps:
    smbd:
    nmbd:
`
View Source
const SambaYamlV2 = `
name: samba
version: 2
developer: acme
apps:
    smbd:
slots:
    slot:
        interface: iface
`
View Source
const SambaYamlWithHook = `` /* 178-byte string literal not displayed */
View Source
const SlotNoAppsYaml = `
name: foo
version: 1
developer: acme
slots:
    slots:
        interface: iface
`
View Source
const SomeSnapYamlV1 = `
name: some-snap
version: 1
developer: acme
apps:
    someapp:
`

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendSuite

type BackendSuite struct {
	Backend interfaces.SecurityBackend
	Repo    *interfaces.Repository
	Iface   *TestInterface
	RootDir string

	testutil.BaseTest
	// contains filtered or unexported fields
}

func (*BackendSuite) InstallSnap

func (s *BackendSuite) InstallSnap(c *C, opts interfaces.ConfinementOptions, instanceName, snapYaml string, revision int) *snap.Info

InstallSnap "installs" a snap from YAML.

func (*BackendSuite) RemoveSnap

func (s *BackendSuite) RemoveSnap(c *C, snapInfo *snap.Info)

RemoveSnap "removes" an "installed" snap.

func (*BackendSuite) SetUpTest

func (s *BackendSuite) SetUpTest(c *C)

func (*BackendSuite) TearDownTest

func (s *BackendSuite) TearDownTest(c *C)

func (*BackendSuite) UpdateSnap

func (s *BackendSuite) UpdateSnap(c *C, oldSnapInfo *snap.Info, opts interfaces.ConfinementOptions, snapYaml string, revision int) *snap.Info

UpdateSnap "updates" an existing snap from YAML.

type Specification

type Specification struct {
	Snippets []string
}

Specification is a specification intended for testing.

func (*Specification) AddConnectedPlug

func (spec *Specification) AddConnectedPlug(iface interfaces.Interface, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

AddConnectedPlug records test side-effects of having a connected plug.

func (*Specification) AddConnectedSlot

func (spec *Specification) AddConnectedSlot(iface interfaces.Interface, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

AddConnectedSlot records test side-effects of having a connected slot.

func (*Specification) AddPermanentPlug

func (spec *Specification) AddPermanentPlug(iface interfaces.Interface, plug *snap.PlugInfo) error

AddPermanentPlug records test side-effects of having a plug.

func (*Specification) AddPermanentSlot

func (spec *Specification) AddPermanentSlot(iface interfaces.Interface, slot *snap.SlotInfo) error

AddPermanentSlot records test side-effects of having a slot.

func (*Specification) AddSnippet

func (spec *Specification) AddSnippet(snippet string)

AddSnippet appends a snippet to a list stored in the specification.

type TestHotplugInterface

type TestHotplugInterface struct {
	TestInterface

	// Support for interacting with hotplug subsystem.
	HotplugKeyCallback            func(deviceInfo *hotplug.HotplugDeviceInfo) (snap.HotplugKey, error)
	HandledByGadgetCallback       func(deviceInfo *hotplug.HotplugDeviceInfo, slot *snap.SlotInfo) bool
	HotplugDeviceDetectedCallback func(deviceInfo *hotplug.HotplugDeviceInfo) (*hotplug.ProposedSlot, error)
}

TestHotplugInterface is an interface for various kinds of tests needing a hotplug-aware interface. It is public so that it can be consumed from other packages.

func (*TestHotplugInterface) HandledByGadget

func (t *TestHotplugInterface) HandledByGadget(deviceInfo *hotplug.HotplugDeviceInfo, slot *snap.SlotInfo) bool

func (*TestHotplugInterface) HotplugDeviceDetected

func (t *TestHotplugInterface) HotplugDeviceDetected(deviceInfo *hotplug.HotplugDeviceInfo) (*hotplug.ProposedSlot, error)

func (*TestHotplugInterface) HotplugKey

func (t *TestHotplugInterface) HotplugKey(deviceInfo *hotplug.HotplugDeviceInfo) (snap.HotplugKey, error)

type TestInterface

type TestInterface struct {
	// InterfaceName is the name of this interface
	InterfaceName       string
	InterfaceStaticInfo interfaces.StaticInfo
	// AutoConnectCallback is the callback invoked inside AutoConnect
	AutoConnectCallback func(*snap.PlugInfo, *snap.SlotInfo) bool
	// BeforePreparePlugCallback is the callback invoked inside BeforePreparePlug()
	BeforePreparePlugCallback func(plug *snap.PlugInfo) error
	// BeforePrepareSlotCallback is the callback invoked inside BeforePrepareSlot()
	BeforePrepareSlotCallback func(slot *snap.SlotInfo) error

	BeforeConnectPlugCallback func(plug *interfaces.ConnectedPlug) error
	BeforeConnectSlotCallback func(slot *interfaces.ConnectedSlot) error

	TestConnectedPlugCallback func(spec *Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	TestConnectedSlotCallback func(spec *Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	TestPermanentPlugCallback func(spec *Specification, plug *snap.PlugInfo) error
	TestPermanentSlotCallback func(spec *Specification, slot *snap.SlotInfo) error

	MountConnectedPlugCallback func(spec *mount.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	MountConnectedSlotCallback func(spec *mount.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	MountPermanentPlugCallback func(spec *mount.Specification, plug *snap.PlugInfo) error
	MountPermanentSlotCallback func(spec *mount.Specification, slot *snap.SlotInfo) error

	UDevConnectedPlugCallback func(spec *udev.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	UDevConnectedSlotCallback func(spec *udev.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	UDevPermanentPlugCallback func(spec *udev.Specification, plug *snap.PlugInfo) error
	UDevPermanentSlotCallback func(spec *udev.Specification, slot *snap.SlotInfo) error

	AppArmorConnectedPlugCallback func(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	AppArmorConnectedSlotCallback func(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	AppArmorPermanentPlugCallback func(spec *apparmor.Specification, plug *snap.PlugInfo) error
	AppArmorPermanentSlotCallback func(spec *apparmor.Specification, slot *snap.SlotInfo) error

	KModConnectedPlugCallback func(spec *kmod.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	KModConnectedSlotCallback func(spec *kmod.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	KModPermanentPlugCallback func(spec *kmod.Specification, plug *snap.PlugInfo) error
	KModPermanentSlotCallback func(spec *kmod.Specification, slot *snap.SlotInfo) error

	SecCompConnectedPlugCallback func(spec *seccomp.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	SecCompConnectedSlotCallback func(spec *seccomp.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	SecCompPermanentPlugCallback func(spec *seccomp.Specification, plug *snap.PlugInfo) error
	SecCompPermanentSlotCallback func(spec *seccomp.Specification, slot *snap.SlotInfo) error

	DBusConnectedPlugCallback func(spec *dbus.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	DBusConnectedSlotCallback func(spec *dbus.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	DBusPermanentPlugCallback func(spec *dbus.Specification, plug *snap.PlugInfo) error
	DBusPermanentSlotCallback func(spec *dbus.Specification, slot *snap.SlotInfo) error

	SystemdConnectedPlugCallback func(spec *systemd.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	SystemdConnectedSlotCallback func(spec *systemd.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error
	SystemdPermanentPlugCallback func(spec *systemd.Specification, plug *snap.PlugInfo) error
	SystemdPermanentSlotCallback func(spec *systemd.Specification, slot *snap.SlotInfo) error
}

TestInterface is a interface for various kind of tests. It is public so that it can be consumed from other packages.

func (*TestInterface) AppArmorConnectedPlug

func (t *TestInterface) AppArmorConnectedPlug(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) AppArmorConnectedSlot

func (t *TestInterface) AppArmorConnectedSlot(spec *apparmor.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) AppArmorPermanentPlug

func (t *TestInterface) AppArmorPermanentPlug(spec *apparmor.Specification, plug *snap.PlugInfo) error

func (*TestInterface) AppArmorPermanentSlot

func (t *TestInterface) AppArmorPermanentSlot(spec *apparmor.Specification, slot *snap.SlotInfo) error

func (*TestInterface) AutoConnect

func (t *TestInterface) AutoConnect(plug *snap.PlugInfo, slot *snap.SlotInfo) bool

AutoConnect returns whether plug and slot should be implicitly auto-connected assuming they will be an unambiguous connection candidate.

func (*TestInterface) BeforeConnectPlug

func (t *TestInterface) BeforeConnectPlug(plug *interfaces.ConnectedPlug) error

func (*TestInterface) BeforeConnectSlot

func (t *TestInterface) BeforeConnectSlot(slot *interfaces.ConnectedSlot) error

func (*TestInterface) BeforePreparePlug

func (t *TestInterface) BeforePreparePlug(plug *snap.PlugInfo) error

BeforePreparePlug checks and possibly modifies a plug.

func (*TestInterface) BeforePrepareSlot

func (t *TestInterface) BeforePrepareSlot(slot *snap.SlotInfo) error

BeforePrepareSlot checks and possibly modifies a slot.

func (*TestInterface) DBusConnectedPlug

func (t *TestInterface) DBusConnectedPlug(spec *dbus.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) DBusConnectedSlot

func (t *TestInterface) DBusConnectedSlot(spec *dbus.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) DBusPermanentPlug

func (t *TestInterface) DBusPermanentPlug(spec *dbus.Specification, plug *snap.PlugInfo) error

func (*TestInterface) DBusPermanentSlot

func (t *TestInterface) DBusPermanentSlot(spec *dbus.Specification, slot *snap.SlotInfo) error

func (*TestInterface) KModConnectedPlug

func (t *TestInterface) KModConnectedPlug(spec *kmod.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) KModConnectedSlot

func (t *TestInterface) KModConnectedSlot(spec *kmod.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) KModPermanentPlug

func (t *TestInterface) KModPermanentPlug(spec *kmod.Specification, plug *snap.PlugInfo) error

func (*TestInterface) KModPermanentSlot

func (t *TestInterface) KModPermanentSlot(spec *kmod.Specification, slot *snap.SlotInfo) error

func (*TestInterface) MountConnectedPlug

func (t *TestInterface) MountConnectedPlug(spec *mount.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) MountConnectedSlot

func (t *TestInterface) MountConnectedSlot(spec *mount.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) MountPermanentPlug

func (t *TestInterface) MountPermanentPlug(spec *mount.Specification, plug *snap.PlugInfo) error

func (*TestInterface) MountPermanentSlot

func (t *TestInterface) MountPermanentSlot(spec *mount.Specification, slot *snap.SlotInfo) error

func (*TestInterface) Name

func (t *TestInterface) Name() string

Name returns the name of the test interface.

func (*TestInterface) SecCompConnectedPlug

func (t *TestInterface) SecCompConnectedPlug(spec *seccomp.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) SecCompConnectedSlot

func (t *TestInterface) SecCompConnectedSlot(spec *seccomp.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) SecCompPermanentPlug

func (t *TestInterface) SecCompPermanentPlug(spec *seccomp.Specification, plug *snap.PlugInfo) error

func (*TestInterface) SecCompPermanentSlot

func (t *TestInterface) SecCompPermanentSlot(spec *seccomp.Specification, slot *snap.SlotInfo) error

func (*TestInterface) StaticInfo

func (t *TestInterface) StaticInfo() interfaces.StaticInfo

func (*TestInterface) String

func (t *TestInterface) String() string

String() returns the same value as Name().

func (*TestInterface) SystemdConnectedPlug

func (t *TestInterface) SystemdConnectedPlug(spec *systemd.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) SystemdConnectedSlot

func (t *TestInterface) SystemdConnectedSlot(spec *systemd.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) SystemdPermanentPlug

func (t *TestInterface) SystemdPermanentPlug(spec *systemd.Specification, plug *snap.PlugInfo) error

func (*TestInterface) SystemdPermanentSlot

func (t *TestInterface) SystemdPermanentSlot(spec *systemd.Specification, slot *snap.SlotInfo) error

func (*TestInterface) TestConnectedPlug

func (t *TestInterface) TestConnectedPlug(spec *Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) TestConnectedSlot

func (t *TestInterface) TestConnectedSlot(spec *Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) TestPermanentPlug

func (t *TestInterface) TestPermanentPlug(spec *Specification, plug *snap.PlugInfo) error

func (*TestInterface) TestPermanentSlot

func (t *TestInterface) TestPermanentSlot(spec *Specification, slot *snap.SlotInfo) error

func (*TestInterface) UDevConnectedPlug

func (t *TestInterface) UDevConnectedPlug(spec *udev.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) UDevConnectedSlot

func (t *TestInterface) UDevConnectedSlot(spec *udev.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error

func (*TestInterface) UDevPermanentPlug

func (t *TestInterface) UDevPermanentPlug(spec *udev.Specification, plug *snap.PlugInfo) error

func (*TestInterface) UDevPermanentSlot

func (t *TestInterface) UDevPermanentSlot(spec *udev.Specification, slot *snap.SlotInfo) error

type TestSecurityBackend

type TestSecurityBackend struct {
	BackendName interfaces.SecuritySystem
	// SetupCalls stores information about all calls to Setup
	SetupCalls []TestSetupCall
	// RemoveCalls stores information about all calls to Remove
	RemoveCalls []string
	// SetupCallback is an callback that is optionally called in Setup
	SetupCallback func(snapInfo *snap.Info, opts interfaces.ConfinementOptions, repo *interfaces.Repository) error
	// RemoveCallback is a callback that is optionally called in Remove
	RemoveCallback func(snapName string) error
	// SandboxFeaturesCallback is a callback that is optionally called in SandboxFeatures
	SandboxFeaturesCallback func() []string
}

TestSecurityBackend is a security backend intended for testing.

func (*TestSecurityBackend) Initialize

Initialize does nothing.

func (*TestSecurityBackend) Name

Name returns the name of the security backend.

func (*TestSecurityBackend) NewSpecification

func (b *TestSecurityBackend) NewSpecification() interfaces.Specification

func (*TestSecurityBackend) Remove

func (b *TestSecurityBackend) Remove(snapName string) error

Remove records information about the call and calls the remove callback if one is defined

func (*TestSecurityBackend) SandboxFeatures

func (b *TestSecurityBackend) SandboxFeatures() []string

func (*TestSecurityBackend) Setup

Setup records information about the call and calls the setup callback if one is defined.

type TestSecurityBackendDiscardingLate

type TestSecurityBackendDiscardingLate struct {
	TestSecurityBackend

	RemoveLateCalledFor [][]string
	RemoveLateCallback  func(snapName string, rev snap.Revision, typ snap.Type) error
}

TestSecurityBackendDiscardingLate implements RemoveLate on top of TestSecurityBackend.

func (*TestSecurityBackendDiscardingLate) RemoveLate

func (b *TestSecurityBackendDiscardingLate) RemoveLate(snapName string, rev snap.Revision, typ snap.Type) error

type TestSecurityBackendSetupMany

type TestSecurityBackendSetupMany struct {
	TestSecurityBackend

	// SetupManyCalls stores information about all calls to Setup
	SetupManyCalls []TestSetupManyCall

	// SetupManyCallback is an callback that is optionally called in Setup
	SetupManyCallback func(snapInfo []*snap.Info, confinement func(snapName string) interfaces.ConfinementOptions, repo *interfaces.Repository, tm timings.Measurer) []error
}

TestSecurityBackendSetupMany is a security backend that implements SetupMany on top of TestSecurityBackend.

func (*TestSecurityBackendSetupMany) SetupMany

func (b *TestSecurityBackendSetupMany) SetupMany(snaps []*snap.Info, confinement func(snapName string) interfaces.ConfinementOptions, repo *interfaces.Repository, tm timings.Measurer) []error

type TestSetupCall

type TestSetupCall struct {
	// SnapInfo is a copy of the snapInfo argument to a particular call to Setup
	SnapInfo *snap.Info
	// Options is a copy of the confinement options to a particular call to Setup
	Options interfaces.ConfinementOptions
}

TestSetupCall stores details about calls to TestSecurityBackend.Setup

type TestSetupManyCall

type TestSetupManyCall struct {
	// SnapInfos is a copy of the snapInfo arguments to a particular call to SetupMany
	SnapInfos []*snap.Info
}

TestSetupManyCall stores details about calls to TestSecurityBackendMany.SetupMany

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL