-
Notifications
You must be signed in to change notification settings - Fork 5
/
tooling.go
218 lines (187 loc) · 7.53 KB
/
tooling.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package force
import (
"net/url"
"strings"
)
// ToolingService handles communication with the Tooling API methods
// of the Salesforce Tooling API.
type ToolingService struct {
client *Client
}
// DescribeGlobalResult represents the response of DescribeGlobal()
type DescribeGlobalResult struct {
Encoding string `json:"encoding"`
MaxBatchSize int `json:"maxBatchSize"`
SObjects []DescribeGlobalSObjectResult `json:"sobjects"`
}
// DescribeGlobalSObjectResult represents the properties for one of the objects
// available for your organization.
type DescribeGlobalSObjectResult struct {
Activateable bool `json:"activateable"`
Createable bool `json:"createable"`
Custom bool `json:"custom"`
CustomSetting bool `json:"customSetting"`
Deletable bool `json:"deletable"`
DeprecatedAndHidden bool `json:"deprecatedAndHidden"`
FeedEnabled bool `json:"feedEnabled"`
KeyPrefix string `json:"keyPrefix"`
Label string `json:"label"`
LabelPlural string `json:"labelPlural"`
Layoutable bool `json:"layoutable"`
Mergeable bool `json:"mergeable"`
Name string `json:"name"`
Queryable bool `json:"queryable"`
Replicateable bool `json:"replicateable"`
Retrieveable bool `json:"retrieveable"`
Searchable bool `json:"searchable"`
Triggerable bool `json:"triggerable"`
Undeletable bool `json:"undeletable"`
Updateable bool `json:"updateable"`
}
// DescribeGlobal lists the available Tooling API objects and their metadata
func (c *ToolingService) DescribeGlobal() (result DescribeGlobalResult, err error) {
req, err := c.client.NewRequest("GET", "/tooling/sobjects/", nil)
if err != nil {
return
}
err = c.client.Do(req, &result)
return
}
// ExecuteAnonymousResult specifies information about whether or not the
// compile and run of the code was successful
type ExecuteAnonymousResult struct {
Column int `json:"column"`
CompileProblem string `json:"compileProblem"`
Compiled bool `json:"compiled"`
ExceptionMessage string `json:"exceptionMessage"`
ExceptionStackTrace string `json:"exceptionStackTrace"`
Line int `json:"line"`
Success bool `json:"success"`
}
// ExecuteAnonymous executes the specified block of Apex anonymously and
// returns the result.
func (c *ToolingService) ExecuteAnonymous(apex string) (result ExecuteAnonymousResult, err error) {
req, err := c.client.NewRequest("GET", "/tooling/executeAnonymous/?anonymousBody="+url.QueryEscape(apex), nil)
if err != nil {
return
}
err = c.client.Do(req, &result)
return
}
// Query executes a query against a Tooling API object and returns data that
// matches the specified criteria.
func (c *ToolingService) Query(soql string, v interface{}) (err error) {
req, err := c.client.NewRequest("GET", "/tooling/query/?q="+url.QueryEscape(soql), nil)
if err != nil {
return
}
err = c.client.Do(req, &v)
return
}
// RunTestsResult contains information about the execution of unit tests,
// including whether unit tests were completed successfully, code coverage
// results, and failures.
type RunTestsResult struct {
ApexLogID string `json:"apexLogId"`
CodeCoverage []CodeCoverageResult `json:"codeCoverage"`
CodeCoverageWarnings []CodeCoverageWarning `json:"codeCoverageWarnings"`
Failures []RunTestFailure `json:"failures"`
NumFailures int `json:"numFailures"`
NumTestsRun int `json:"numTestsRun"`
Successes []RunTestSuccess `json:"successes"`
TotalTime float64 `json:"totalTime"`
}
// CodeCoverageResult contains the details of the code coverage for the
// specified unit tests.
type CodeCoverageResult struct {
DmlInfo []CodeLocation `json:"dmlInfo"`
ID string `json:"id"`
LocationsNotCovered []CodeLocation `json:"locationsNotCovered"`
MethodInfo []CodeLocation `json:"methodInfo"`
Name string `json:"name"`
Namespace string `json:"namespace"`
NumLocations int `json:"numLocations"`
NumLocationsNotCovered int `json:"numLocationsNotCovered"`
SoqlInfo []CodeLocation `json:"soqlInfo"`
SoslInfo []CodeLocation `json:"soslInfo"`
Type string `json:"type"`
}
// CodeCoverageWarning contains results include both the total number of lines
// that could have been executed, as well as the number, line, and column
// positions of code that was not executed.
type CodeCoverageWarning struct {
Id string `json:"id"`
Message string `json:"message"`
Name string `json:"name"`
Namespace string `json:"namespace"`
}
// RunTestsAsynchronousRequest contains a sample request to the
// runTestAsynchronous method
type RunTestsAsynchronousRequest struct {
ClassIDs string `json:"classids,omitempty"`
SuiteIDs string `json:"suiteids,omitempty"`
MaxFailedTests string `json:"maxFailedTests,omitempty"`
TestLevel string `json:"testLevel,omitempty"`
}
// RunTestFailure contains information about failures during the unit test run.
type RunTestFailure struct {
Id string `json:"id"`
Message string `json:"message"`
MethodName string `json:"methodName"`
Name string `json:"name"`
Namespace string `json:"namespace"`
SeeAllData string `json:"seeAllData"`
StackTrace string `json:"stackTrace"`
Time float64 `json:"time"`
Type string `json:"string"`
}
// RunTestSuccess contains information about successes during the unit test run.
type RunTestSuccess struct {
Id string `json:"id"`
MethodName string `json:"methodName"`
Name string `json:"name"`
Namespace string `json:"namespace"`
SeeAllData string `json:"seeAllData"`
Time float64 `json:"time"`
}
// CodeLocation contains if any code is not covered, the line and column of the
// code not tested, and the number of times the code was executed
type CodeLocation struct {
Column int `json:"column"`
Line int `json:"line"`
NumExecutions int `json:"numExecutions"`
Time float64 `json:"time"`
}
func (c *ToolingService) RunTestsAsynchronous(classids []string, suiteids []string, maxFailedTests string, testLevel string) (result string, err error) {
body := RunTestsAsynchronousRequest{
ClassIDs: strings.Join(classids, ","),
SuiteIDs: strings.Join(suiteids, ","),
MaxFailedTests: maxFailedTests,
TestLevel: testLevel,
}
req, err := c.client.NewRequest("POST", "/tooling/runTestsAsynchronous/", body)
if err != nil {
return
}
err = c.client.Do(req, &result)
return
}
// RunTests executes the tests in the specified classes using the synchronous
// test execution mechanism.
func (c *ToolingService) RunTests(classnames []string) (result RunTestsResult, err error) {
req, err := c.client.NewRequest("GET", "/tooling/runTestsSynchronous/?classnames="+url.QueryEscape(strings.Join(classnames, ",")), nil)
if err != nil {
return
}
err = c.client.Do(req, &result)
return
}
// Search is used to search for records that match a specified text string.
func (c *ToolingService) Search(sosl string, v interface{}) (err error) {
req, err := c.client.NewRequest("GET", "/tooling/search/?q="+url.QueryEscape(sosl), nil)
if err != nil {
return
}
err = c.client.Do(req, &v)
return
}