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

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package application
     5  
     6  import (
     7  	"github.com/juju/cmd"
     8  
     9  	"github.com/juju/juju/api"
    10  	"github.com/juju/juju/api/base"
    11  	"github.com/juju/juju/cmd/modelcmd"
    12  	"github.com/juju/juju/jujuclient"
    13  	"github.com/juju/juju/resource/resourceadapters"
    14  )
    15  
    16  type RemoveApplicationAPI removeApplicationAPI
    17  
    18  func NewUpgradeCharmCommandForTest(
    19  	store jujuclient.ClientStore,
    20  	apiOpen api.OpenFunc,
    21  	deployResources resourceadapters.DeployResourcesFunc,
    22  	resolveCharm ResolveCharmFunc,
    23  	newCharmAdder NewCharmAdderFunc,
    24  	newCharmClient func(base.APICallCloser) CharmClient,
    25  	newCharmUpgradeClient func(base.APICallCloser) CharmAPIClient,
    26  	newModelConfigGetter func(base.APICallCloser) ModelConfigGetter,
    27  	newResourceLister func(base.APICallCloser) (ResourceLister, error),
    28  	charmStoreURLGetter func(base.APICallCloser) (string, error),
    29  ) cmd.Command {
    30  	cmd := &upgradeCharmCommand{
    31  		DeployResources:       deployResources,
    32  		ResolveCharm:          resolveCharm,
    33  		NewCharmAdder:         newCharmAdder,
    34  		NewCharmClient:        newCharmClient,
    35  		NewCharmUpgradeClient: newCharmUpgradeClient,
    36  		NewModelConfigGetter:  newModelConfigGetter,
    37  		NewResourceLister:     newResourceLister,
    38  		CharmStoreURLGetter:   charmStoreURLGetter,
    39  	}
    40  	cmd.SetClientStore(store)
    41  	cmd.SetAPIOpen(apiOpen)
    42  	return modelcmd.Wrap(cmd)
    43  }
    44  
    45  // NewResolvedCommandForTest returns a ResolvedCommand with the api provided as specified.
    46  func NewResolvedCommandForTest(applicationResolveAPI applicationResolveAPI, clientAPI clientAPI, store jujuclient.ClientStore) modelcmd.ModelCommand {
    47  	cmd := &resolvedCommand{applicationResolveAPI: applicationResolveAPI, clientAPI: clientAPI}
    48  	cmd.SetClientStore(store)
    49  	return modelcmd.Wrap(cmd)
    50  }
    51  
    52  // NewAddUnitCommandForTest returns an AddUnitCommand with the api provided as specified.
    53  func NewAddUnitCommandForTest(api applicationAddUnitAPI, store jujuclient.ClientStore) modelcmd.ModelCommand {
    54  	cmd := &addUnitCommand{api: api}
    55  	cmd.SetClientStore(store)
    56  	return modelcmd.Wrap(cmd)
    57  }
    58  
    59  // NewAddUnitCommandForTest returns an AddUnitCommand with the api provided as specified as well as overrides the refresh function.
    60  func NewAddUnitCommandForTestWithRefresh(api applicationAddUnitAPI, store jujuclient.ClientStore, refreshFunc func(jujuclient.ClientStore, string) error) modelcmd.ModelCommand {
    61  	cmd := &addUnitCommand{api: api}
    62  	cmd.SetClientStore(store)
    63  	cmd.SetModelRefresh(refreshFunc)
    64  	return modelcmd.Wrap(cmd)
    65  }
    66  
    67  // NewRemoveUnitCommandForTest returns a RemoveUnitCommand with the api provided as specified.
    68  func NewRemoveUnitCommandForTest(api removeApplicationAPI, store jujuclient.ClientStore) modelcmd.ModelCommand {
    69  	cmd := &removeUnitCommand{api: api}
    70  	cmd.SetClientStore(store)
    71  	return modelcmd.Wrap(cmd)
    72  }
    73  
    74  // NewAddRelationCommandForTest returns an AddRelationCommand with the api provided as specified.
    75  func NewAddRelationCommandForTest(addAPI applicationAddRelationAPI, consumeAPI applicationConsumeDetailsAPI) modelcmd.ModelCommand {
    76  	cmd := &addRelationCommand{addRelationAPI: addAPI, consumeDetailsAPI: consumeAPI}
    77  	return modelcmd.Wrap(cmd)
    78  }
    79  
    80  // NewRemoveRelationCommandForTest returns an RemoveRelationCommand with the api provided as specified.
    81  func NewRemoveRelationCommandForTest(api ApplicationDestroyRelationAPI, store jujuclient.ClientStore) modelcmd.ModelCommand {
    82  	cmd := &removeRelationCommand{newAPIFunc: func() (ApplicationDestroyRelationAPI, error) {
    83  		return api, nil
    84  	}}
    85  	cmd.SetClientStore(store)
    86  	return modelcmd.Wrap(cmd)
    87  }
    88  
    89  // NewConsumeCommandForTest returns a ConsumeCommand with the specified api.
    90  func NewConsumeCommandForTest(
    91  	store jujuclient.ClientStore,
    92  	sourceAPI applicationConsumeDetailsAPI,
    93  	targetAPI applicationConsumeAPI,
    94  ) cmd.Command {
    95  	c := &consumeCommand{sourceAPI: sourceAPI, targetAPI: targetAPI}
    96  	c.SetClientStore(store)
    97  	return modelcmd.Wrap(c)
    98  }
    99  
   100  // NewSetSeriesCommandForTest returns a SetSeriesCommand with the specified api.
   101  func NewSetSeriesCommandForTest(
   102  	seriesAPI setSeriesAPI,
   103  	store jujuclient.ClientStore,
   104  ) modelcmd.ModelCommand {
   105  	cmd := &setSeriesCommand{
   106  		setSeriesClient: seriesAPI,
   107  	}
   108  	cmd.SetClientStore(store)
   109  	return modelcmd.Wrap(cmd)
   110  }
   111  
   112  // NewSuspendRelationCommandForTest returns a SuspendRelationCommand with the api provided as specified.
   113  func NewSuspendRelationCommandForTest(api SetRelationSuspendedAPI, store jujuclient.ClientStore) modelcmd.ModelCommand {
   114  	cmd := &suspendRelationCommand{newAPIFunc: func() (SetRelationSuspendedAPI, error) {
   115  		return api, nil
   116  	}}
   117  	cmd.SetClientStore(store)
   118  	return modelcmd.Wrap(cmd)
   119  }
   120  
   121  // NewResumeRelationCommandForTest returns a ResumeRelationCommand with the api provided as specified.
   122  func NewResumeRelationCommandForTest(api SetRelationSuspendedAPI, store jujuclient.ClientStore) modelcmd.ModelCommand {
   123  	cmd := &resumeRelationCommand{newAPIFunc: func() (SetRelationSuspendedAPI, error) {
   124  		return api, nil
   125  	}}
   126  	cmd.SetClientStore(store)
   127  	return modelcmd.Wrap(cmd)
   128  }
   129  
   130  // NewRemoveSaasCommandForTest returns a RemoveSaasCommand with the api provided as specified.
   131  func NewRemoveSaasCommandForTest(api RemoveSaasAPI, store jujuclient.ClientStore) modelcmd.ModelCommand {
   132  	cmd := &removeSaasCommand{newAPIFunc: func() (RemoveSaasAPI, error) {
   133  		return api, nil
   134  	}}
   135  	cmd.SetClientStore(store)
   136  	return modelcmd.Wrap(cmd)
   137  }
   138  
   139  // NewScaleCommandForTest returns a ScaleCommand with the api provided as specified.
   140  func NewScaleCommandForTest(api scaleApplicationAPI, store jujuclient.ClientStore) modelcmd.ModelCommand {
   141  	cmd := &scaleApplicationCommand{newAPIFunc: func() (scaleApplicationAPI, error) {
   142  		return api, nil
   143  	}}
   144  	cmd.SetClientStore(store)
   145  	return modelcmd.Wrap(cmd)
   146  }
   147  
   148  func NewBundleDiffCommandForTest(api base.APICallCloser, charmStore BundleResolver, store jujuclient.ClientStore) modelcmd.ModelCommand {
   149  	cmd := &bundleDiffCommand{
   150  		_apiRoot:    api,
   151  		_charmStore: charmStore,
   152  	}
   153  	cmd.SetClientStore(store)
   154  	return modelcmd.Wrap(cmd)
   155  }
   156  
   157  func NewShowCommandForTest(api ApplicationsInfoAPI, store jujuclient.ClientStore) cmd.Command {
   158  	cmd := &showApplicationCommand{newAPIFunc: func() (ApplicationsInfoAPI, error) {
   159  		return api, nil
   160  	}}
   161  	cmd.SetClientStore(store)
   162  	return modelcmd.Wrap(cmd)
   163  }