github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/testing/errors.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "fmt" 8 "reflect" 9 10 jc "github.com/juju/testing/checkers" 11 gc "gopkg.in/check.v1" 12 13 "github.com/juju/juju/apiserver/params" 14 ) 15 16 var ErrUnauthorized = ¶ms.Error{ 17 Message: "permission denied", 18 Code: params.CodeUnauthorized, 19 } 20 21 func NotFoundError(prefixMessage string) *params.Error { 22 return ¶ms.Error{ 23 Message: fmt.Sprintf("%s not found", prefixMessage), 24 Code: params.CodeNotFound, 25 } 26 } 27 28 func NotProvisionedError(machineId string) *params.Error { 29 return ¶ms.Error{ 30 Message: fmt.Sprintf("machine %s not provisioned", machineId), 31 Code: params.CodeNotProvisioned, 32 } 33 } 34 35 func NotAssignedError(unitName string) *params.Error { 36 return ¶ms.Error{ 37 Message: fmt.Sprintf("unit %q is not assigned to a machine", unitName), 38 Code: params.CodeNotAssigned, 39 } 40 } 41 42 func AlreadyExistsError(what string) *params.Error { 43 return ¶ms.Error{ 44 Message: fmt.Sprintf("%s already exists", what), 45 Code: params.CodeAlreadyExists, 46 } 47 } 48 49 func ServerError(message string) *params.Error { 50 return ¶ms.Error{ 51 Message: message, 52 Code: "", 53 } 54 } 55 56 func PrefixedError(prefix, message string) *params.Error { 57 return ServerError(prefix + message) 58 } 59 60 func AssertNotImplemented(c *gc.C, apiFacade interface{}, methodName string) { 61 val := reflect.ValueOf(apiFacade) 62 c.Assert(val.IsValid(), jc.IsTrue) 63 indir := reflect.Indirect(val) 64 c.Assert(indir.IsValid(), jc.IsTrue) 65 method := indir.MethodByName(methodName) 66 c.Assert(method.IsValid(), jc.IsFalse) 67 }