github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/caasoperator/mock_test.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package caasoperator_test
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/juju/juju/core/life"
     9  	"github.com/juju/juju/core/model"
    10  	"github.com/juju/juju/worker/fortress"
    11  	"github.com/juju/proxy"
    12  	"github.com/juju/testing"
    13  	"github.com/juju/version"
    14  	"gopkg.in/juju/charm.v6"
    15  	"gopkg.in/juju/names.v2"
    16  
    17  	"github.com/juju/juju/agent"
    18  	"github.com/juju/juju/api/base"
    19  	"github.com/juju/juju/core/status"
    20  	"github.com/juju/juju/core/watcher"
    21  	"github.com/juju/juju/core/watcher/watchertest"
    22  	"github.com/juju/juju/downloader"
    23  	coretesting "github.com/juju/juju/testing"
    24  	"github.com/juju/juju/worker/caasoperator"
    25  )
    26  
    27  var (
    28  	gitlabCharmURL = charm.MustParseURL("cs:gitlab-1")
    29  	gitlabSettings = charm.Settings{"k": 123}
    30  
    31  	fakeCharmContent    = []byte("abc")
    32  	fakeCharmSHA256     = "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
    33  	fakeModifiedVersion = 666
    34  )
    35  
    36  type fakeAgent struct {
    37  	agent.Agent
    38  	config fakeAgentConfig
    39  }
    40  
    41  func (a *fakeAgent) CurrentConfig() agent.Config {
    42  	return &a.config
    43  }
    44  
    45  type fakeAgentConfig struct {
    46  	agent.Config
    47  	dataDir string
    48  	tag     names.Tag
    49  }
    50  
    51  func (c *fakeAgentConfig) Tag() names.Tag {
    52  	return c.tag
    53  }
    54  
    55  func (c *fakeAgentConfig) Model() names.ModelTag {
    56  	return coretesting.ModelTag
    57  }
    58  
    59  func (c *fakeAgentConfig) DataDir() string {
    60  	return c.dataDir
    61  }
    62  
    63  type fakeAPICaller struct {
    64  	base.APICaller
    65  }
    66  
    67  type fakeClient struct {
    68  	testing.Stub
    69  	caasoperator.Client
    70  	unitsWatcher       *watchertest.MockStringsWatcher
    71  	watcher            *watchertest.MockNotifyWatcher
    72  	applicationWatched chan struct{}
    73  	unitRemoved        chan struct{}
    74  	life               life.Value
    75  }
    76  
    77  func (c *fakeClient) SetStatus(application string, status status.Status, message string, data map[string]interface{}) error {
    78  	c.MethodCall(c, "SetStatus", application, status, message, data)
    79  	return c.NextErr()
    80  }
    81  
    82  func (c *fakeClient) Charm(application string) (*charm.URL, bool, string, int, error) {
    83  	c.MethodCall(c, "Charm", application)
    84  	if err := c.NextErr(); err != nil {
    85  		return nil, false, "", 0, err
    86  	}
    87  	return gitlabCharmURL, true, fakeCharmSHA256, fakeModifiedVersion, nil
    88  }
    89  
    90  func (c *fakeClient) SetPodSpec(entityName, spec string) error {
    91  	c.MethodCall(c, "SetPodSpec", entityName, spec)
    92  	return c.NextErr()
    93  }
    94  
    95  func (c *fakeClient) CharmConfig(application string) (charm.Settings, error) {
    96  	c.MethodCall(c, "CharmConfig", application)
    97  	if err := c.NextErr(); err != nil {
    98  		return nil, err
    99  	}
   100  	return gitlabSettings, nil
   101  }
   102  
   103  func (c *fakeClient) WatchCharmConfig(application string) (watcher.NotifyWatcher, error) {
   104  	return nil, errors.NotSupportedf("watch charm config")
   105  }
   106  
   107  func (c *fakeClient) WatchUnits(application string) (watcher.StringsWatcher, error) {
   108  	c.MethodCall(c, "WatchUnits", application)
   109  	if err := c.NextErr(); err != nil {
   110  		return nil, err
   111  	}
   112  	return c.unitsWatcher, nil
   113  }
   114  
   115  func (c *fakeClient) Watch(application string) (watcher.NotifyWatcher, error) {
   116  	c.MethodCall(c, "Watch", application)
   117  	if err := c.NextErr(); err != nil {
   118  		return nil, err
   119  	}
   120  	c.applicationWatched <- struct{}{}
   121  	return c.watcher, nil
   122  }
   123  
   124  func (c *fakeClient) RemoveUnit(unit string) error {
   125  	c.MethodCall(c, "RemoveUnit", unit)
   126  	c.unitRemoved <- struct{}{}
   127  	return c.NextErr()
   128  }
   129  
   130  func (c *fakeClient) SetVersion(appName string, v version.Binary) error {
   131  	c.MethodCall(c, "SetVersion", appName, v)
   132  	return c.NextErr()
   133  }
   134  
   135  func (c *fakeClient) Life(entity string) (life.Value, error) {
   136  	c.MethodCall(c, "Life", entity)
   137  	if err := c.NextErr(); err != nil {
   138  		return life.Dead, err
   139  	}
   140  	return c.life, nil
   141  }
   142  
   143  func (c *fakeClient) APIAddresses() ([]string, error) {
   144  	c.MethodCall(c, "APIAddresses", nil)
   145  	if err := c.NextErr(); err != nil {
   146  		return nil, err
   147  	}
   148  	return []string{"10.0.0.1:10000"}, nil
   149  }
   150  
   151  func (c *fakeClient) ProxySettings() (proxy.Settings, error) {
   152  	c.MethodCall(c, "ProxySettings", nil)
   153  	if err := c.NextErr(); err != nil {
   154  		return proxy.Settings{}, err
   155  	}
   156  	return proxy.Settings{Http: "http.proxy"}, nil
   157  }
   158  
   159  func (c *fakeClient) Model() (*model.Model, error) {
   160  	return &model.Model{
   161  		Name: "gitlab-model",
   162  	}, nil
   163  }
   164  
   165  type fakeDownloader struct {
   166  	testing.Stub
   167  	path string
   168  }
   169  
   170  func (d *fakeDownloader) Download(req downloader.Request) (string, error) {
   171  	d.MethodCall(d, "Download", req)
   172  	if err := d.NextErr(); err != nil {
   173  		return "", err
   174  	}
   175  	return d.path, nil
   176  }
   177  
   178  type mockCharmDirGuard struct {
   179  	fortress.Guard
   180  	testing.Stub
   181  }
   182  
   183  func (l *mockCharmDirGuard) Unlock() error {
   184  	l.MethodCall(l, "Unlock")
   185  	return l.NextErr()
   186  }
   187  
   188  func (l *mockCharmDirGuard) Lockdown(abort fortress.Abort) error {
   189  	l.MethodCall(l, "Lockdown", abort)
   190  	return l.NextErr()
   191  }