forked from keploy/keploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.resolvers.go
167 lines (145 loc) · 4.04 KB
/
schema.resolvers.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
package graph
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
import (
"context"
"fmt"
"time"
"go.keploy.io/server/graph/generated"
"go.keploy.io/server/graph/model"
"go.keploy.io/server/pkg"
"go.keploy.io/server/pkg/models"
)
func (r *mutationResolver) UpdateTestCase(ctx context.Context, tc []*model.TestCaseInput) (bool, error) {
var tcs []models.TestCase
for _, t := range tc {
tcs = append(tcs, ConvertTestCaseInput(t))
}
err := r.reg.UpdateTC(ctx, tcs)
if err != nil {
return false, err
}
return true, nil
}
func (r *mutationResolver) DeleteTestCase(ctx context.Context, id string) (bool, error) {
err := r.reg.DeleteTC(ctx, DEFAULT_COMPANY, id)
if err != nil {
return false, err
}
return true, nil
}
func (r *mutationResolver) NormalizeTest(ctx context.Context, id string) (bool, error) {
err := r.run.Normalize(ctx, DEFAULT_COMPANY, id)
if err != nil {
return false, err
}
return true, nil
}
func (r *queryResolver) Apps(ctx context.Context) ([]*model.App, error) {
apps, err := r.reg.GetApps(ctx, DEFAULT_COMPANY)
if err != nil {
return nil, err
}
var res []*model.App
for _, v := range apps {
res = append(res, &model.App{ID: v})
}
return res, nil
}
func (r *queryResolver) TestRun(ctx context.Context, user *string, app *string, id *string, from *time.Time, to *time.Time, offset *int, limit *int) ([]*model.TestRun, error) {
preloads := GetPreloads(ctx)
summary := true
if pkg.Contains(preloads, "tests") {
summary = false
}
usr := DEFAULT_USER
runs, err := r.run.Get(ctx, summary, DEFAULT_COMPANY, &usr, app, id, from, to, offset, limit)
if err != nil {
return nil, err
}
var res []*model.TestRun
for _, run := range runs {
var tests []*model.Test
if run.Tests != nil {
for _, t := range run.Tests {
uri := t.URI
completed := time.Unix(t.Completed, 0)
tests = append(tests, &model.Test{
ID: t.ID,
Status: ConvertTestStatus(t.Status),
Started: time.Unix(t.Started, 0),
Completed: &completed,
TestCaseID: t.TestCaseID,
URI: &uri,
Req: ConvertHttpReq(t.Req),
Noise: t.Noise,
Deps: ConvertDeps(t.Dep),
Result: ConvertResult(t.Result),
})
}
}
ts := &model.TestRun{
ID: run.ID,
Status: ConvertTestRunStatus(run.Status),
Created: time.Unix(run.Created, 0),
Updated: time.Unix(run.Updated, 0),
App: run.App,
User: run.User,
Success: run.Success,
Failure: run.Failure,
Total: run.Total,
Tests: tests,
}
//if run.Updated != nil {
// ts.Updated = time.Unix(*run.Updated, 0)
//}
//if run.Created != nil {
// ts.Created = time.Unix(*run.Created, 0)
//}
//if run.App != nil {
// ts.App = *run.App
//}
//if run.User != nil {
// ts.User = *run.User
//}
//if run.Success != nil {
// ts.Success = *run.Success
//}
//if run.Failure != nil {
// ts.Failure = *run.Failure
//}
//if run.Total != nil {
// ts.Total = *run.Total
//}
res = append(res, ts)
}
return res, nil
}
func (r *queryResolver) TestCase(ctx context.Context, app *string, id *string, offset *int, limit *int) ([]*model.TestCase, error) {
a := ""
if app != nil {
a = *app
}
if id != nil {
tc, err := r.reg.Get(ctx, DEFAULT_COMPANY, a, *id)
if err != nil {
return nil, err
}
return []*model.TestCase{ConvertTestCase(tc)}, nil
}
tcs, err := r.reg.GetAll(ctx, DEFAULT_COMPANY, a, offset, limit)
if err != nil {
return nil, err
}
var res []*model.TestCase
for _, v := range tcs {
res = append(res, ConvertTestCase(v))
}
return res, nil
}
func (r *subscriptionResolver) TestRun(ctx context.Context, app *string, id *string) (<-chan []*model.TestRun, error) {
panic(fmt.Errorf("not implemented"))
}
// Subscription returns generated.SubscriptionResolver implementation.
func (r *Resolver) Subscription() generated.SubscriptionResolver { return &subscriptionResolver{r} }
type subscriptionResolver struct{ *Resolver }