func (s *facadeRegistrySuite) TestRegisterStandardFacade(c *gc.C) { common.SanitizeFacades(s) common.RegisterStandardFacade("testing", 0, validFactory) wrapped, err := common.Facades.GetFactory("testing", 0) c.Assert(err, gc.IsNil) val, err := wrapped(nil, nil, nil, "") c.Assert(err, gc.IsNil) c.Check(*(val.(*int)), gc.Equals, 100) }
func (s *facadeRegistrySuite) TestRegister(c *gc.C) { common.SanitizeFacades(s) var v interface{} common.RegisterFacade("myfacade", 0, testFacade, reflect.TypeOf(&v).Elem()) f, err := common.Facades.GetFactory("myfacade", 0) c.Assert(err, gc.IsNil) val, err := f(nil, nil, nil, "") c.Assert(err, gc.IsNil) c.Check(val, gc.Equals, "myobject") }
func (s *facadeRegistrySuite) TestRegisterStandardFacadePanic(c *gc.C) { common.SanitizeFacades(s) c.Assert( func() { common.RegisterStandardFacade("badtest", 0, noArgs) }, gc.PanicMatches, `function ".*noArgs" does not take 3 parameters and return 2`) _, err := common.Facades.GetFactory("badtest", 0) c.Assert(err, jc.Satisfies, errors.IsNotFound) c.Assert(err, gc.ErrorMatches, `badtest\(0\) not found`) }
func (s *facadeRegistrySuite) TestRegisterForFeature(c *gc.C) { common.SanitizeFacades(s) var v interface{} common.RegisterFacadeForFeature("myfacade", 0, testFacade, reflect.TypeOf(&v).Elem(), "magic") f, err := common.Facades.GetFactory("myfacade", 0) c.Check(err, jc.Satisfies, errors.IsNotFound) s.SetFeatureFlags("magic") f, err = common.Facades.GetFactory("myfacade", 0) c.Assert(err, jc.ErrorIsNil) val, err := f(nil) c.Assert(err, jc.ErrorIsNil) c.Check(val, gc.Equals, "myobject") }