github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/openstack/errors_test.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package openstack 5 6 import ( 7 "github.com/juju/errors" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 gooseerrors "gopkg.in/goose.v2/errors" 11 12 "github.com/juju/juju/testing" 13 ) 14 15 type ErrorSuite struct { 16 testing.BaseSuite 17 } 18 19 var _ = gc.Suite(&ErrorSuite{}) 20 21 func (s *ErrorSuite) TestIsUnauthorisedError(c *gc.C) { 22 e := gooseerrors.NewUnauthorisedf(nil, "", "not on") 23 c.Assert(IsAuthorisationFailure(e), jc.IsTrue) 24 c.Assert(IsAuthorisationFailure(errors.Cause(e)), jc.IsTrue) 25 26 traced := errors.Trace(e) 27 c.Assert(IsAuthorisationFailure(traced), jc.IsTrue) 28 29 annotated := errors.Annotatef(e, "more and more") 30 c.Assert(IsAuthorisationFailure(annotated), jc.IsTrue) 31 } 32 33 func (s *ErrorSuite) TestIsNotUnauthorisedErro(c *gc.C) { 34 e := errors.New("fluffy") 35 c.Assert(IsAuthorisationFailure(e), jc.IsFalse) 36 37 c.Assert(IsAuthorisationFailure(nil), jc.IsFalse) 38 }