github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/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/errors" 8 "github.com/juju/testing" 9 10 "github.com/juju/juju/api/base" 11 "github.com/juju/juju/api/common/charms" 12 "github.com/juju/juju/caas" 13 "github.com/juju/juju/core/config" 14 "github.com/juju/juju/core/life" 15 "github.com/juju/juju/core/watcher" 16 "github.com/juju/juju/core/watcher/watchertest" 17 "github.com/juju/juju/worker/caasfirewaller" 18 ) 19 20 type fakeAPICaller struct { 21 base.APICaller 22 } 23 24 type fakeBroker struct { 25 caas.Broker 26 } 27 28 type fakeClient struct { 29 caasfirewaller.Client 30 } 31 32 type mockServiceExposer struct { 33 testing.Stub 34 exposed chan<- struct{} 35 unexposed chan<- struct{} 36 } 37 38 func (m *mockServiceExposer) ExposeService(appName string, resourceTags map[string]string, config config.ConfigAttributes) error { 39 m.MethodCall(m, "ExposeService", appName, resourceTags, config) 40 m.exposed <- struct{}{} 41 return m.NextErr() 42 } 43 44 func (m *mockServiceExposer) UnexposeService(appName string) error { 45 m.MethodCall(m, "UnexposeService", appName) 46 m.unexposed <- struct{}{} 47 return m.NextErr() 48 } 49 50 type mockApplicationGetter struct { 51 testing.Stub 52 allWatcher *watchertest.MockStringsWatcher 53 appWatcher *watchertest.MockNotifyWatcher 54 exposed bool 55 } 56 57 func (m *mockApplicationGetter) WatchApplications() (watcher.StringsWatcher, error) { 58 m.MethodCall(m, "WatchApplications") 59 if err := m.NextErr(); err != nil { 60 return nil, err 61 } 62 return m.allWatcher, nil 63 } 64 65 func (m *mockApplicationGetter) WatchApplication(appName string) (watcher.NotifyWatcher, error) { 66 m.MethodCall(m, "WatchApplication", appName) 67 if err := m.NextErr(); err != nil { 68 return nil, err 69 } 70 return m.appWatcher, nil 71 } 72 73 func (m *mockApplicationGetter) IsExposed(appName string) (bool, error) { 74 m.MethodCall(m, "IsExposed", appName) 75 if err := m.NextErr(); err != nil { 76 return false, err 77 } 78 return m.exposed, nil 79 } 80 81 func (a *mockApplicationGetter) ApplicationConfig(appName string) (config.ConfigAttributes, error) { 82 a.MethodCall(a, "ApplicationConfig", appName) 83 return config.ConfigAttributes{"juju-external-hostname": "exthost"}, a.NextErr() 84 } 85 86 type mockLifeGetter struct { 87 testing.Stub 88 life life.Value 89 } 90 91 func (m *mockLifeGetter) Life(entityName string) (life.Value, error) { 92 m.MethodCall(m, "Life", entityName) 93 if err := m.NextErr(); err != nil { 94 return "", err 95 } 96 return m.life, nil 97 } 98 99 type mockCharmGetter struct { 100 testing.Stub 101 charmInfo *charms.CharmInfo 102 } 103 104 func (m *mockCharmGetter) ApplicationCharmInfo(appName string) (*charms.CharmInfo, error) { 105 m.MethodCall(m, "ApplicationCharmInfo", appName) 106 if err := m.NextErr(); err != nil { 107 return nil, err 108 } 109 if m.charmInfo == nil { 110 return nil, errors.NotFoundf("application %q", appName) 111 } 112 return m.charmInfo, nil 113 }