当前位置: 首页>>代码示例>>Golang>>正文


Golang testing.ServerError函数代码示例

本文整理汇总了Golang中github.com/juju/juju/apiserver/testing.ServerError函数的典型用法代码示例。如果您正苦于以下问题:Golang ServerError函数的具体用法?Golang ServerError怎么用?Golang ServerError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ServerError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestInstanceStatusSuccess

func (s *InstancePollerSuite) TestInstanceStatusSuccess(c *gc.C) {
	s.st.SetMachineInfo(c, machineInfo{id: "1", instanceStatus: statusInfo("foo")})
	s.st.SetMachineInfo(c, machineInfo{id: "2", instanceStatus: statusInfo("")})

	result, err := s.api.InstanceStatus(s.mixedEntities)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, params.StatusResults{
		Results: []params.StatusResult{
			{Status: "foo"},
			{Status: ""},
			{Error: apiservertesting.NotFoundError("machine 42")},
			{Error: apiservertesting.ServerError(`"application-unknown" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"invalid-tag" is not a valid tag`)},
			{Error: apiservertesting.ServerError(`"unit-missing-1" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"" is not a valid tag`)},
			{Error: apiservertesting.ServerError(`"42" is not a valid tag`)},
		},
	},
	)

	s.st.CheckFindEntityCall(c, 0, "1")
	s.st.CheckCall(c, 1, "InstanceStatus")
	s.st.CheckFindEntityCall(c, 2, "2")
	s.st.CheckCall(c, 3, "InstanceStatus")
	s.st.CheckFindEntityCall(c, 4, "42")
}
开发者ID:bac,项目名称:juju,代码行数:26,代码来源:instancepoller_test.go

示例2: TestProviderAddressesSuccess

func (s *InstancePollerSuite) TestProviderAddressesSuccess(c *gc.C) {
	addrs := network.NewAddresses("0.1.2.3", "127.0.0.1", "8.8.8.8")
	expectedAddresses := params.FromNetworkAddresses(addrs...)
	s.st.SetMachineInfo(c, machineInfo{id: "1", providerAddresses: addrs})
	s.st.SetMachineInfo(c, machineInfo{id: "2", providerAddresses: nil})

	result, err := s.api.ProviderAddresses(s.mixedEntities)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, params.MachineAddressesResults{
		Results: []params.MachineAddressesResult{
			{Addresses: expectedAddresses},
			{Addresses: nil},
			{Error: apiservertesting.NotFoundError("machine 42")},
			{Error: apiservertesting.ServerError(`"application-unknown" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"invalid-tag" is not a valid tag`)},
			{Error: apiservertesting.ServerError(`"unit-missing-1" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"" is not a valid tag`)},
			{Error: apiservertesting.ServerError(`"42" is not a valid tag`)},
		}},
	)

	s.st.CheckFindEntityCall(c, 0, "1")
	s.st.CheckCall(c, 1, "ProviderAddresses")
	s.st.CheckFindEntityCall(c, 2, "2")
	s.st.CheckCall(c, 3, "ProviderAddresses")
	s.st.CheckFindEntityCall(c, 4, "42")
}
开发者ID:bac,项目名称:juju,代码行数:27,代码来源:instancepoller_test.go

示例3: TestAreManuallyProvisionedFailure

func (s *InstancePollerSuite) TestAreManuallyProvisionedFailure(c *gc.C) {
	s.st.SetErrors(
		errors.New("pow!"),                   // m1 := FindEntity("1")
		nil,                                  // m2 := FindEntity("2")
		errors.New("FAIL"),                   // m2.IsManual()
		errors.NotProvisionedf("machine 42"), // FindEntity("3") (ensure wrapping is preserved)
	)
	s.st.SetMachineInfo(c, machineInfo{id: "1", isManual: true})
	s.st.SetMachineInfo(c, machineInfo{id: "2", isManual: false})

	result, err := s.api.AreManuallyProvisioned(s.machineEntities)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, params.BoolResults{
		Results: []params.BoolResult{
			{Error: apiservertesting.ServerError("pow!")},
			{Error: apiservertesting.ServerError("FAIL")},
			{Error: apiservertesting.NotProvisionedError("42")},
		}},
	)

	s.st.CheckFindEntityCall(c, 0, "1")
	s.st.CheckFindEntityCall(c, 1, "2")
	s.st.CheckCall(c, 2, "IsManual")
	s.st.CheckFindEntityCall(c, 3, "3")
}
开发者ID:bac,项目名称:juju,代码行数:25,代码来源:instancepoller_test.go

