-
Notifications
You must be signed in to change notification settings - Fork 1
/
internal_test.go
55 lines (49 loc) · 1.4 KB
/
internal_test.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
package goidoit
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
)
// export getID
func TgetID() int {
return getID()
}
// reset id
func TResetID() {
id = 0
}
// export debug func
func TdebugPrint(format string, a ...interface{}) (n int, err error) {
return debugPrint(format, a...)
}
func TgetDebug() bool {
return debug
}
func idoitAPIStub() *httptest.Server {
var resp string
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
if err != nil {
http.Error(w, err.Error(), 500)
return
}
var req Request
err = json.Unmarshal(b, &req)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
switch req.Method {
case "idoit.login":
resp = `{"jsonrpc":"2.0","result":{"result":true,"userid":"1","name":"username","mail":"","username":"username","session-id":"mysessionid","client-id":"1","client-name":"client"},"id":1}`
case "test", "idoit.search", "idoit.version", "cmdb.objects.read", "cmdb.objects.create", "cmdb.objects.update", "cmdb.objects.delete", "cmdb.objets.quickpurge", "idoit.reports.read", "idoit.dialog.read", "cmdb.category.read", "cmdb.category.create", "cmdb.category.update", "cmdb.category.delete":
resp = `{"jsonrpc":"2.0","result":[]}`
default:
http.Error(w, "not found", http.StatusNotFound)
return
}
w.Write([]byte(resp))
}))
}