Exemplo n.º 1
0
func (s *registrySuite) TestRegisterAndList(c *gc.C) {
	r := registry.NewTypedNameVersion(factoryType)
	c.Assert(r.Register("name", 0, nilFactory), gc.IsNil)
	c.Check(r.List(), gc.DeepEquals, []registry.Description{
		{Name: "name", Versions: []int{0}},
	})
}
Exemplo n.º 2
0
func (s *registrySuite) TestGetUnknown(c *gc.C) {
	r := registry.NewTypedNameVersion(factoryType)
	f, err := r.Get("name", 0)
	c.Check(err, jc.Satisfies, errors.IsNotFound)
	c.Check(err, gc.ErrorMatches, `name\(0\) not found`)
	c.Check(f, gc.IsNil)
}
Exemplo n.º 3
0
func (s *registrySuite) TestGetUnknownVersion(c *gc.C) {
	r := registry.NewTypedNameVersion(factoryType)
	c.Assert(r.Register("name", 0, nilFactory), gc.IsNil)
	f, err := r.Get("name", 1)
	c.Check(err, jc.Satisfies, errors.IsNotFound)
	c.Check(err, gc.ErrorMatches, `name\(1\) not found`)
	c.Check(f, gc.IsNil)
}
Exemplo n.º 4
0
func (s *registrySuite) TestGet(c *gc.C) {
	r := registry.NewTypedNameVersion(factoryType)
	customFactory := func() (interface{}, error) {
		return 10, nil
	}
	c.Assert(r.Register("name", 0, customFactory), gc.IsNil)
	f, err := r.Get("name", 0)
	c.Assert(err, gc.IsNil)
	c.Assert(f, gc.NotNil)
	res, err := f.(Factory)()
	c.Assert(err, gc.IsNil)
	c.Check(res, gc.Equals, 10)
}
Exemplo n.º 5
0
func (s *registrySuite) TestRegisterAlreadyPresent(c *gc.C) {
	r := registry.NewTypedNameVersion(factoryType)
	err := r.Register("name", 0, func() (interface{}, error) {
		return "orig", nil
	})
	c.Assert(err, gc.IsNil)
	err = r.Register("name", 0, func() (interface{}, error) {
		return "broken", nil
	})
	c.Check(err, gc.ErrorMatches, `object "name\(0\)" already registered`)
	f, err := r.Get("name", 0)
	c.Assert(err, gc.IsNil)
	val, err := f.(Factory)()
	c.Assert(err, gc.IsNil)
	c.Check(val, gc.Equals, "orig")
}
Exemplo n.º 6
0
func (s *registrySuite) TestRegisterWrongType(c *gc.C) {
	r := registry.NewTypedNameVersion(factoryType)
	err := r.Register("other", 0, "notAFactory")
	c.Check(err, gc.ErrorMatches, `object of type string cannot be converted to type .*registry_test.Factory`)
}