github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/apiserver/restrict_upgrades_test.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package apiserver_test
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	jc "github.com/juju/testing/checkers"
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/apiserver"
    12  	"github.com/juju/juju/rpc/params"
    13  	"github.com/juju/juju/testing"
    14  )
    15  
    16  type restrictUpgradesSuite struct {
    17  	testing.BaseSuite
    18  }
    19  
    20  var _ = gc.Suite(&restrictUpgradesSuite{})
    21  
    22  func (r *restrictUpgradesSuite) TestAllowedMethods(c *gc.C) {
    23  	root := apiserver.TestingUpgradingRoot()
    24  	checkAllowed := func(facade, method string, version int) {
    25  		caller, err := root.FindMethod(facade, version, method)
    26  		c.Check(err, jc.ErrorIsNil)
    27  		c.Check(caller, gc.NotNil)
    28  	}
    29  	checkAllowed("Client", "FullStatus", clientFacadeVersion)
    30  	checkAllowed("SSHClient", "PublicAddress", sshClientFacadeVersion)
    31  	checkAllowed("SSHClient", "Proxy", sshClientFacadeVersion)
    32  	checkAllowed("Pinger", "Ping", pingerFacadeVersion)
    33  }
    34  
    35  func (r *restrictUpgradesSuite) TestFindDisallowedMethod(c *gc.C) {
    36  	root := apiserver.TestingUpgradingRoot()
    37  	caller, err := root.FindMethod("Client", clientFacadeVersion, "ModelSet")
    38  	c.Assert(errors.Cause(err), gc.Equals, params.UpgradeInProgressError)
    39  	c.Assert(caller, gc.IsNil)
    40  }