FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sourcegraph/dev/gqltest/code_insights_test.go at main · TiO2/sourcegraph · GitHub
TiO2
/
sourcegraph
Public
forked from
sourcegraph/sourcegraph-public-snapshot
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sourcegraph
/
dev
/
gqltest
/
code_insights_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
222 lines (206 loc) · 6.65 KB
Breadcrumbs
sourcegraph
/
dev
/
gqltest
/
code_insights_test.go
Copy path
File metadata and controls
222 lines (206 loc) · 6.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package
main
import
(
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/sourcegraph/sourcegraph/cmd/frontend/graphqlbackend"
"github.com/sourcegraph/sourcegraph/internal/gqltestutil"
)
func
TestCreateDashboard
(
t
*
testing.
T
) {
t
.
Run
(
"can create an insights dashboard"
,
func
(
t
*
testing.
T
) {
title
:=
"Dashboard Title 1"
result
,
err
:=
client
.
CreateDashboard
(gqltestutil.
DashboardInputArgs
{
Title
:
title
,
GlobalGrant
:
true
,
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
want
:=
gqltestutil.
DashboardResponse
{
Title
:
title
,
Grants
: gqltestutil.
GrantsResponse
{
Users
: []
string
{},
Organizations
: []
string
{},
Global
:
true
,
},
}
err
=
client
.
DeleteDashboard
(
result
.
Id
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Ignore the newly created id
result
.
Id
=
""
if
diff
:=
cmp
.
Diff
(
want
,
result
);
diff
!=
""
{
t
.
Fatalf
(
"Mismatch (-want +got):
\n
%s"
,
diff
)
}
})
t
.
Run
(
"errors on a grant that the user does not have permission to give"
,
func
(
t
*
testing.
T
) {
title
:=
"Dashboard Title 1"
_
,
err
:=
client
.
CreateDashboard
(gqltestutil.
DashboardInputArgs
{
Title
:
title
,
UserGrant
:
string
(
graphqlbackend
.
MarshalUserID
(
9999
)),
})
if
!
strings
.
Contains
(
err
.
Error
(),
"user does not have permission"
) {
t
.
Fatal
(
"Should have thrown an error"
)
}
})
t
.
Run
(
"errors on zero grants"
,
func
(
t
*
testing.
T
) {
title
:=
"Dashboard Title 1"
_
,
err
:=
client
.
CreateDashboard
(gqltestutil.
DashboardInputArgs
{
Title
:
title
,
})
if
!
strings
.
Contains
(
err
.
Error
(),
"dashboard must be created with at least one grant"
) {
t
.
Fatal
(
"Should have thrown an error"
)
}
})
}
func
TestGetDashboards
(
t
*
testing.
T
) {
titles
:=
[]
string
{
"Title 1"
,
"Title 2"
,
"Title 3"
,
"Title 4"
,
"Title 5"
}
ids
:=
[]
string
{}
for
_
,
title
:=
range
titles
{
response
,
err
:=
client
.
CreateDashboard
(gqltestutil.
DashboardInputArgs
{
Title
:
title
,
GlobalGrant
:
true
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
ids
=
append
(
ids
,
response
.
Id
)
}
defer
func
() {
for
_
,
id
:=
range
ids
{
err
:=
client
.
DeleteDashboard
(
id
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
}()
t
.
Run
(
"can get all dashboards"
,
func
(
t
*
testing.
T
) {
resultTitles
:=
getTitles
(
t
, gqltestutil.
GetDashboardArgs
{})
if
diff
:=
cmp
.
Diff
(
titles
,
resultTitles
);
diff
!=
""
{
t
.
Fatalf
(
"Mismatch (-want +got):
\n
%s"
,
diff
)
}
})
t
.
Run
(
"can get the first 2 dashboards"
,
func
(
t
*
testing.
T
) {
first
:=
2
args
:=
gqltestutil.
GetDashboardArgs
{
First
:
&
first
}
resultTitles
:=
getTitles
(
t
,
args
)
if
diff
:=
cmp
.
Diff
(
titles
[
0
:
2
],
resultTitles
);
diff
!=
""
{
t
.
Fatalf
(
"Mismatch (-want +got):
\n
%s"
,
diff
)
}
})
t
.
Run
(
"can get a dashboard by id"
,
func
(
t
*
testing.
T
) {
args
:=
gqltestutil.
GetDashboardArgs
{
Id
:
&
ids
[
3
]}
resultTitles
:=
getTitles
(
t
,
args
)
if
diff
:=
cmp
.
Diff
([]
string
{
titles
[
3
]},
resultTitles
);
diff
!=
""
{
t
.
Fatalf
(
"Mismatch (-want +got):
\n
%s"
,
diff
)
}
})
t
.
Run
(
"can get all dashboards after a cursor"
,
func
(
t
*
testing.
T
) {
args
:=
gqltestutil.
GetDashboardArgs
{
After
:
&
ids
[
1
]}
resultTitles
:=
getTitles
(
t
,
args
)
if
diff
:=
cmp
.
Diff
(
titles
[
2
:
5
],
resultTitles
);
diff
!=
""
{
t
.
Fatalf
(
"Mismatch (-want +got):
\n
%s"
,
diff
)
}
})
t
.
Run
(
"can get a single dashboard after a cursor"
,
func
(
t
*
testing.
T
) {
first
:=
1
args
:=
gqltestutil.
GetDashboardArgs
{
First
:
&
first
,
After
:
&
ids
[
2
]}
resultTitles
:=
getTitles
(
t
,
args
)
if
diff
:=
cmp
.
Diff
([]
string
{
titles
[
3
]},
resultTitles
);
diff
!=
""
{
t
.
Fatalf
(
"Mismatch (-want +got):
\n
%s"
,
diff
)
}
})
}
func
TestUpdateDashboard
(
t
*
testing.
T
) {
dashboard
,
err
:=
client
.
CreateDashboard
(gqltestutil.
DashboardInputArgs
{
Title
:
"Title"
,
GlobalGrant
:
true
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
func
() {
err
:=
client
.
DeleteDashboard
(
dashboard
.
Id
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}()
t
.
Run
(
"can update a dashboard"
,
func
(
t
*
testing.
T
) {
updatedTitle
:=
"Updated title"
userGrant
:=
client
.
AuthenticatedUserID
()
updatedDashboard
,
err
:=
client
.
UpdateDashboard
(
dashboard
.
Id
, gqltestutil.
DashboardInputArgs
{
Title
:
updatedTitle
,
UserGrant
:
userGrant
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
wantDashboard
:=
gqltestutil.
DashboardResponse
{
Id
:
dashboard
.
Id
,
Title
:
updatedTitle
,
Grants
: gqltestutil.
GrantsResponse
{
Users
: []
string
{
userGrant
},
Organizations
: []
string
{},
Global
:
false
,
},
}
if
diff
:=
cmp
.
Diff
(
wantDashboard
,
updatedDashboard
);
diff
!=
""
{
t
.
Fatalf
(
"Mismatch (-want +got):
\n
%s"
,
diff
)
}
})
}
func
TestDeleteDashboard
(
t
*
testing.
T
) {
t
.
Run
(
"can delete an insights dashboard"
,
func
(
t
*
testing.
T
) {
dashboard
,
err
:=
client
.
CreateDashboard
(gqltestutil.
DashboardInputArgs
{
Title
:
"Should be deleted"
,
GlobalGrant
:
true
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
err
=
client
.
DeleteDashboard
(
dashboard
.
Id
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
responseDashboard
,
err
:=
client
.
GetDashboards
(gqltestutil.
GetDashboardArgs
{
Id
:
&
dashboard
.
Id
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
diff
:=
cmp
.
Diff
(
0
,
len
(
responseDashboard
));
diff
!=
""
{
t
.
Fatalf
(
"Mismatch (-want +got):
\n
%s"
,
diff
)
}
})
t
.
Run
(
"cannot delete an insights dashboard without permission"
,
func
(
t
*
testing.
T
) {
dashboard
,
err
:=
client
.
CreateDashboard
(gqltestutil.
DashboardInputArgs
{
Title
:
"Should be deleted"
,
GlobalGrant
:
true
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
_
,
err
=
client
.
UpdateDashboard
(
dashboard
.
Id
, gqltestutil.
DashboardInputArgs
{})
if
err
==
nil
||
!
strings
.
Contains
(
err
.
Error
(),
"got nil for non-null"
) {
t
.
Fatal
(
err
)
}
err
=
client
.
DeleteDashboard
(
dashboard
.
Id
)
if
!
strings
.
Contains
(
err
.
Error
(),
"dashboard not found"
) {
t
.
Fatal
(
"Should have thrown an error"
)
}
})
t
.
Run
(
"returns an error when a dashboard does not exist"
,
func
(
t
*
testing.
T
) {
err
:=
client
.
DeleteDashboard
(
"ZGFzaGJvYXJkOnsiSWRUeXBlIjoiY3VzdG9tIiwiQXJnIjo5OTk5OX0="
)
if
!
strings
.
Contains
(
err
.
Error
(),
"dashboard not found"
) {
t
.
Fatal
(
"Should have thrown an error"
)
}
})
}
func
getTitles
(
t
*
testing.
T
,
args
gqltestutil.
GetDashboardArgs
) []
string
{
dashboards
,
err
:=
client
.
GetDashboards
(
args
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
retry
:=
false
resultTitles
:=
[]
string
{}
for
_
,
dashboard
:=
range
dashboards
{
// Sometimes the LAM dashboard will be present since the service is running. We do not want to count it in the test,
// so we hide the LAM dashboard and query the dashboards again.
if
dashboard
.
Title
==
"Limited Access Mode Dashboard"
{
_
,
err
=
client
.
UpdateDashboard
(
dashboard
.
Id
, gqltestutil.
DashboardInputArgs
{
Title
:
"Limited Access Mode Dashboard"
})
if
err
==
nil
||
!
strings
.
Contains
(
err
.
Error
(),
"got nil for non-null"
) {
t
.
Fatal
(
err
)
}
retry
=
true
}
resultTitles
=
append
(
resultTitles
,
dashboard
.
Title
)
}
if
retry
{
return
getTitles
(
t
,
args
)
}
return
resultTitles
}
Back
|
FazBrowse Home
|
New Git URL