github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/cmd/juju/backups/export_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package backups 5 6 import ( 7 "github.com/juju/cmd" 8 "github.com/juju/errors" 9 10 "github.com/juju/juju/apiserver/params" 11 "github.com/juju/juju/cmd/modelcmd" 12 "github.com/juju/juju/environs" 13 "github.com/juju/juju/jujuclient" 14 "github.com/juju/juju/testing" 15 ) 16 17 const ( 18 NotSet = notset 19 DownloadWarning = downloadWarning 20 ) 21 22 var ( 23 NewAPIClient = &newAPIClient 24 ) 25 26 type CreateCommand struct { 27 *createCommand 28 } 29 30 type DownloadCommand struct { 31 *downloadCommand 32 } 33 34 func NewCreateCommandForTest() (cmd.Command, *CreateCommand) { 35 c := &createCommand{} 36 c.Log = &cmd.Log{} 37 return modelcmd.Wrap(c), &CreateCommand{c} 38 } 39 40 func NewDownloadCommandForTest() (cmd.Command, *DownloadCommand) { 41 c := &downloadCommand{} 42 c.Log = &cmd.Log{} 43 return modelcmd.Wrap(c), &DownloadCommand{c} 44 } 45 46 func NewListCommandForTest() cmd.Command { 47 c := &listCommand{} 48 c.Log = &cmd.Log{} 49 return modelcmd.Wrap(c) 50 } 51 52 func NewShowCommandForTest() cmd.Command { 53 c := &showCommand{} 54 c.Log = &cmd.Log{} 55 return modelcmd.Wrap(c) 56 } 57 58 func NewUploadCommandForTest() cmd.Command { 59 c := &uploadCommand{} 60 c.Log = &cmd.Log{} 61 return modelcmd.Wrap(c) 62 } 63 64 func NewRemoveCommandForTest() cmd.Command { 65 c := &removeCommand{} 66 c.Log = &cmd.Log{} 67 return modelcmd.Wrap(c) 68 } 69 70 func NewRestoreCommandForTest( 71 store jujuclient.ClientStore, 72 api RestoreAPI, 73 getArchive func(string) (ArchiveReader, *params.BackupsMetadataResult, error), 74 newEnviron func(environs.OpenParams) (environs.Environ, error), 75 getRebootstrapParams func(*cmd.Context, string, *params.BackupsMetadataResult) (*restoreBootstrapParams, error), 76 ) cmd.Command { 77 c := &restoreCommand{ 78 getArchiveFunc: getArchive, 79 newEnvironFunc: newEnviron, 80 getRebootstrapParamsFunc: getRebootstrapParams, 81 newAPIClientFunc: func() (RestoreAPI, error) { 82 return api, nil 83 }, 84 waitForAgentFunc: func(ctx *cmd.Context, c *modelcmd.ModelCommandBase, controllerName, hostedModelName string) error { 85 return nil 86 }, 87 } 88 if getRebootstrapParams == nil { 89 c.getRebootstrapParamsFunc = c.getRebootstrapParams 90 } 91 if newEnviron == nil { 92 c.newEnvironFunc = environs.New 93 } 94 c.Log = &cmd.Log{} 95 c.SetClientStore(store) 96 return modelcmd.Wrap(c) 97 } 98 99 func GetEnvironFunc(e environs.Environ) func(environs.OpenParams) (environs.Environ, error) { 100 return func(environs.OpenParams) (environs.Environ, error) { 101 return e, nil 102 } 103 } 104 105 func GetRebootstrapParamsFunc(cloud string) func(*cmd.Context, string, *params.BackupsMetadataResult) (*restoreBootstrapParams, error) { 106 return func(*cmd.Context, string, *params.BackupsMetadataResult) (*restoreBootstrapParams, error) { 107 return &restoreBootstrapParams{ 108 ControllerConfig: testing.FakeControllerConfig(), 109 Cloud: environs.CloudSpec{ 110 Type: "lxd", 111 Name: cloud, 112 Region: "a-region", 113 }, 114 }, nil 115 } 116 } 117 118 func GetRebootstrapParamsFuncWithError() func(*cmd.Context, string, *params.BackupsMetadataResult) (*restoreBootstrapParams, error) { 119 return func(*cmd.Context, string, *params.BackupsMetadataResult) (*restoreBootstrapParams, error) { 120 return nil, errors.New("failed") 121 } 122 }