Skip to content

Commit

Permalink
i/ifacetest: add functions for mocking connected plugs/slots from sna…
Browse files Browse the repository at this point in the history
…ps with components
  • Loading branch information
andrewphelpsj committed Apr 2, 2024
1 parent 85daedf commit b137c92
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions interfaces/ifacetest/app_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ func MockConnectedSlot(c *check.C, yaml string, si *snap.SideInfo, slotName stri
return MockConnectedSlotWithAttrs(c, yaml, si, slotName, nil, nil)
}

func MockConnectedSlotWithComponents(c *check.C, yaml string, si *snap.SideInfo, compYamls []string, slotName string) (*interfaces.ConnectedSlot, *snap.SlotInfo) {
set := MockInfoAndAppSet(c, yaml, compYamls, si)
info := set.Info()

slotInfo, ok := info.Slots[slotName]
if !ok {
c.Fatalf("cannot find slot %q in snap %q", slotName, info.InstanceName())
}

return interfaces.NewConnectedSlot(slotInfo, set, nil, nil), slotInfo
}

func MockConnectedPlugWithComponents(c *check.C, yaml string, si *snap.SideInfo, compYamls []string, plugName string) (*interfaces.ConnectedPlug, *snap.PlugInfo) {
set := MockInfoAndAppSet(c, yaml, compYamls, si)
info := set.Info()

plugInfo, ok := info.Plugs[plugName]
if !ok {
c.Fatalf("cannot find plug %q in snap %q", plugName, info.InstanceName())
}

return interfaces.NewConnectedPlug(plugInfo, set, nil, nil), plugInfo
}

func MockConnectedSlotWithAttrs(c *check.C, yaml string, si *snap.SideInfo, slotName string, staticAttrs, dynamicAttrs map[string]interface{}) (*interfaces.ConnectedSlot, *snap.SlotInfo) {
info := snaptest.MockInfo(c, yaml, si)

Expand Down

0 comments on commit b137c92

Please sign in to comment.