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