Esempio n. 1
0
// FindSnapsByName returns all snaps with the given name in the "haystack"
// slice of snaps (useful for filtering)
func FindSnapsByName(needle string, haystack []*Snap) (res []*Snap) {
	name, developer := SplitDeveloper(needle)
	ignorens := developer == ""

	for _, snap := range haystack {
		if snap.Name() == name && (ignorens || snap.Developer() == developer) {
			res = append(res, snap)
		}
	}

	return res
}
Esempio n. 2
0
// FindSnapsByNameAndRevision returns the snaps with the name/version in the
// given slice of snaps
func FindSnapsByNameAndRevision(needle string, revision int, haystack []*Snap) []*Snap {
	name, developer := SplitDeveloper(needle)
	ignorens := developer == ""
	var found []*Snap

	for _, snap := range haystack {
		if snap.Name() == name && snap.Revision() == revision && (ignorens || snap.Developer() == developer) {
			found = append(found, snap)
		}
	}

	return found
}
Esempio n. 3
0
func (s *SnapTestSuite) TestServicesWithPorts(c *C) {
	const packageHello = `name: hello-snap
version: 1.10
apps:
 hello:
  command: bin/hello
 svc1:
   command: svc1
   type: forking
   description: "Service #1"
   ports:
      external:
        ui:
          port: 8080/tcp
        nothing:
          port: 8081/tcp
          negotiable: yes
 svc2:
   command: svc2
   type: forking
   description: "Service #2"
`

	yamlFile, err := makeInstalledMockSnap(packageHello, 11)
	c.Assert(err, IsNil)

	snap, err := NewInstalledSnap(yamlFile)
	c.Assert(err, IsNil)
	c.Assert(snap, NotNil)

	c.Assert(snap.Name(), Equals, "hello-snap")
	c.Assert(snap.Developer(), Equals, testDeveloper)
	c.Assert(snap.Version(), Equals, "1.10")
	c.Assert(snap.IsActive(), Equals, false)

	apps := snap.Info().Apps
	c.Assert(apps, HasLen, 3)

	c.Assert(apps["svc1"].Name, Equals, "svc1")

	c.Assert(apps["svc2"].Name, Equals, "svc2")
}