當前位置: 首頁>>代碼示例>>Golang>>正文


Golang params.ErrCode函數代碼示例

本文整理匯總了Golang中launchpad/net/juju-core/state/api/params.ErrCode函數的典型用法代碼示例。如果您正苦於以下問題:Golang ErrCode函數的具體用法?Golang ErrCode怎麽用?Golang ErrCode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ErrCode函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestUnitRemove

func (s *deployerSuite) TestUnitRemove(c *gc.C) {
	unit, err := s.st.Unit(s.principal.Tag())
	c.Assert(err, gc.IsNil)

	// It fails because the entity is still alive.
	// And EnsureDead will fail because there is a subordinate.
	err = unit.Remove()
	c.Assert(err, gc.ErrorMatches, `cannot remove entity "unit-mysql-0": still alive`)
	c.Assert(params.ErrCode(err), gc.Equals, "")

	// With the subordinate it also fails due to it being alive.
	unit, err = s.st.Unit(s.subordinate.Tag())
	c.Assert(err, gc.IsNil)
	err = unit.Remove()
	c.Assert(err, gc.ErrorMatches, `cannot remove entity "unit-logging-0": still alive`)
	c.Assert(params.ErrCode(err), gc.Equals, "")

	// Make it dead first and try again.
	err = s.subordinate.EnsureDead()
	c.Assert(err, gc.IsNil)
	err = unit.Remove()
	c.Assert(err, gc.IsNil)

	// Verify it's gone.
	err = unit.Refresh()
	s.assertUnauthorized(c, err)
	unit, err = s.st.Unit(s.subordinate.Tag())
	s.assertUnauthorized(c, err)
	c.Assert(unit, gc.IsNil)
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:30,代碼來源:deployer_test.go

示例2: TestEnsureDead

func (s *uniterSuite) TestEnsureDead(c *gc.C) {
	c.Assert(s.unit.Life(), gc.Equals, state.Alive)

	unit, err := s.uniter.Unit("unit-wordpress-0")
	c.Assert(err, gc.IsNil)

	err = unit.EnsureDead()
	c.Assert(err, gc.IsNil)

	err = s.unit.Refresh()
	c.Assert(err, gc.IsNil)
	c.Assert(s.unit.Life(), gc.Equals, state.Dead)

	err = unit.EnsureDead()
	c.Assert(err, gc.IsNil)
	err = s.unit.Refresh()
	c.Assert(err, gc.IsNil)
	c.Assert(s.unit.Life(), gc.Equals, state.Dead)

	err = s.unit.Remove()
	c.Assert(err, gc.IsNil)
	err = s.unit.Refresh()
	c.Assert(err, jc.Satisfies, errors.IsNotFoundError)

	err = unit.EnsureDead()
	c.Assert(err, gc.ErrorMatches, `unit "wordpress/0" not found`)
	c.Assert(params.ErrCode(err), gc.Equals, params.CodeNotFound)
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:28,代碼來源:uniter_test.go

示例3: opClientDestroyRelation

func opClientDestroyRelation(c *C, st *api.State, mst *state.State) (func(), error) {
	err := st.Client().DestroyRelation("nosuch1", "nosuch2")
	if params.ErrCode(err) == params.CodeNotFound {
		err = nil
	}
	return func() {}, err
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:7,代碼來源:perm_test.go

示例4: opClientServiceSetCharm

func opClientServiceSetCharm(c *C, st *api.State, mst *state.State) (func(), error) {
	err := st.Client().ServiceSetCharm("nosuch", "local:series/wordpress", false)
	if params.ErrCode(err) == params.CodeNotFound {
		err = nil
	}
	return func() {}, err
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:7,代碼來源:perm_test.go

示例5: TestSetToolsWrongMachine

func (s *upgraderSuite) TestSetToolsWrongMachine(c *C) {
	err := s.st.SetTools("42", &tools.Tools{
		Version: version.Current,
	})
	c.Assert(err, ErrorMatches, "permission denied")
	c.Assert(params.ErrCode(err), Equals, params.CodeUnauthorized)
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:7,代碼來源:upgrader_test.go

示例6: opClientAddServiceUnits

func opClientAddServiceUnits(c *C, st *api.State, mst *state.State) (func(), error) {
	_, err := st.Client().AddServiceUnits("nosuch", 1)
	if params.ErrCode(err) == params.CodeNotFound {
		err = nil
	}
	return func() {}, err
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:7,代碼來源:perm_test.go

示例7: opClientServiceDestroy

func opClientServiceDestroy(c *C, st *api.State, mst *state.State) (func(), error) {
	err := st.Client().ServiceDestroy("non-existent")
	if params.ErrCode(err) == params.CodeNotFound {
		err = nil
	}
	return func() {}, err
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:7,代碼來源:perm_test.go

示例8: OpenAPI

// OpenAPI tries to open the state using the given Conf.  If it
// returns a non-empty newPassword, the password used to connect
// to the state should be changed accordingly - the caller should write the
// configuration with StateInfo.Password set to newPassword, then
// set the entity's password accordingly.
func (c *Conf) OpenAPI(dialOpts api.DialOpts) (st *api.State, newPassword string, err error) {
	info := *c.APIInfo
	info.Nonce = c.MachineNonce
	if info.Password != "" {
		st, err := api.Open(&info, dialOpts)
		if err == nil {
			return st, "", nil
		}
		if params.ErrCode(err) != params.CodeUnauthorized {
			return nil, "", err
		}
		// Access isn't authorized even though we have a password
		// This can happen if we crash after saving the
		// password but before changing it, so we'll try again
		// with the old password.
	}
	info.Password = c.OldPassword
	st, err = api.Open(&info, dialOpts)
	if err != nil {
		return nil, "", err
	}
	// We've succeeded in connecting with the old password, so
	// we can now change it to something more private.
	password, err := utils.RandomPassword()
	if err != nil {
		st.Close()
		return nil, "", err
	}
	return st, password, nil
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:35,代碼來源:agent.go

示例9: TestEnsureDead

func (s *machinerSuite) TestEnsureDead(c *C) {
	c.Assert(s.machine.Life(), Equals, state.Alive)

	machine, err := s.st.Machiner().Machine("machine-0")
	c.Assert(err, IsNil)

	err = machine.EnsureDead()
	c.Assert(err, IsNil)

	err = s.machine.Refresh()
	c.Assert(err, IsNil)
	c.Assert(s.machine.Life(), Equals, state.Dead)

	err = machine.EnsureDead()
	c.Assert(err, IsNil)
	err = s.machine.Refresh()
	c.Assert(err, IsNil)
	c.Assert(s.machine.Life(), Equals, state.Dead)

	err = s.machine.Remove()
	c.Assert(err, IsNil)
	err = s.machine.Refresh()
	c.Assert(err, checkers.Satisfies, errors.IsNotFoundError)

	err = machine.EnsureDead()
	c.Assert(err, ErrorMatches, "machine 0 not found")
	c.Assert(params.ErrCode(err), Equals, params.CodeNotFound)
}
開發者ID:CSRedRat,項目名稱:juju-core,代碼行數:28,代碼來源:machiner_test.go

示例10: isFatal

func isFatal(err error) bool {
	isTerminate := err == worker.ErrTerminateAgent
	notProvisioned := params.ErrCode(err) == params.CodeNotProvisioned
	if isTerminate || notProvisioned || isUpgraded(err) {
		return true
	}
	_, ok := err.(*fatalError)
	return ok
}
開發者ID:CSRedRat,項目名稱:juju-core,代碼行數:9,代碼來源:agent.go

示例11: TestMachineAndMachineTag

func (s *machinerSuite) TestMachineAndMachineTag(c *gc.C) {
	machine, err := s.machiner.Machine("machine-42")
	c.Assert(err, gc.ErrorMatches, "permission denied")
	c.Assert(params.ErrCode(err), gc.Equals, params.CodeUnauthorized)
	c.Assert(machine, gc.IsNil)

	machine, err = s.machiner.Machine("machine-0")
	c.Assert(err, gc.IsNil)
	c.Assert(machine.Tag(), gc.Equals, "machine-0")
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:10,代碼來源:machiner_test.go

示例12: TestMachineAndMachineId

func (s *machinerSuite) TestMachineAndMachineId(c *C) {
	machine, err := s.st.Machiner().Machine("machine-42")
	c.Assert(err, ErrorMatches, "permission denied")
	c.Assert(params.ErrCode(err), Equals, params.CodeUnauthorized)
	c.Assert(machine, IsNil)

	machine, err = s.st.Machiner().Machine("machine-0")
	c.Assert(err, IsNil)
	c.Assert(machine.Tag(), Equals, "machine-0")
}
開發者ID:CSRedRat,項目名稱:juju-core,代碼行數:10,代碼來源:machiner_test.go

示例13: TestUnitAndUnitTag

func (s *uniterSuite) TestUnitAndUnitTag(c *gc.C) {
	unit, err := s.uniter.Unit("unit-foo-42")
	c.Assert(err, gc.ErrorMatches, "permission denied")
	c.Assert(params.ErrCode(err), gc.Equals, params.CodeUnauthorized)
	c.Assert(unit, gc.IsNil)

	unit, err = s.uniter.Unit("unit-wordpress-0")
	c.Assert(err, gc.IsNil)
	c.Assert(unit.Tag(), gc.Equals, "unit-wordpress-0")
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:10,代碼來源:uniter_test.go

示例14: TestMachine

func (s *suite) TestMachine(c *C) {
	m, err := s.st.MachineAgent().Machine("42")
	c.Assert(err, ErrorMatches, "permission denied")
	c.Assert(params.ErrCode(err), Equals, params.CodeUnauthorized)
	c.Assert(m, IsNil)

	m, err = s.st.MachineAgent().Machine(s.machine.Tag())
	c.Assert(err, IsNil)
	c.Assert(m.Tag(), Equals, s.machine.Tag())
	c.Assert(m.Life(), Equals, params.Alive)
	c.Assert(m.Jobs(), DeepEquals, []params.MachineJob{params.JobHostUnits})

	err = s.machine.EnsureDead()
	c.Assert(err, IsNil)
	err = s.machine.Remove()
	c.Assert(err, IsNil)

	m, err = s.st.MachineAgent().Machine(s.machine.Tag())
	c.Assert(err, ErrorMatches, fmt.Sprintf("machine %s not found", s.machine.Id()))
	c.Assert(params.ErrCode(err), Equals, params.CodeNotFound)
	c.Assert(m, IsNil)
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:22,代碼來源:state_test.go

示例15: TestUnitEntity

func (s *unitSuite) TestUnitEntity(c *gc.C) {
	m, err := s.st.Agent().Entity("wordpress/1")
	c.Assert(err, gc.ErrorMatches, "permission denied")
	c.Assert(params.ErrCode(err), gc.Equals, params.CodeUnauthorized)
	c.Assert(m, gc.IsNil)

	m, err = s.st.Agent().Entity(s.unit.Tag())
	c.Assert(err, gc.IsNil)
	c.Assert(m.Tag(), gc.Equals, s.unit.Tag())
	c.Assert(m.Life(), gc.Equals, params.Alive)
	c.Assert(m.Jobs(), gc.HasLen, 0)

	err = s.unit.EnsureDead()
	c.Assert(err, gc.IsNil)
	err = s.unit.Remove()
	c.Assert(err, gc.IsNil)

	m, err = s.st.Agent().Entity(s.unit.Tag())
	c.Assert(err, gc.ErrorMatches, fmt.Sprintf("unit %q not found", s.unit.Name()))
	c.Assert(params.ErrCode(err), gc.Equals, params.CodeNotFound)
	c.Assert(m, gc.IsNil)
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:22,代碼來源:unit_test.go


注:本文中的launchpad/net/juju-core/state/api/params.ErrCode函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。