github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/lxd/errors_test.go (about)

     1  // Copyright 2018 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package lxd
     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/testing"
    12  )
    13  
    14  type ErrorSuite struct {
    15  	testing.BaseSuite
    16  }
    17  
    18  var _ = gc.Suite(&ErrorSuite{})
    19  
    20  func (s *ErrorSuite) TestIsUnauthorisedError(c *gc.C) {
    21  	err := errors.New("not authorized")
    22  	c.Assert(IsAuthorisationFailure(err), jc.IsTrue)
    23  	c.Assert(IsAuthorisationFailure(errors.Cause(err)), jc.IsTrue)
    24  
    25  	traced := errors.Trace(err)
    26  	c.Assert(IsAuthorisationFailure(traced), jc.IsTrue)
    27  
    28  	annotated := errors.Annotate(err, "testing is great")
    29  	c.Assert(IsAuthorisationFailure(annotated), jc.IsTrue)
    30  }
    31  
    32  func (s *ErrorSuite) TestNotUnauthorisedError(c *gc.C) {
    33  	err := errors.New("everything is fine")
    34  	c.Assert(IsAuthorisationFailure(err), jc.IsFalse)
    35  
    36  	c.Assert(IsAuthorisationFailure(nil), jc.IsFalse)
    37  }