示例4: TestAreManuallyProvisionedSuccess

func (s *InstancePollerSuite) TestAreManuallyProvisionedSuccess(c *gc.C) {
	s.st.SetMachineInfo(c, machineInfo{id: "1", isManual: true})
	s.st.SetMachineInfo(c, machineInfo{id: "2", isManual: false})

	result, err := s.api.AreManuallyProvisioned(s.mixedEntities)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, params.BoolResults{
		Results: []params.BoolResult{
			{Result: true},
			{Result: false},
			{Error: apiservertesting.NotFoundError("machine 42")},
			{Error: apiservertesting.ServerError(`"application-unknown" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"invalid-tag" is not a valid tag`)},
			{Error: apiservertesting.ServerError(`"unit-missing-1" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"" is not a valid tag`)},
			{Error: apiservertesting.ServerError(`"42" is not a valid tag`)},
		}},
	)

	s.st.CheckFindEntityCall(c, 0, "1")
	s.st.CheckCall(c, 1, "IsManual")
	s.st.CheckFindEntityCall(c, 2, "2")
	s.st.CheckCall(c, 3, "IsManual")
	s.st.CheckFindEntityCall(c, 4, "42")
}
开发者ID:bac,项目名称:juju,代码行数:25,代码来源:instancepoller_test.go

示例5: TestStatusFailure

func (s *InstancePollerSuite) TestStatusFailure(c *gc.C) {
	s.st.SetErrors(
		errors.New("pow!"),                   // m1 := FindEntity("1"); Status not called
		nil,                                  // m2 := FindEntity("2")
		errors.New("FAIL"),                   // m2.Status()
		errors.NotProvisionedf("machine 42"), // FindEntity("3") (ensure wrapping is preserved)
	)
	s.st.SetMachineInfo(c, machineInfo{id: "1"})
	s.st.SetMachineInfo(c, machineInfo{id: "2"})

	result, err := s.api.Status(s.machineEntities)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, params.StatusResults{
		Results: []params.StatusResult{
			{Error: apiservertesting.ServerError("pow!")},
			{Error: apiservertesting.ServerError("FAIL")},
			{Error: apiservertesting.NotProvisionedError("42")},
		}},
	)

	s.st.CheckFindEntityCall(c, 0, "1")
	s.st.CheckFindEntityCall(c, 1, "2")
	s.st.CheckCall(c, 2, "Status")
	s.st.CheckFindEntityCall(c, 3, "3")
}
开发者ID:bac,项目名称:juju,代码行数:25,代码来源:instancepoller_test.go

示例6: TestLifeFailure

func (s *InstancePollerSuite) TestLifeFailure(c *gc.C) {
	s.st.SetErrors(
		errors.New("pow!"),                   // m1 := FindEntity("1"); Life not called
		nil,                                  // m2 := FindEntity("2")
		errors.New("FAIL"),                   // m2.Life() - unused
		errors.NotProvisionedf("machine 42"), // FindEntity("3") (ensure wrapping is preserved)
	)
	s.st.SetMachineInfo(c, machineInfo{id: "1", life: state.Alive})
	s.st.SetMachineInfo(c, machineInfo{id: "2", life: state.Dead})
	s.st.SetMachineInfo(c, machineInfo{id: "3", life: state.Dying})

	result, err := s.api.Life(s.machineEntities)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, params.LifeResults{
		Results: []params.LifeResult{
			{Error: apiservertesting.ServerError("pow!")},
			{Life: params.Dead},
			{Error: apiservertesting.NotProvisionedError("42")},
		}},
	)

	s.st.CheckFindEntityCall(c, 0, "1")
	s.st.CheckFindEntityCall(c, 1, "2")
	s.st.CheckCall(c, 2, "Life")
	s.st.CheckFindEntityCall(c, 3, "3")
}
开发者ID:bac,项目名称:juju,代码行数:26,代码来源:instancepoller_test.go

