Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: rename-space #11143

Merged
merged 30 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
efd63f8
rename-space: init api creation
Jan 22, 2020
bb82252
rename-space: stubs to rename space
Jan 23, 2020
3016c35
rename-space: create initial rename code
Jan 23, 2020
d981a9a
rename-space: initial connection to apiserver
Jan 23, 2020
d8202a7
rename-space: initial working version
Jan 23, 2020
cf946ee
rename-space: rework initial model and indirection
Jan 23, 2020
a7c7194
rename space: resolve merge conflict
Jan 24, 2020
5020480
spaces environ: code to check whether cloud supports providerspaces +…
Jan 24, 2020
48c527f
spaces environ: update settings to take collection
Jan 24, 2020
669519e
spaces environ: redo interface and constraints db access
Jan 28, 2020
d950960
spaces api test: add test
Jan 28, 2020
bfa6bd8
state: change constraints to add another struct
Jan 28, 2020
4d1762d
state space: correct constraint handling
Jan 29, 2020
d11eba9
space: rework indirection. fix rest of comments
Jan 29, 2020
c55477b
space: fix existing unit tests
Jan 29, 2020
5a1ec3a
space apiserver test: add additional test for renaming case
Jan 30, 2020
3f3f389
space apiserver test: fix test
Jan 30, 2020
489965d
space: remove not needed method
Jan 30, 2020
6147288
space: fix renaming issues
Jan 30, 2020
81060f1
space: fix use correct DocID not ID
Jan 30, 2020
1723108
space rename: address simons review
Jan 30, 2020
d2db8e5
space rename: wordings
Jan 30, 2020
778d402
space rename: remove unneeded shim methods
Jan 30, 2020
6e173d5
space rename: add mock model and skip if not controllermodel
Jan 31, 2020
95da83f
space rename: fix copy pasta and ordering of test to ensure better re…
Jan 31, 2020
298e16b
space rename: add first review part of joe
Jan 31, 2020
a765b62
constraints spaces: add additional tests and add negation
Feb 4, 2020
b560fa4
refactoring of spaces
Feb 4, 2020
32eb198
apiserver spaces: error on alpha space
Feb 4, 2020
ed6ae8f
cmd spaces: fix removed to renamed
Feb 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions api/spaces/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package spaces

import (
"github.com/juju/juju/api/base"
)

func NewAPIFromCaller(caller base.FacadeCaller) *API {
return &API{
facade: caller,
}
}
22 changes: 22 additions & 0 deletions api/spaces/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,25 @@ func (api *API) ReloadSpaces() error {
}
return err
}

func (api *API) RenameSpace(oldName string, newName string) error {
var response params.ErrorResults
spaceRenameParams := make([]params.RenameSpaceParams, 1)
spaceRename := params.RenameSpaceParams{
FromSpaceTag: names.NewSpaceTag(oldName).String(),
ToSpaceTag: names.NewSpaceTag(newName).String(),
}
spaceRenameParams[0] = spaceRename
args := params.RenameSpacesParams{SpacesRenames: spaceRenameParams}
err := api.facade.FacadeCall("RenameSpace", args, &response)
if err != nil {
if params.IsCodeNotSupported(err) {
return errors.NewNotSupported(nil, err.Error())
}
return errors.Trace(err)
}
if err := response.Combine(); err != nil {
return errors.Trace(err)
}
return nil
}
62 changes: 62 additions & 0 deletions api/spaces/spaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,79 @@ import (
"fmt"
"math/rand"

"github.com/golang/mock/gomock"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/juju/names.v3"

"github.com/juju/juju/api/base/mocks"
apitesting "github.com/juju/juju/api/base/testing"
"github.com/juju/juju/api/spaces"
"github.com/juju/juju/apiserver/params"
"github.com/juju/juju/core/network"
coretesting "github.com/juju/juju/testing"
)

// spacesSuite are using mocks instead of the apicaller stubs
type spacesSuite struct {
fCaller *mocks.MockFacadeCaller
API *spaces.API
}

var _ = gc.Suite(&spacesSuite{})

func (s *spacesSuite) SetUpTest(c *gc.C) {
}

func (s *spacesSuite) TearDownTest(c *gc.C) {
s.fCaller = nil
}

func (s *spacesSuite) setUpMocks(c *gc.C) *gomock.Controller {
ctrl := gomock.NewController(c)

caller := mocks.NewMockAPICallCloser(ctrl)
caller.EXPECT().BestFacadeVersion(gomock.Any()).Return(0).AnyTimes()

s.fCaller = mocks.NewMockFacadeCaller(ctrl)
s.fCaller.EXPECT().RawAPICaller().Return(caller).AnyTimes()
s.API = spaces.NewAPIFromCaller(s.fCaller)
return ctrl
}

func (s *spacesSuite) TestRenameSpace(c *gc.C) {
defer s.setUpMocks(c).Finish()
from, to := "from", "to"
resultSource := params.ErrorResults{}
args := params.RenameSpacesParams{SpacesRenames: []params.RenameSpaceParams{{
FromSpaceTag: names.NewSpaceTag(from).String(),
ToSpaceTag: names.NewSpaceTag(to).String(),
}}}
s.fCaller.EXPECT().FacadeCall("RenameSpace", args, gomock.Any()).SetArg(2, resultSource).Return(nil)

err := s.API.RenameSpace(from, to)
c.Assert(err, gc.IsNil)
}

func (s *spacesSuite) TestRenameSpaceError(c *gc.C) {
defer s.setUpMocks(c).Finish()
from, to := "from", "to"
resultSource := params.ErrorResults{Results: []params.ErrorResult{{
Error: &params.Error{
Message: "bam",
Code: "500",
},
}}}
args := params.RenameSpacesParams{SpacesRenames: []params.RenameSpaceParams{{
FromSpaceTag: names.NewSpaceTag(from).String(),
ToSpaceTag: names.NewSpaceTag(to).String(),
}}}
s.fCaller.EXPECT().FacadeCall("RenameSpace", args, gomock.Any()).SetArg(2, resultSource).Return(nil)

err := s.API.RenameSpace(from, to)
c.Assert(err, gc.ErrorMatches, "bam")
}

type SpacesSuite struct {
coretesting.BaseSuite

Expand Down
228 changes: 227 additions & 1 deletion apiserver/facades/client/spaces/mocks/package_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.