github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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  
     9  	"github.com/juju/juju/apiserver/params"
    10  	"github.com/juju/juju/cmd/modelcmd"
    11  	"github.com/juju/juju/environs"
    12  	"github.com/juju/juju/jujuclient"
    13  )
    14  
    15  const (
    16  	NotSet          = notset
    17  	DownloadWarning = downloadWarning
    18  )
    19  
    20  var (
    21  	NewAPIClient = &newAPIClient
    22  )
    23  
    24  type CreateCommand struct {
    25  	*createCommand
    26  }
    27  
    28  type DownloadCommand struct {
    29  	*downloadCommand
    30  }
    31  
    32  func NewCreateCommandForTest() (cmd.Command, *CreateCommand) {
    33  	c := &createCommand{}
    34  	c.Log = &cmd.Log{}
    35  	return modelcmd.Wrap(c), &CreateCommand{c}
    36  }
    37  
    38  func NewDownloadCommandForTest() (cmd.Command, *DownloadCommand) {
    39  	c := &downloadCommand{}
    40  	c.Log = &cmd.Log{}
    41  	return modelcmd.Wrap(c), &DownloadCommand{c}
    42  }
    43  
    44  func NewListCommandForTest() cmd.Command {
    45  	c := &listCommand{}
    46  	c.Log = &cmd.Log{}
    47  	return modelcmd.Wrap(c)
    48  }
    49  
    50  func NewShowCommandForTest() cmd.Command {
    51  	c := &showCommand{}
    52  	c.Log = &cmd.Log{}
    53  	return modelcmd.Wrap(c)
    54  }
    55  
    56  func NewUploadCommandForTest() cmd.Command {
    57  	c := &uploadCommand{}
    58  	c.Log = &cmd.Log{}
    59  	return modelcmd.Wrap(c)
    60  }
    61  
    62  func NewRemoveCommandForTest() cmd.Command {
    63  	c := &removeCommand{}
    64  	c.Log = &cmd.Log{}
    65  	return modelcmd.Wrap(c)
    66  }
    67  
    68  func NewRestoreCommandForTest(
    69  	store jujuclient.ClientStore,
    70  	api RestoreAPI,
    71  	getArchive func(string) (ArchiveReader, *params.BackupsMetadataResult, error),
    72  	getEnviron func(string, *params.BackupsMetadataResult) (environs.Environ, error),
    73  ) cmd.Command {
    74  	c := &restoreCommand{
    75  		getArchiveFunc: getArchive,
    76  		getEnvironFunc: getEnviron,
    77  		newAPIClientFunc: func() (RestoreAPI, error) {
    78  			return api, nil
    79  		}}
    80  	if getEnviron == nil {
    81  		c.getEnvironFunc = func(controllerNme string, meta *params.BackupsMetadataResult) (environs.Environ, error) {
    82  			return c.getEnviron(controllerNme, meta)
    83  		}
    84  	}
    85  	c.Log = &cmd.Log{}
    86  	c.SetClientStore(store)
    87  	return modelcmd.Wrap(c)
    88  }