コード例 #1
0
func parseCapabilityMap(m jsonData) ([]*app.Capability, error) {
	ret := make([]*app.Capability, 0)
	for k, v := range m {
		switch vv := v.(type) {
		case string:
			ver, err := semver.NewVersion(vv)
			if err != nil {
				return nil, fmt.Errorf("Capability %s has invalid version", k)
			}
			cpb := new(app.Capability)
			cpb.Version = *ver
			cpb.Name = k
			ret = append(ret, cpb)
		default:
			return nil, fmt.Errorf("Capability %s has invalid version", k)
		}
	}
	return ret, nil
}
コード例 #2
0
func getMockApp() *app.App {
	// construct a new app
	a := new(app.App)
	a.Manifest = new(app.Manifest)
	a.Manifest.Name = "name1"
	a.Manifest.InstanceId = "instance1"

	// construct capabilities
	caps := make([]*app.Capability, 2)
	cap1 := new(app.Capability)
	v1, _ := semver.NewVersion("1.1.1")
	v2, _ := semver.NewVersion("1.1.2")
	cap1.Version = *v1
	cap1.Name = "capability1"
	caps[0] = cap1
	cap2 := new(app.Capability)
	cap2.Version = *v2
	cap2.Name = "capability2"
	caps[1] = cap2
	a.Manifest.Capabilities = caps

	// construct dependencies
	deps := make([]*app.Capability, 2)
	dep1 := new(app.Capability)
	dep1.Version = *v1
	dep1.Name = "dependency1"
	deps[0] = dep1
	dep2 := new(app.Capability)
	dep2.Version = *v2
	dep2.Name = "dependency2"
	deps[1] = dep2

	a.Manifest.Dependencies = deps

	return a
}