github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/model/export_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package model
     5  
     6  import (
     7  	jujuclock "github.com/juju/clock"
     8  	"github.com/juju/cmd"
     9  
    10  	"github.com/juju/juju/api"
    11  	"github.com/juju/juju/api/base"
    12  	"github.com/juju/juju/cmd/modelcmd"
    13  	"github.com/juju/juju/jujuclient"
    14  	"github.com/juju/juju/jujuclient/jujuclienttesting"
    15  )
    16  
    17  // NewConfigCommandForTest returns a configCommand with the api
    18  // provided as specified.
    19  func NewConfigCommandForTest(api configCommandAPI) cmd.Command {
    20  	cmd := &configCommand{
    21  		api: api,
    22  	}
    23  	cmd.SetClientStore(jujuclienttesting.MinimalStore())
    24  	return modelcmd.Wrap(cmd)
    25  }
    26  
    27  // NewDefaultsCommandForTest returns a defaultsCommand with the api provided as specified.
    28  func NewDefaultsCommandForTest(apiRoot api.Connection, dAPI defaultsCommandAPI, cAPI cloudAPI, store jujuclient.ClientStore) cmd.Command {
    29  	cmd := &defaultsCommand{
    30  		newAPIRoot:     func() (api.Connection, error) { return apiRoot, nil },
    31  		newDefaultsAPI: func(caller base.APICallCloser) defaultsCommandAPI { return dAPI },
    32  		newCloudAPI:    func(caller base.APICallCloser) cloudAPI { return cAPI },
    33  	}
    34  	cmd.SetClientStore(store)
    35  	return modelcmd.WrapController(cmd)
    36  }
    37  
    38  // NewRetryProvisioningCommandForTest returns a RetryProvisioningCommand with the api provided as specified.
    39  func NewRetryProvisioningCommandForTest(api RetryProvisioningAPI) cmd.Command {
    40  	cmd := &retryProvisioningCommand{
    41  		api: api,
    42  	}
    43  	cmd.SetClientStore(jujuclienttesting.MinimalStore())
    44  	return modelcmd.Wrap(cmd)
    45  }
    46  
    47  // NewShowCommandForTest returns a ShowCommand with the api provided as specified.
    48  func NewShowCommandForTest(api ShowModelAPI, refreshFunc func(jujuclient.ClientStore, string) error, store jujuclient.ClientStore) cmd.Command {
    49  	cmd := &showModelCommand{api: api}
    50  	cmd.SetClientStore(store)
    51  	cmd.SetModelRefresh(refreshFunc)
    52  	return modelcmd.Wrap(cmd, modelcmd.WrapSkipModelFlags)
    53  }
    54  
    55  // NewDumpCommandForTest returns a DumpCommand with the api provided as specified.
    56  func NewDumpCommandForTest(api DumpModelAPI, store jujuclient.ClientStore) cmd.Command {
    57  	cmd := &dumpCommand{api: api}
    58  	cmd.SetClientStore(store)
    59  	return modelcmd.Wrap(cmd)
    60  }
    61  
    62  // NewDumpDBCommandForTest returns a DumpDBCommand with the api provided as specified.
    63  func NewDumpDBCommandForTest(api DumpDBAPI, store jujuclient.ClientStore) cmd.Command {
    64  	cmd := &dumpDBCommand{api: api}
    65  	cmd.SetClientStore(store)
    66  	return modelcmd.Wrap(cmd)
    67  }
    68  
    69  // NewExportBundleCommandForTest returns a ExportBundleCommand with the api provided as specified.
    70  func NewExportBundleCommandForTest(api ExportBundleAPI, store jujuclient.ClientStore) cmd.Command {
    71  	cmd := &exportBundleCommand{newAPIFunc: func() (ExportBundleAPI, error) {
    72  		return api, nil
    73  	}}
    74  	cmd.SetClientStore(store)
    75  	return modelcmd.Wrap(cmd)
    76  }
    77  
    78  // NewDestroyCommandForTest returns a DestroyCommand with the api provided as specified.
    79  func NewDestroyCommandForTest(
    80  	api DestroyModelAPI,
    81  	configAPI ModelConfigAPI,
    82  	storageAPI StorageAPI,
    83  	clk jujuclock.Clock,
    84  	refreshFunc func(jujuclient.ClientStore, string) error, store jujuclient.ClientStore,
    85  ) cmd.Command {
    86  	cmd := &destroyCommand{
    87  		api:        api,
    88  		clock:      clk,
    89  		configAPI:  configAPI,
    90  		storageAPI: storageAPI,
    91  	}
    92  	cmd.SetClientStore(store)
    93  	cmd.SetModelRefresh(refreshFunc)
    94  	return modelcmd.Wrap(
    95  		cmd,
    96  		modelcmd.WrapSkipDefaultModel,
    97  		modelcmd.WrapSkipModelFlags,
    98  	)
    99  }
   100  
   101  type GrantCommand struct {
   102  	*grantCommand
   103  }
   104  
   105  type RevokeCommand struct {
   106  	*revokeCommand
   107  }
   108  
   109  // NewGrantCommandForTest returns a GrantCommand with the api provided as specified.
   110  func NewGrantCommandForTest(modelsApi GrantModelAPI, offersAPI GrantOfferAPI, store jujuclient.ClientStore) (cmd.Command, *GrantCommand) {
   111  	cmd := &grantCommand{
   112  		modelsApi: modelsApi,
   113  		offersApi: offersAPI,
   114  	}
   115  	cmd.SetClientStore(store)
   116  	return modelcmd.WrapController(cmd), &GrantCommand{cmd}
   117  }
   118  
   119  // NewRevokeCommandForTest returns an revokeCommand with the api provided as specified.
   120  func NewRevokeCommandForTest(modelsApi RevokeModelAPI, offersAPI RevokeOfferAPI, store jujuclient.ClientStore) (cmd.Command, *RevokeCommand) {
   121  	cmd := &revokeCommand{
   122  		modelsApi: modelsApi,
   123  		offersApi: offersAPI,
   124  	}
   125  	cmd.SetClientStore(store)
   126  	return modelcmd.WrapController(cmd), &RevokeCommand{cmd}
   127  }
   128  
   129  type GrantCloudCommand struct {
   130  	*grantCloudCommand
   131  }
   132  
   133  type RevokeCloudCommand struct {
   134  	*revokeCloudCommand
   135  }
   136  
   137  // NewGrantCloudCommandForTest returns a grantCloudCommand with the api provided as specified.
   138  func NewGrantCloudCommandForTest(cloudsApi GrantCloudAPI, store jujuclient.ClientStore) (cmd.Command, *GrantCloudCommand) {
   139  	cmd := &grantCloudCommand{
   140  		cloudsApi: cloudsApi,
   141  	}
   142  	cmd.SetClientStore(store)
   143  	return modelcmd.WrapController(cmd), &GrantCloudCommand{cmd}
   144  }
   145  
   146  // NewRevokeCloudCommandForTest returns a revokeCloudCommand with the api provided as specified.
   147  func NewRevokeCloudCommandForTest(cloudsApi RevokeCloudAPI, store jujuclient.ClientStore) (cmd.Command, *RevokeCloudCommand) {
   148  	cmd := &revokeCloudCommand{
   149  		cloudsApi: cloudsApi,
   150  	}
   151  	cmd.SetClientStore(store)
   152  	return modelcmd.WrapController(cmd), &RevokeCloudCommand{cmd}
   153  }
   154  
   155  func NewModelSetConstraintsCommandForTest() cmd.Command {
   156  	cmd := &modelSetConstraintsCommand{}
   157  	cmd.SetClientStore(jujuclienttesting.MinimalStore())
   158  	return modelcmd.Wrap(cmd)
   159  }
   160  
   161  func NewModelGetConstraintsCommandForTest() cmd.Command {
   162  	cmd := &modelGetConstraintsCommand{}
   163  	cmd.SetClientStore(jujuclienttesting.MinimalStore())
   164  	return modelcmd.Wrap(cmd)
   165  }
   166  
   167  var GetBudgetAPIClient = &getBudgetAPIClient
   168  
   169  // NewModelCredentialCommandForTest returns a ModelCredentialCommand with the api provided as specified.
   170  func NewModelCredentialCommandForTest(modelClient ModelCredentialAPI, cloudClient CloudAPI, rootFunc func() (base.APICallCloser, error), store jujuclient.ClientStore) cmd.Command {
   171  	cmd := &modelCredentialCommand{
   172  		newModelCredentialAPIFunc: func(root base.APICallCloser) ModelCredentialAPI {
   173  			return modelClient
   174  		},
   175  		newCloudAPIFunc: func(root base.APICallCloser) CloudAPI {
   176  			return cloudClient
   177  		},
   178  		newAPIRootFunc: rootFunc,
   179  	}
   180  	cmd.SetClientStore(store)
   181  	return modelcmd.Wrap(cmd)
   182  }
   183  
   184  func NewAddGenerationCommandForTest(api AddGenerationCommandAPI, store jujuclient.ClientStore) cmd.Command {
   185  	cmd := &addGenerationCommand{
   186  		api: api,
   187  	}
   188  	cmd.SetClientStore(store)
   189  	return modelcmd.Wrap(cmd)
   190  }
   191  
   192  func NewCancelGenerationCommandForTest(api CancelGenerationCommandAPI, store jujuclient.ClientStore) cmd.Command {
   193  	cmd := &cancelGenerationCommand{
   194  		api: api,
   195  	}
   196  	cmd.SetClientStore(store)
   197  	return modelcmd.Wrap(cmd)
   198  }
   199  
   200  func NewAdvanceGenerationCommandForTest(api AdvanceGenerationCommandAPI, store jujuclient.ClientStore) cmd.Command {
   201  	cmd := &advanceGenerationCommand{
   202  		api: api,
   203  	}
   204  	cmd.SetClientStore(store)
   205  	return modelcmd.Wrap(cmd)
   206  }
   207  
   208  func NewSwitchGenerationCommandForTest(api SwitchGenerationCommandAPI, store jujuclient.ClientStore) cmd.Command {
   209  	cmd := &switchGenerationCommand{
   210  		api: api,
   211  	}
   212  	cmd.SetClientStore(store)
   213  	return modelcmd.Wrap(cmd)
   214  }