github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/api/uniter/sla_test.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package uniter_test
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  	"gopkg.in/juju/names.v2"
    10  
    11  	"github.com/juju/juju/api/base/testing"
    12  	"github.com/juju/juju/api/uniter"
    13  )
    14  
    15  type slaSuiteV4 struct {
    16  	uniterSuite
    17  }
    18  
    19  var _ = gc.Suite(&slaSuiteV4{})
    20  
    21  func (s *slaSuiteV4) SetUpTest(c *gc.C) {
    22  	s.uniterSuite.SetUpTest(c)
    23  	s.PatchValue(&uniter.NewState, uniter.NewStateV4)
    24  }
    25  
    26  func (s *slaSuiteV4) TestSetPodSpecApplication(c *gc.C) {
    27  	c.Skip("this API not present in V4")
    28  }
    29  
    30  func (s *slaSuiteV4) TestSLALevelOldFacadeVersion(c *gc.C) {
    31  	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
    32  		return nil
    33  	})
    34  	st := uniter.NewState(apiCaller, names.NewUnitTag("wordpress/0"))
    35  	level, err := st.SLALevel()
    36  	c.Assert(err, jc.ErrorIsNil)
    37  
    38  	// testing.APICallerFunc declared the BestFacadeVersion to be 0: that is why we
    39  	// expect "unsupported", because we are talking to an old apiserver.
    40  	c.Assert(level, gc.Equals, "unsupported")
    41  }
    42  
    43  type slaSuite struct {
    44  	uniterSuite
    45  }
    46  
    47  var _ = gc.Suite(&slaSuite{})
    48  
    49  func (s *slaSuite) TestSLALevel(c *gc.C) {
    50  	err := s.State.SetSLA("essential", "bob", []byte("creds"))
    51  	c.Assert(err, jc.ErrorIsNil)
    52  
    53  	level, err := s.uniter.SLALevel()
    54  	c.Assert(err, jc.ErrorIsNil)
    55  	c.Assert(level, gc.Equals, "essential")
    56  }