示例7: TestIPAddressesServerError

func (s *AddresserSuite) TestIPAddressesServerError(c *gc.C) {
	tag1 := names.NewIPAddressTag("11111111-0000-0000-0000-000000000000")
	tag2 := names.NewIPAddressTag("22222222-0000-0000-0000-000000000000")

	var called int
	args := params.Entities{
		Entities: []params.Entity{
			{Tag: tag1.String()},
			{Tag: tag2.String()},
		},
	}
	results := params.LifeResults{
		Results: []params.LifeResult{
			{params.Alive, nil},
			{"", apiservertesting.ServerError("server failure")},
		},
	}
	apiCaller := successAPICaller(c, "Life", args, results, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddresses, err := api.IPAddresses(tag1, tag2)
	c.Assert(len(ipAddresses), gc.Equals, 2)
	c.Assert(ipAddresses[0].Tag().String(), gc.Equals, tag1.String())
	c.Assert(ipAddresses[1], gc.IsNil)
	c.Assert(err, gc.Equals, common.ErrPartialResults)
	c.Assert(called, gc.Equals, 1)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:27,代码来源:addresser_test.go

示例8: TestUnitStatus

func (s *uniterV2Suite) TestUnitStatus(c *gc.C) {
	err := s.wordpressUnit.SetStatus(state.StatusMaintenance, "blah", nil)
	c.Assert(err, jc.ErrorIsNil)
	err = s.mysqlUnit.SetStatus(state.StatusTerminated, "foo", nil)
	c.Assert(err, jc.ErrorIsNil)

	args := params.Entities{
		Entities: []params.Entity{
			{Tag: "unit-mysql-0"},
			{Tag: "unit-wordpress-0"},
			{Tag: "unit-foo-42"},
			{Tag: "machine-1"},
			{Tag: "invalid"},
		}}
	result, err := s.uniter.UnitStatus(args)
	c.Assert(err, jc.ErrorIsNil)
	// Zero out the updated timestamps so we can easily check the results.
	for i, statusResult := range result.Results {
		r := statusResult
		if r.Status != "" {
			c.Assert(r.Since, gc.NotNil)
		}
		r.Since = nil
		result.Results[i] = r
	}
	c.Assert(result, gc.DeepEquals, params.StatusResults{
		Results: []params.StatusResult{
			{Error: apiservertesting.ErrUnauthorized},
			{Status: params.StatusMaintenance, Info: "blah", Data: map[string]interface{}{}},
			{Error: apiservertesting.ErrUnauthorized},
			{Error: apiservertesting.ErrUnauthorized},
			{Error: apiservertesting.ServerError(`"invalid" is not a valid tag`)},
		},
	})
}
开发者ID:imoapps,项目名称:juju,代码行数:35,代码来源:uniter_v2_test.go

示例9: TestGetMachinePorts

func (s *firewallerSuite) TestGetMachinePorts(c *gc.C) {
	s.openPorts(c)

	subnetTag := names.NewSubnetTag("10.20.30.0/24").String()
	args := params.MachinePortsParams{
		Params: []params.MachinePorts{
			{MachineTag: s.machines[0].Tag().String(), SubnetTag: ""},
			{MachineTag: s.machines[0].Tag().String(), SubnetTag: subnetTag},
			{MachineTag: s.machines[1].Tag().String(), SubnetTag: ""},
			{MachineTag: s.machines[2].Tag().String(), SubnetTag: ""},
			{MachineTag: s.machines[0].Tag().String(), SubnetTag: "invalid"},
			{MachineTag: "machine-42", SubnetTag: ""},
			{MachineTag: s.machines[0].Tag().String(), SubnetTag: "subnet-bad"},
		},
	}
	unit0Tag := s.units[0].Tag().String()
	expectPortsMachine0NoSubnet := []params.MachinePortRange{
		{UnitTag: unit0Tag, PortRange: params.PortRange{
			FromPort: 4321, ToPort: 4321, Protocol: "tcp",
		}},
	}
	expectPortsMachine0WithSubnet := []params.MachinePortRange{
		{UnitTag: unit0Tag, PortRange: params.PortRange{
			FromPort: 1234, ToPort: 1400, Protocol: "tcp",
		}},
	}
	unit2Tag := s.units[2].Tag().String()
	expectPortsMachine2 := []params.MachinePortRange{
		{UnitTag: unit2Tag, PortRange: params.PortRange{
			FromPort: 1111, ToPort: 2222, Protocol: "udp",
		}},
	}
	result, err := s.firewaller.GetMachinePorts(args)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, params.MachinePortsResults{
		Results: []params.MachinePortsResult{
			{Ports: expectPortsMachine0NoSubnet},
			{Ports: expectPortsMachine0WithSubnet},
			{Error: nil, Ports: nil},
			{Ports: expectPortsMachine2},
			{Error: apiservertesting.ServerError(`"invalid" is not a valid tag`)},
			{Error: apiservertesting.NotFoundError("machine 42")},
			{Error: apiservertesting.ServerError(`"subnet-bad" is not a valid subnet tag`)},
		},
	})

}
开发者ID:bac,项目名称:juju,代码行数:47,代码来源:firewaller_test.go

示例10: TestGetMachineActiveSubnets

func (s *firewallerSuite) TestGetMachineActiveSubnets(c *gc.C) {
	s.openPorts(c)

	subnetTag := names.NewSubnetTag("10.20.30.0/24").String()
	args := addFakeEntities(params.Entities{Entities: []params.Entity{
		{Tag: s.machines[0].Tag().String()},
		{Tag: s.machines[1].Tag().String()},
		{Tag: s.machines[2].Tag().String()},
		{Tag: s.service.Tag().String()},
		{Tag: s.units[0].Tag().String()},
	}})
	expectResultsMachine0 := []string{subnetTag, ""}
	expectResultsMachine2 := []string{""}
	result, err := s.firewaller.GetMachineActiveSubnets(args)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, params.StringsResults{
		Results: []params.StringsResult{
			{Result: expectResultsMachine0},
			{Result: nil, Error: nil},
			{Result: expectResultsMachine2},
			{Error: apiservertesting.ServerError(`"application-wordpress" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"unit-wordpress-0" is not a valid machine tag`)},
			{Error: apiservertesting.NotFoundError("machine 42")},
			{Error: apiservertesting.ServerError(`"unit-foo-0" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"application-bar" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"user-foo" is not a valid machine tag`)},
			{Error: apiservertesting.ServerError(`"foo-bar" is not a valid tag`)},
			{Error: apiservertesting.ServerError(`"" is not a valid tag`)},
		},
	})
}
开发者ID:bac,项目名称:juju,代码行数:31,代码来源:firewaller_test.go

