-
Notifications
You must be signed in to change notification settings - Fork 0
/
genAPITests.go
108 lines (81 loc) · 1.76 KB
/
genAPITests.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
package gen
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
"github.com/macinnir/dvc/core/lib"
)
// GenAPITests generates api tests
func (g *Gen) GenAPITests() (e error) {
fileBytes, e := ioutil.ReadFile(lib.RoutesFilePath)
if e != nil {
return
}
c := &RoutesJSONContainer{}
if e = json.Unmarshal(fileBytes, c); e != nil {
return
}
for k := range c.Routes {
fmt.Printf("Testing %s \n", k)
fmt.Printf("Body: ")
}
// fmt.Println(c.Aggregates["ConversationAggregate"])
// for k := range c.Aggregates {
// fmt.Println(k)
// }
// b := false
// for k := range c.Routes {
// controller := c.Routes[k]
// for l := range controller.Routes {
// // if controller.Routes[l].Name != "CreateBusiness" {
// // continue
// // }
// // b = true
// bodyCat, bodyType := getTypeFullKey(controller.Routes[l].BodyType)
// responseCat, responseType := getTypeFullKey(controller.Routes[l].ResponseType)
// fmt.Println(
// controller.Routes[l].Name,
// controller.Routes[l].Method,
// controller.Routes[l].Raw,
// controller.Routes[l].BodyType,
// controller.Routes[l].ResponseType,
// fmt.Sprintf("%s.%s", bodyCat, bodyType),
// fmt.Sprintf("%s.%s", responseCat, responseType),
// )
// // break
// }
// if b {
// break
// }
// }
return
}
func getTypeFullKey(name string) (baseType string, typeName string) {
if len(name) == 0 {
return
}
for {
if len(name) == 0 {
return
}
if name[0:1] == "*" {
name = name[1:]
continue
}
if name[0:2] == "[]" {
name = name[2:]
continue
}
break
}
if strings.Contains(name, ".") {
parts := strings.Split(name, ".")
baseType = parts[0]
typeName = parts[1]
} else {
baseType = "aggregates"
typeName = name
}
return
}