コード例 #1
0
ファイル: endpoint_bindings_test.go プロジェクト: OSBI/juju
func (s *BindingsSuite) TestCombinedCharmRelations(c *gc.C) {
	_, err := state.CombinedCharmRelations(nil)
	c.Check(err, gc.ErrorMatches, "nil charm metadata")

	meta := s.newMeta
	allRelations, err := state.CombinedCharmRelations(meta)
	c.Check(err, jc.ErrorIsNil)
	combinedLength := len(meta.Provides) + len(meta.Requires) + len(meta.Peers)
	c.Check(allRelations, gc.HasLen, combinedLength)
	c.Check(allRelations, jc.DeepEquals, map[string]charm.Relation{
		"foo1": meta.Provides["foo1"],
		"foo2": meta.Provides["foo2"],
		"bar2": meta.Requires["bar2"],
		"bar3": meta.Requires["bar3"],
		"self": meta.Peers["self"],
		"me":   meta.Peers["me"],
	})
}
コード例 #2
0
ファイル: deploy.go プロジェクト: OSBI/juju
func getEffectiveBindingsForCharmMeta(charmMeta *charm.Meta, givenBindings map[string]string) (map[string]string, error) {
	combinedEndpoints, err := state.CombinedCharmRelations(charmMeta)
	if err != nil {
		return nil, errors.Trace(err)
	}
	if givenBindings == nil {
		givenBindings = make(map[string]string, len(combinedEndpoints))
	}

	// Get the service-level default binding for all unspecified endpoint, if
	// set, otherwise use the empty default.
	serviceDefaultSpace, _ := givenBindings[""]

	effectiveBindings := make(map[string]string, len(combinedEndpoints))
	for endpoint, _ := range combinedEndpoints {
		if givenSpace, isGiven := givenBindings[endpoint]; isGiven {
			effectiveBindings[endpoint] = givenSpace
		} else {
			effectiveBindings[endpoint] = serviceDefaultSpace
		}
	}
	return effectiveBindings, nil
}