示例11: TestErrorWithHostInsteadOfContainer

func (s *prepareSuite) TestErrorWithHostInsteadOfContainer(c *gc.C) {
	s.newAPI(c, true, false)
	args := s.makeArgs(s.machines[0])
	s.assertCall(c, args, s.makeErrors(
		apiservertesting.ServerError(
			`cannot allocate address for "machine-0": not a container`,
		),
	), "")
}
开发者ID:makyo,项目名称:juju,代码行数:9,代码来源:container_test.go

示例12: TestStatusSuccess

func (s *InstancePollerSuite) TestStatusSuccess(c *gc.C) {
	now := time.Now()
	s1 := status.StatusInfo{
		Status:  status.Error,
		Message: "not really",
		Data: map[string]interface{}{
			"price": 4.2,
			"bool":  false,
			"bar":   []string{"a", "b"},
		},
		Since: &now,
	}
	s2 := status.StatusInfo{}
	s.st.SetMachineInfo(c, machineInfo{id: "1", status: s1})
	s.st.SetMachineInfo(c, machineInfo{id: "2", status: s2})

	result, err := s.api.Status(s.mixedEntities)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, jc.DeepEquals, params.StatusResults{
		Results: []params.StatusResult{
			{
				Status: status.Error.String(),
				Info:   s1.Message,
				Data:   s1.Data,
				Since:  s1.Since,
			},
			{Status: "", Info: "", Data: nil, Since: nil},
			{Error: apiservertesting.NotFoundError("machine 42")},
			{Error: apiservertesting.ErrUnauthorized},
			{Error: apiservertesting.ServerError(`"invalid-tag" is not a valid tag`)},
			{Error: apiservertesting.ErrUnauthorized},
			{Error: apiservertesting.ServerError(`"" is not a valid tag`)},
			{Error: apiservertesting.ServerError(`"42" is not a valid tag`)},
		}},
	)

	s.st.CheckFindEntityCall(c, 0, "1")
	s.st.CheckCall(c, 1, "Status")
	s.st.CheckFindEntityCall(c, 2, "2")
	s.st.CheckCall(c, 3, "Status")
	s.st.CheckFindEntityCall(c, 4, "42")
}
开发者ID:bac,项目名称:juju,代码行数:42,代码来源:instancepoller_test.go

