Skip to content

Commit

Permalink
Fix the tests for migration target
Browse files Browse the repository at this point in the history
Ensure that we test the slice rather than the integer. This is ensures
we can view it as a sliding window.
  • Loading branch information
SimonRichardson committed Nov 29, 2023
1 parent 0069467 commit 06b2faa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions api/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (*ImportSuite) TestImports(c *gc.C) {
"api/base",
"api/watcher",
"core/arch",
"core/backups",
"core/base",
"core/constraints",
"core/database",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ func (s *Suite) TestFacadeRegistered(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)

api, err := aFactory(&facadetest.Context{
State_: s.State,
Auth_: s.authorizer,
State_: s.State,
Auth_: s.authorizer,
ServiceFactory_: servicefactorytesting.NewTestingServiceFactory(),
})
c.Assert(err, jc.ErrorIsNil)
c.Assert(api, gc.FitsTypeOf, new(migrationtarget.API))
Expand Down
3 changes: 2 additions & 1 deletion apiserver/facades/controller/migrationtarget/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ func newFacade(ctx facade.Context, facadeVersions facades.FacadeVersions) (*API,
credentialcommon.CredentialInvalidatorGetter(ctx),
stateenvirons.GetNewEnvironFunc(environs.New),
stateenvirons.GetNewCAASBrokerFunc(caas.New),
facadeVersions)
facadeVersions,
)
}
26 changes: 13 additions & 13 deletions apiserver/facadeversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/juju/juju/api"
"github.com/juju/juju/apiserver"
"github.com/juju/juju/core/facades"
coretesting "github.com/juju/juju/testing"
)

Expand Down Expand Up @@ -52,24 +53,24 @@ func (s *facadeVersionSuite) TestFacadeVersionsMatchServerVersions(c *gc.C) {
c.Check(apiFacadeVersions, jc.DeepEquals, serverFacadeBestVersions)
}

// TestClient3xSupport checks that the client facade supports the 3.x for
// certain tasks. You must be very careful when removing support for facades
// TestClientSupport checks that the client facade supports the 3.x and 4.x
// for certain tasks. You must be very careful when removing support for facades
// as it can break model migrations, upgrades, and state reports.
func (s *facadeVersionSuite) TestClient3xSupport(c *gc.C) {
func (s *facadeVersionSuite) TestClientSupport(c *gc.C) {
tests := []struct {
facadeName string
summary string
apiClientVersion int
apiClientVersion facades.FacadeVersion
}{
{
facadeName: "Client",
summary: "Ensure that the Client facade supports 3.x for status requests",
apiClientVersion: 6,
apiClientVersion: []int{6},
},
{
facadeName: "ModelManager",
summary: "Ensure that the ModelManager facade supports 3.x for model migration and status requests",
apiClientVersion: 9,
apiClientVersion: []int{9},
},
}
for _, test := range tests {
Expand All @@ -88,18 +89,17 @@ var Contains gc.Checker = &containsChecker{
}

func (checker *containsChecker) Check(params []interface{}, names []string) (result bool, err string) {
expected, ok := params[1].(int)
expected, ok := params[1].(facades.FacadeVersion)
if !ok {
return false, "expected must be a string"
return false, "expected must be a int"
}

obtained, ok := params[0].([]int)
obtained, ok := params[0].(facades.FacadeVersion)
if ok {
for _, v := range obtained {
if v == expected {
return true, ""
}
if set.NewInts(expected...).Intersection(set.NewInts(obtained...)).Size() > 0 {
return true, ""
}

return false, ""
}

Expand Down

0 comments on commit 06b2faa

Please sign in to comment.