func (s *StateSuite) TestAddService(c *C) { charm := s.AddTestingCharm(c, "dummy") _, err := s.State.AddService("haha/borken", charm) c.Assert(err, ErrorMatches, `"haha/borken" is not a valid service name`) _, err = s.State.Service("haha/borken") c.Assert(err, ErrorMatches, `"haha/borken" is not a valid service name`) wordpress, err := s.State.AddService("wordpress", charm) c.Assert(err, IsNil) c.Assert(wordpress.Name(), Equals, "wordpress") mysql, err := s.State.AddService("mysql", charm) c.Assert(err, IsNil) c.Assert(mysql.Name(), Equals, "mysql") // Check that retrieving the new created services works correctly. wordpress, err = s.State.Service("wordpress") c.Assert(err, IsNil) c.Assert(wordpress.Name(), Equals, "wordpress") ch, _, err := wordpress.Charm() c.Assert(err, IsNil) c.Assert(ch.URL(), DeepEquals, charm.URL()) mysql, err = s.State.Service("mysql") c.Assert(err, IsNil) c.Assert(mysql.Name(), Equals, "mysql") ch, _, err = mysql.Charm() c.Assert(err, IsNil) c.Assert(ch.URL(), DeepEquals, charm.URL()) }
func (s *clientSuite) TestClientServiceDeployPrincipal(c *C) { // TODO(fwereade): test ToMachineSpec directly on srvClient, when we // manage to extract it as a package and can thus do it conveniently. store, restore := makeMockCharmStore() defer restore() curl, bundle := addCharm(c, store, "dummy") mem4g := constraints.MustParse("mem=4G") err := s.APIState.Client().ServiceDeploy( curl.String(), "service", 3, "", mem4g, ) c.Assert(err, IsNil) service, err := s.State.Service("service") c.Assert(err, IsNil) charm, force, err := service.Charm() c.Assert(err, IsNil) c.Assert(force, Equals, false) c.Assert(charm.URL(), DeepEquals, curl) c.Assert(charm.Meta(), DeepEquals, bundle.Meta()) c.Assert(charm.Config(), DeepEquals, bundle.Config()) cons, err := service.Constraints() c.Assert(err, IsNil) c.Assert(cons, DeepEquals, mem4g) units, err := service.AllUnits() c.Assert(err, IsNil) for _, unit := range units { mid, err := unit.AssignedMachineId() c.Assert(err, IsNil) machine, err := s.State.Machine(mid) c.Assert(err, IsNil) cons, err := machine.Constraints() c.Assert(err, IsNil) c.Assert(cons, DeepEquals, mem4g) } }
func (s *clientSuite) TestClientServiceDeploySubordinate(c *C) { store, restore := makeMockCharmStore() defer restore() curl, bundle := addCharm(c, store, "logging") err := s.APIState.Client().ServiceDeploy( curl.String(), "service-name", 0, "", constraints.Value{}, ) service, err := s.State.Service("service-name") c.Assert(err, IsNil) charm, force, err := service.Charm() c.Assert(err, IsNil) c.Assert(force, Equals, false) c.Assert(charm.URL(), DeepEquals, curl) c.Assert(charm.Meta(), DeepEquals, bundle.Meta()) c.Assert(charm.Config(), DeepEquals, bundle.Config()) units, err := service.AllUnits() c.Assert(err, IsNil) c.Assert(units, HasLen, 0) }
func (s *clientSuite) TestClientCharmInfo(c *C) { // Use wordpress for tests so that we can compare Provides and Requires. charm := s.AddTestingCharm(c, "wordpress") for i, t := range clientCharmInfoTests { c.Logf("test %d. %s", i, t.about) info, err := s.APIState.Client().CharmInfo(t.url) if t.err != "" { c.Assert(err, ErrorMatches, t.err) continue } c.Assert(err, IsNil) expected := &api.CharmInfo{ Revision: charm.Revision(), URL: charm.URL().String(), Config: charm.Config(), Meta: charm.Meta(), } c.Assert(info, DeepEquals, expected) } }
func (s *clientSuite) TestClientServiceSetCharmForce(c *C) { store, restore := makeMockCharmStore() defer restore() curl, _ := addCharm(c, store, "dummy") err := s.APIState.Client().ServiceDeploy( curl.String(), "service", 3, "", constraints.Value{}, ) c.Assert(err, IsNil) addCharm(c, store, "wordpress") err = s.APIState.Client().ServiceSetCharm( "service", "cs:precise/wordpress-3", true, ) c.Assert(err, IsNil) // Ensure that the charm is marked as forced. service, err := s.State.Service("service") c.Assert(err, IsNil) charm, force, err := service.Charm() c.Assert(err, IsNil) c.Assert(charm.URL().String(), Equals, "cs:precise/wordpress-3") c.Assert(force, Equals, true) }