示例13: TestErrorWithNoFeatureFlag

func (s *releaseSuite) TestErrorWithNoFeatureFlag(c *gc.C) {
	s.SetFeatureFlags() // clear the flags.
	s.newAPI(c, true, false)
	args := s.makeArgs(s.machines[0])
	expectedError := `cannot mark addresses for removal for "machine-0": not a container`
	s.assertCall(c, args, &params.ErrorResults{
		Results: []params.ErrorResult{{
			Error: apiservertesting.ServerError(expectedError),
		}},
	}, "")
}
开发者ID:makyo,项目名称:juju,代码行数:11,代码来源:container_test.go

示例14: TestErrorWithProvisionedContainer

func (s *prepareSuite) TestErrorWithProvisionedContainer(c *gc.C) {
	container := s.newAPI(c, true, true)
	err := container.SetProvisioned("i-foo", "fake_nonce", nil)
	c.Assert(err, jc.ErrorIsNil)
	args := s.makeArgs(container)
	s.assertCall(c, args, s.makeErrors(
		apiservertesting.ServerError(
			`container "0/lxc/0" already provisioned as "i-foo"`,
		),
	), "")
}
开发者ID:makyo,项目名称:juju,代码行数:11,代码来源:container_test.go

示例15: TestDeleteKeysNotJujuInternal

func (s *keyManagerSuite) TestDeleteKeysNotJujuInternal(c *gc.C) {
	key1 := sshtesting.ValidKeyOne.Key + " juju-client-key"
	key2 := sshtesting.ValidKeyTwo.Key + " juju-system-key"
	key3 := sshtesting.ValidKeyThree.Key + " a user key"
	initialKeys := []string{key1, key2, key3}
	s.setAuthorisedKeys(c, strings.Join(initialKeys, "\n"))

	args := params.ModifyUserSSHKeys{
		User: s.AdminUserTag(c).Name(),
		Keys: []string{"juju-client-key", "juju-system-key"},
	}
	results, err := s.keymanager.DeleteKeys(args)
	c.Check(results, gc.DeepEquals, params.ErrorResults{
		Results: []params.ErrorResult{
			{Error: apiservertesting.ServerError("may not delete internal key: juju-client-key")},
			{Error: apiservertesting.ServerError("may not delete internal key: juju-system-key")},
		},
	})
	c.Assert(err, jc.ErrorIsNil)
	s.assertEnvironKeys(c, initialKeys)
}
开发者ID:bac,项目名称:juju,代码行数:21,代码来源:keymanager_test.go


注:本文中的github.com/juju/juju/apiserver/testing.ServerError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。