This repository has been archived by the owner on Jul 7, 2022. It is now read-only.
/
api_inquisitor_DeptService.go
136 lines (108 loc) · 2.66 KB
/
api_inquisitor_DeptService.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
package api_inquisitor
import (
"context"
"fmt"
pb "github.com/pigfall/curdboy_playground/api/v1/contacts"
api "github.com/pigfall/curdboy_playground/http_api_contacts"
"log"
)
type DeptServiceInquisitor struct {
client api.ApiClientIfce
}
func DeptServiceInquisitorNew(client api.ApiClientIfce) ApiInquisitor {
return &DeptServiceInquisitor{
client: client,
}
}
func (this *DeptServiceInquisitor) Check(ctx context.Context) error {
// DeptCreate
// DeptFind
// DeptFindById
// DeptUpdate
// DeptDelete
//reqEntity := &pb.Dept{}
reqEntity := RandomDept()
// { insert data
log.Printf("开始插入测试数据 %+v \n", reqEntity)
created, err := api.DeptCreateNew(reqEntity).ExecBy(ctx, this.client)
if err != nil {
log.Println(err)
return err
}
log.Println("插入测试数据成功")
// }
// { find data by id
log.Printf("开始根据 id %+v 查询上一步插入的数据", created)
findedData, err := api.DeptFindByIdNew(created).ExecBy(ctx, this.client)
if err != nil {
log.Println(err)
return err
}
log.Println("根据id 查询数据成功")
// }
toCmp := reqEntity
toCmp.DeptId = created.DeptId
{
toCmp.DeptId = created.DeptId
var cmpFunc func() bool
cmpFunc = func() bool {
return toCmp.DeptId == findedData.DeptId
}
if !cmpFunc() {
err = fmt.Errorf("Field %s not matched %v %v", "DeptId", toCmp.DeptId, findedData.DeptId)
log.Println(err)
return err
}
}
// { update
reqEntityToUpdate := RandomDept()
reqEntityToUpdate.DeptId = created.DeptId
log.Printf("开始更新 数据 %+v \n", reqEntityToUpdate)
_, err = api.DeptUpdateNew(reqEntityToUpdate).ExecBy(ctx, this.client)
if err != nil {
log.Println(err)
return err
}
// }
// { check data after update
log.Println("😈 check data after update")
findedData, err = api.DeptFindByIdNew(created).ExecBy(ctx, this.client)
if err != nil {
log.Println(err)
return err
}
toCmp = reqEntityToUpdate
{
toCmp.DeptId = created.DeptId
var cmpFunc func() bool
cmpFunc = func() bool {
return toCmp.DeptId == findedData.DeptId
}
if !cmpFunc() {
err = fmt.Errorf("Field %s not matched %v %v", "DeptId", toCmp.DeptId, findedData.DeptId)
log.Println(err)
return err
}
}
// }
// { delete data
_, err = api.DeptDeleteNew(created).ExecBy(ctx, this.client)
if err != nil {
log.Println(err)
return err
}
// }
// { check deleted data TODO
log.Println("Checking data if delete")
findedData, err = api.DeptFindByIdNew(created).ExecBy(ctx, this.client)
if err == nil {
log.Println("deleted data failed")
}
// }
return nil
}
func RandomDept() *pb.Dept {
output := &pb.Dept{}
output.DeptId = randomStringValue()
return output
}