本文整理汇总了Golang中github.com/juju/juju/cmd/modelcmd.Wrap函数的典型用法代码示例。如果您正苦于以下问题:Golang Wrap函数的具体用法?Golang Wrap怎么用?Golang Wrap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Wrap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestDebugHooksCommand
func (s *DebugHooksSuite) TestDebugHooksCommand(c *gc.C) {
//TODO(bogdanteleaga): Fix once debughooks are supported on windows
if runtime.GOOS == "windows" {
c.Skip("bug 1403084: Skipping on windows for now")
}
machines := s.makeMachines(3, c, true)
dummy := s.AddTestingCharm(c, "dummy")
srv := s.AddTestingService(c, "mysql", dummy)
s.addUnit(srv, machines[0], c)
srv = s.AddTestingService(c, "mongodb", dummy)
s.addUnit(srv, machines[1], c)
s.addUnit(srv, machines[2], c)
for i, t := range debugHooksTests {
c.Logf("test %d: %s\n\t%s\n", i, t.info, t.args)
ctx := coretesting.Context(c)
debugHooksCmd := &debugHooksCommand{}
debugHooksCmd.proxy = true
err := modelcmd.Wrap(debugHooksCmd).Init(t.args)
if err == nil {
err = modelcmd.Wrap(debugHooksCmd).Run(ctx)
}
if t.error != "" {
c.Assert(err, gc.ErrorMatches, t.error)
} else {
c.Assert(err, jc.ErrorIsNil)
}
}
}
示例2: TestResetPreviousUpgrade
func (s *UpgradeJujuSuite) TestResetPreviousUpgrade(c *gc.C) {
fakeAPI := NewFakeUpgradeJujuAPI(c, s.State)
fakeAPI.patch(s)
ctx := coretesting.Context(c)
var stdin bytes.Buffer
ctx.Stdin = &stdin
run := func(answer string, expect bool, args ...string) {
stdin.Reset()
if answer != "" {
stdin.WriteString(answer)
}
fakeAPI.reset()
cmd := &upgradeJujuCommand{}
err := coretesting.InitCommand(modelcmd.Wrap(cmd),
append([]string{"--reset-previous-upgrade"}, args...))
c.Assert(err, jc.ErrorIsNil)
err = modelcmd.Wrap(cmd).Run(ctx)
if expect {
c.Assert(err, jc.ErrorIsNil)
} else {
c.Assert(err, gc.ErrorMatches, "previous upgrade not reset and no new upgrade triggered")
}
c.Assert(fakeAPI.abortCurrentUpgradeCalled, gc.Equals, expect)
expectedVersion := version.Number{}
if expect {
expectedVersion = fakeAPI.nextVersion.Number
}
c.Assert(fakeAPI.setVersionCalledWith, gc.Equals, expectedVersion)
}
const expectUpgrade = true
const expectNoUpgrade = false
// EOF on stdin - equivalent to answering no.
run("", expectNoUpgrade)
// -y on command line - no confirmation required
run("", expectUpgrade, "-y")
// --yes on command line - no confirmation required
run("", expectUpgrade, "--yes")
// various ways of saying "yes" to the prompt
for _, answer := range []string{"y", "Y", "yes", "YES"} {
run(answer, expectUpgrade)
}
// various ways of saying "no" to the prompt
for _, answer := range []string{"n", "N", "no", "foo"} {
run(answer, expectNoUpgrade)
}
}
示例3: TestSCPCommand
func (s *SCPSuite) TestSCPCommand(c *gc.C) {
m := s.makeMachines(4, c, true)
ch := testcharms.Repo.CharmDir("dummy")
curl := charm.MustParseURL(
fmt.Sprintf("local:quantal/%s-%d", ch.Meta().Name, ch.Revision()),
)
info := state.CharmInfo{
Charm: ch,
ID: curl,
StoragePath: "dummy-path",
SHA256: "dummy-1-sha256",
}
dummyCharm, err := s.State.AddCharm(info)
c.Assert(err, jc.ErrorIsNil)
srv := s.AddTestingService(c, "mysql", dummyCharm)
s.addUnit(srv, m[0], c)
srv = s.AddTestingService(c, "mongodb", dummyCharm)
s.addUnit(srv, m[1], c)
s.addUnit(srv, m[2], c)
srv = s.AddTestingService(c, "ipv6-svc", dummyCharm)
s.addUnit(srv, m[3], c)
// Simulate machine 3 has a public IPv6 address.
ipv6Addr := network.NewScopedAddress("2001:db8::1", network.ScopePublic)
err = m[3].SetProviderAddresses(ipv6Addr)
c.Assert(err, jc.ErrorIsNil)
for i, t := range scpTests {
c.Logf("test %d: %s -> %s\n", i, t.about, t.args)
ctx := coretesting.Context(c)
scpcmd := &scpCommand{}
scpcmd.proxy = t.proxy
err := modelcmd.Wrap(scpcmd).Init(t.args)
c.Check(err, jc.ErrorIsNil)
err = modelcmd.Wrap(scpcmd).Run(ctx)
if t.error != "" {
c.Check(err, gc.ErrorMatches, t.error)
c.Check(t.result, gc.Equals, "")
} else {
c.Check(err, jc.ErrorIsNil)
// we suppress stdout from scp
c.Check(ctx.Stderr.(*bytes.Buffer).String(), gc.Equals, "")
c.Check(ctx.Stdout.(*bytes.Buffer).String(), gc.Equals, "")
data, err := ioutil.ReadFile(filepath.Join(s.bin, "scp.args"))
c.Check(err, jc.ErrorIsNil)
actual := string(data)
if t.proxy {
actual = strings.Replace(actual, ".dns", ".internal", 2)
}
c.Check(actual, gc.Equals, t.result)
}
}
}
示例4: TestBlockUpgradeInProgress
func (s *UpgradeJujuSuite) TestBlockUpgradeInProgress(c *gc.C) {
fakeAPI := NewFakeUpgradeJujuAPI(c, s.State)
fakeAPI.setVersionErr = common.OperationBlockedError("the operation has been blocked")
fakeAPI.patch(s)
cmd := &upgradeJujuCommand{}
err := coretesting.InitCommand(modelcmd.Wrap(cmd), []string{})
c.Assert(err, jc.ErrorIsNil)
// Block operation
s.BlockAllChanges(c, "TestBlockUpgradeInProgress")
err = modelcmd.Wrap(cmd).Run(coretesting.Context(c))
s.AssertBlocked(c, err, ".*To enable changes.*")
}
示例5: NewRestoreCommandForTest
func NewRestoreCommandForTest(
store jujuclient.ClientStore,
api RestoreAPI,
getArchive func(string) (ArchiveReader, *params.BackupsMetadataResult, error),
newEnviron func(environs.OpenParams) (environs.Environ, error),
getRebootstrapParams func(*cmd.Context, string, *params.BackupsMetadataResult) (*restoreBootstrapParams, error),
) cmd.Command {
c := &restoreCommand{
getArchiveFunc: getArchive,
newEnvironFunc: newEnviron,
getRebootstrapParamsFunc: getRebootstrapParams,
newAPIClientFunc: func() (RestoreAPI, error) {
return api, nil
},
waitForAgentFunc: func(ctx *cmd.Context, c *modelcmd.ModelCommandBase, controllerName, hostedModelName string) error {
return nil
},
}
if getRebootstrapParams == nil {
c.getRebootstrapParamsFunc = c.getRebootstrapParams
}
if newEnviron == nil {
c.newEnvironFunc = environs.New
}
c.Log = &cmd.Log{}
c.SetClientStore(store)
return modelcmd.Wrap(c)
}
示例6: newVolumeListCommand
func newVolumeListCommand() cmd.Command {
cmd := &volumeListCommand{}
cmd.newAPIFunc = func() (VolumeListAPI, error) {
return cmd.NewStorageAPI()
}
return modelcmd.Wrap(cmd)
}
示例7: newFilesystemListCommand
func newFilesystemListCommand() cmd.Command {
cmd := &filesystemListCommand{}
cmd.newAPIFunc = func() (FilesystemListAPI, error) {
return cmd.NewStorageAPI()
}
return modelcmd.Wrap(cmd)
}
示例8: NewDestroyCommand
// NewDestroyCommand returns a command used to destroy a model.
func NewDestroyCommand() cmd.Command {
return modelcmd.Wrap(
&destroyCommand{},
modelcmd.WrapSkipDefaultModel,
modelcmd.WrapSkipModelFlags,
)
}
示例9: NewDeployCommandWithDefaultAPI
func NewDeployCommandWithDefaultAPI(steps []DeployStep) cmd.Command {
deployCmd := &DeployCommand{Steps: steps}
cmd := modelcmd.Wrap(deployCmd)
deployCmd.NewAPIRoot = func() (DeployAPI, error) {
apiRoot, err := deployCmd.ModelCommandBase.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
bakeryClient, err := deployCmd.BakeryClient()
if err != nil {
return nil, errors.Trace(err)
}
cstoreClient := newCharmStoreClient(bakeryClient).WithChannel(deployCmd.Channel)
adapter := &deployAPIAdapter{
Connection: apiRoot,
apiClient: &apiClient{Client: apiRoot.Client()},
charmsClient: &charmsClient{Client: apicharms.NewClient(apiRoot)},
applicationClient: &applicationClient{Client: application.NewClient(apiRoot)},
modelConfigClient: &modelConfigClient{Client: modelconfig.NewClient(apiRoot)},
charmstoreClient: &charmstoreClient{Client: cstoreClient},
annotationsClient: &annotationsClient{Client: annotations.NewClient(apiRoot)},
charmRepoClient: &charmRepoClient{CharmStore: charmrepo.NewCharmStoreFromClient(cstoreClient)},
}
return adapter, nil
}
return cmd
}
示例10: newAddCommand
func newAddCommand() cmd.Command {
cmd := &addCommand{}
cmd.newAPIFunc = func() (StorageAddAPI, error) {
return cmd.NewStorageAPI()
}
return modelcmd.Wrap(cmd)
}
示例11: NewDestroyCommand
// NewDestroyCommand returns a command used to destroy a model.
func NewDestroyCommand() cmd.Command {
return modelcmd.Wrap(
&destroyCommand{},
modelcmd.ModelSkipDefault,
modelcmd.ModelSkipFlags,
)
}
示例12: NewAddCommandForTest
func NewAddCommandForTest(api StorageAddAPI, store jujuclient.ClientStore) cmd.Command {
cmd := &addCommand{newAPIFunc: func() (StorageAddAPI, error) {
return api, nil
}}
cmd.SetClientStore(store)
return modelcmd.Wrap(cmd)
}
示例13: NewPoolCreateCommandForTest
func NewPoolCreateCommandForTest(api PoolCreateAPI, store jujuclient.ClientStore) cmd.Command {
cmd := &poolCreateCommand{newAPIFunc: func() (PoolCreateAPI, error) {
return api, nil
}}
cmd.SetClientStore(store)
return modelcmd.Wrap(cmd)
}
示例14: NewShowCommand
// NewShowCommand returns a command that shows storage details
// on the specified machine
func NewShowCommand() cmd.Command {
cmd := &showCommand{}
cmd.newAPIFunc = func() (StorageShowAPI, error) {
return cmd.NewStorageAPI()
}
return modelcmd.Wrap(cmd)
}
示例15: NewListCommand
// NewListCommand returns a command for listing storage instances.
func NewListCommand() cmd.Command {
cmd := &listCommand{}
cmd.newAPIFunc = func() (StorageListAPI, error) {
return cmd.NewStorageAPI()
}
return modelcmd.Wrap(cmd)
}