/
cmd_automated_test_impl.go
60 lines (51 loc) · 1.87 KB
/
cmd_automated_test_impl.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
package services
import (
"bytes"
"context"
"encoding/json"
"fmt"
"os"
"github.com/geekymedic/neon/logger"
"github.com/geekymedic/neon-cli/templates"
"github.com/geekymedic/neon-cli/types"
"github.com/geekymedic/neon-cli/types/sysdes"
"github.com/tidwall/pretty"
)
func (s *GenerateServer) GenerateAutomatedTest(ctx context.Context, arg *GenServerAutomatedTestArg) (_ *EmptyReply, err error) {
// IntellijAutomated Test
s.sys.Bffs.ImplIter(func(item *sysdes.BffItem, impl *sysdes.BffImpl) bool {
var (
bffInterfaceTree = impl.AstTree.Interface.(*sysdes.BffInterfaceTree)
bffReqTree = impl.AstTree.Request.(*sysdes.BffRequestTree)
intellijAutomatedTest templates.IntellijAutomatedProperty
txt string
)
intellijAutomatedTest.Title = bffInterfaceTree.Annotation.Zh
intellijAutomatedTest.URL = bffInterfaceTree.Annotation.URI
if intellijAutomatedTest.URL == "" {
intellijAutomatedTest.URL = fmt.Sprintf("/api/%s", PacketRouter(item.DirNode.Name(),
bffInterfaceTree.FileNode.Name(), s.sys.Name))
}
var data bytes.Buffer
if err = json.NewEncoder(&data).Encode(InjectAstTree(bffReqTree.TopNode)); err != nil {
return false
}
intellijAutomatedTest.Data = fmt.Sprintf("%s", pretty.Pretty(data.Bytes()))
txt, err = templates.ParseTemplate(templates.IntellijAutomatedTemplate, intellijAutomatedTest)
types.AssertNil(err)
filename := arg.Out.Append(fmt.Sprintf("%s_%s.http", item.DirNode.Name(), impl.FileNode.Name())).(types.DirNode).Abs()
mkFp := types.NewBaseFile(filename)
err = mkFp.Create(os.O_CREATE|os.O_WRONLY|os.O_EXCL, types.DefPerm)
if err != nil {
logger.With("path", mkFp.Abs()).Info("Skipped")
return true
}
_, err = mkFp.WriteString(txt)
types.AssertNil(err)
types.AssertNil(mkFp.Sync())
types.AssertNil(mkFp.Close())
return true
})
// 生成http-client-private.env.json
return
}