github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/apiserver/facades/client/bundle/mock_test.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package bundle_test 5 6 import ( 7 "github.com/juju/charm/v12" 8 "github.com/juju/description/v5" 9 "github.com/juju/testing" 10 11 "github.com/juju/juju/apiserver/facades/client/bundle" 12 "github.com/juju/juju/core/network" 13 "github.com/juju/juju/state" 14 ) 15 16 type mockCharm struct { 17 charm.Charm 18 } 19 20 func (c *mockCharm) Config() *charm.Config { 21 return &charm.Config{Options: map[string]charm.Option{ 22 "foo": {Default: "bar"}, 23 }} 24 } 25 26 type mockState struct { 27 testing.Stub 28 bundle.Backend 29 model description.Model 30 charm *mockCharm 31 Spaces map[string]string 32 } 33 34 func (m *mockState) ExportPartial(config state.ExportConfig) (description.Model, error) { 35 m.MethodCall(m, "ExportPartial", config) 36 if err := m.NextErr(); err != nil { 37 return nil, err 38 } 39 40 return m.model, nil 41 } 42 43 func (m *mockState) GetExportConfig() state.ExportConfig { 44 return state.ExportConfig{ 45 SkipActions: true, 46 SkipCloudImageMetadata: true, 47 SkipCredentials: true, 48 SkipIPAddresses: true, 49 SkipSSHHostKeys: true, 50 SkipStatusHistory: true, 51 SkipLinkLayerDevices: true, 52 } 53 } 54 55 func (m *mockState) Charm(url string) (charm.Charm, error) { 56 return m.charm, nil 57 } 58 59 func (m *mockState) AllSpaceInfos() (network.SpaceInfos, error) { 60 result := make(network.SpaceInfos, len(m.Spaces)) 61 i := 0 62 for id, name := range m.Spaces { 63 result[i] = network.SpaceInfo{ID: id, Name: network.SpaceName(name)} 64 i += 1 65 } 66 return result, nil 67 } 68 69 func (m *mockState) Space(_ string) (*state.Space, error) { 70 return nil, nil 71 } 72 73 func newMockState() *mockState { 74 st := &mockState{ 75 Stub: testing.Stub{}, 76 } 77 st.Spaces = make(map[string]string) 78 return st 79 }