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

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package caasfirewaller_test
     5  
     6  import (
     7  	"github.com/juju/testing"
     8  
     9  	"github.com/juju/juju/api/base"
    10  	"github.com/juju/juju/caas"
    11  	"github.com/juju/juju/core/application"
    12  	"github.com/juju/juju/core/life"
    13  	"github.com/juju/juju/core/watcher"
    14  	"github.com/juju/juju/core/watcher/watchertest"
    15  	"github.com/juju/juju/worker/caasfirewaller"
    16  )
    17  
    18  type fakeAPICaller struct {
    19  	base.APICaller
    20  }
    21  
    22  type fakeBroker struct {
    23  	caas.Broker
    24  }
    25  
    26  type fakeClient struct {
    27  	caasfirewaller.Client
    28  }
    29  
    30  type mockServiceExposer struct {
    31  	testing.Stub
    32  	exposed   chan<- struct{}
    33  	unexposed chan<- struct{}
    34  }
    35  
    36  func (m *mockServiceExposer) ExposeService(appName string, resourceTags map[string]string, config application.ConfigAttributes) error {
    37  	m.MethodCall(m, "ExposeService", appName, resourceTags, config)
    38  	m.exposed <- struct{}{}
    39  	return m.NextErr()
    40  }
    41  
    42  func (m *mockServiceExposer) UnexposeService(appName string) error {
    43  	m.MethodCall(m, "UnexposeService", appName)
    44  	m.unexposed <- struct{}{}
    45  	return m.NextErr()
    46  }
    47  
    48  type mockApplicationGetter struct {
    49  	testing.Stub
    50  	allWatcher *watchertest.MockStringsWatcher
    51  	appWatcher *watchertest.MockNotifyWatcher
    52  	exposed    bool
    53  }
    54  
    55  func (m *mockApplicationGetter) WatchApplications() (watcher.StringsWatcher, error) {
    56  	m.MethodCall(m, "WatchApplications")
    57  	if err := m.NextErr(); err != nil {
    58  		return nil, err
    59  	}
    60  	return m.allWatcher, nil
    61  }
    62  
    63  func (m *mockApplicationGetter) WatchApplication(appName string) (watcher.NotifyWatcher, error) {
    64  	m.MethodCall(m, "WatchApplication", appName)
    65  	if err := m.NextErr(); err != nil {
    66  		return nil, err
    67  	}
    68  	return m.appWatcher, nil
    69  }
    70  
    71  func (m *mockApplicationGetter) IsExposed(appName string) (bool, error) {
    72  	m.MethodCall(m, "IsExposed", appName)
    73  	if err := m.NextErr(); err != nil {
    74  		return false, err
    75  	}
    76  	return m.exposed, nil
    77  }
    78  
    79  func (a *mockApplicationGetter) ApplicationConfig(appName string) (application.ConfigAttributes, error) {
    80  	a.MethodCall(a, "ApplicationConfig", appName)
    81  	return application.ConfigAttributes{"juju-external-hostname": "exthost"}, a.NextErr()
    82  }
    83  
    84  type mockLifeGetter struct {
    85  	testing.Stub
    86  	life life.Value
    87  }
    88  
    89  func (m *mockLifeGetter) Life(entityName string) (life.Value, error) {
    90  	m.MethodCall(m, "Life", entityName)
    91  	if err := m.NextErr(); err != nil {
    92  		return "", err
    93  	}
    94  	return m.life, nil
    95  }