@@ -76,18 +76,12 @@ import rego.v1
76
76
77
77
tempDir := t .TempDir ()
78
78
79
- ls , connClient , err := createAndInitServer (ctx , newTestLogger (t ), tempDir , files , clientHandler )
79
+ _ , connClient , err := createAndInitServer (ctx , newTestLogger (t ), tempDir , files , clientHandler )
80
80
if err != nil {
81
81
t .Fatalf ("failed to create and init language server: %s" , err )
82
82
}
83
83
84
- for f := range ls .cache .GetAllFiles () {
85
- t .Log ("file loaded: " , f )
86
- }
87
-
88
- t .Log ("queue" , len (ls .lintWorkspaceJobs ))
89
-
90
- timeout := time .NewTimer (defaultTimeout )
84
+ timeout := time .NewTimer (determineTimeout ())
91
85
defer timeout .Stop ()
92
86
93
87
// no unresolved-imports at this stage
@@ -111,65 +105,27 @@ import rego.v1
111
105
}
112
106
}
113
107
114
- t .Log ("queue" , len (ls .lintWorkspaceJobs ))
115
-
116
108
barURI := fileURIScheme + filepath .Join (tempDir , "bar.rego" )
117
109
118
- contentUpdate1 := `package qux
119
-
120
- import rego.v1
121
- `
122
-
123
110
err = connClient .Call (ctx , "textDocument/didChange" , types.TextDocumentDidChangeParams {
124
111
TextDocument : types.TextDocumentIdentifier {
125
112
URI : barURI ,
126
113
},
127
114
ContentChanges : []types.TextDocumentContentChangeEvent {
128
115
{
129
- Text : contentUpdate1 ,
116
+ Text : `package qux
117
+
118
+ import rego.v1
119
+ ` ,
130
120
},
131
121
},
132
122
}, nil )
133
123
if err != nil {
134
124
t .Fatalf ("failed to send didChange notification: %s" , err )
135
125
}
136
126
137
- t .Log ("queue" , len (ls .lintWorkspaceJobs ))
138
-
139
- // wait for content to have been updated
140
- timeout .Reset (defaultTimeout )
141
-
142
- ticker := time .NewTicker (500 * time .Millisecond )
143
-
144
- for {
145
- var success bool
146
- select {
147
- case <- ticker .C :
148
- contents , ok := ls .cache .GetFileContents (barURI )
149
- if ! ok {
150
- t .Log ("waiting, bar.rego contents missing" )
151
-
152
- continue
153
- }
154
-
155
- if contents != contentUpdate1 {
156
- t .Log ("waiting, bar.rego contents not yet updated" )
157
-
158
- continue
159
- }
160
-
161
- success = true
162
- case <- timeout .C :
163
- t .Fatalf ("timed out waiting bar.rego content to have been updated" )
164
- }
165
-
166
- if success {
167
- break
168
- }
169
- }
170
-
171
127
// unresolved-imports is now expected
172
- timeout .Reset (defaultTimeout )
128
+ timeout .Reset (determineTimeout () )
173
129
174
130
for {
175
131
var success bool
@@ -193,60 +149,28 @@ import rego.v1
193
149
194
150
fooURI := fileURIScheme + filepath .Join (tempDir , "foo.rego" )
195
151
196
- contentUpdate2 := `package foo
197
-
198
- import rego.v1
199
-
200
- import data.baz
201
- import data.qux # new name for bar.rego package
202
- `
203
-
204
152
err = connClient .Call (ctx , "textDocument/didChange" , types.TextDocumentDidChangeParams {
205
153
TextDocument : types.TextDocumentIdentifier {
206
154
URI : fooURI ,
207
155
},
208
156
ContentChanges : []types.TextDocumentContentChangeEvent {
209
157
{
210
- Text : contentUpdate2 ,
158
+ Text : `package foo
159
+
160
+ import rego.v1
161
+
162
+ import data.baz
163
+ import data.qux # new name for bar.rego package
164
+ ` ,
211
165
},
212
166
},
213
167
}, nil )
214
168
if err != nil {
215
169
t .Fatalf ("failed to send didChange notification: %s" , err )
216
170
}
217
171
218
- // wait for content to have been updated
219
- timeout .Reset (defaultTimeout )
220
-
221
- for {
222
- var success bool
223
- select {
224
- case <- ticker .C :
225
- contents , ok := ls .cache .GetFileContents (fooURI )
226
- if ! ok {
227
- t .Log ("waiting, foo.rego contents missing" )
228
-
229
- continue
230
- }
231
-
232
- if contents != contentUpdate2 {
233
- t .Log ("waiting, foo.rego contents not yet updated" )
234
-
235
- continue
236
- }
237
-
238
- success = true
239
- case <- timeout .C :
240
- t .Fatalf ("timed out waiting foo.rego content to have been updated" )
241
- }
242
-
243
- if success {
244
- break
245
- }
246
- }
247
-
248
172
// unresolved-imports is again not expected
249
- timeout .Reset (defaultTimeout )
173
+ timeout .Reset (determineTimeout () )
250
174
251
175
for {
252
176
var success bool
@@ -309,7 +233,7 @@ import data.quz
309
233
}
310
234
311
235
// 1. check the Aggregates are set at start up
312
- timeout := time .NewTimer (defaultTimeout )
236
+ timeout := time .NewTimer (determineTimeout () )
313
237
314
238
ticker := time .NewTicker (500 * time .Millisecond )
315
239
defer ticker .Stop ()
@@ -398,7 +322,7 @@ import data.wow # new
398
322
t .Fatalf ("failed to send didChange notification: %s" , err )
399
323
}
400
324
401
- timeout .Reset (defaultTimeout )
325
+ timeout .Reset (determineTimeout () )
402
326
403
327
for {
404
328
success := false
@@ -490,7 +414,7 @@ import rego.v1
490
414
}
491
415
492
416
// wait for foo.rego to have the correct violations
493
- timeout := time .NewTimer (defaultTimeout )
417
+ timeout := time .NewTimer (determineTimeout () )
494
418
defer timeout .Stop ()
495
419
496
420
for {
@@ -515,59 +439,26 @@ import rego.v1
515
439
516
440
// update the contents of the bar.rego file to address the unresolved-import
517
441
barURI := fileURIScheme + filepath .Join (tempDir , "bar.rego" )
518
- contentUpdate1 := `package bax # package imported in foo.rego
519
-
520
- import rego.v1
521
- `
522
442
523
443
err = connClient .Call (ctx , "textDocument/didChange" , types.TextDocumentDidChangeParams {
524
444
TextDocument : types.TextDocumentIdentifier {
525
445
URI : barURI ,
526
446
},
527
447
ContentChanges : []types.TextDocumentContentChangeEvent {
528
448
{
529
- Text : contentUpdate1 ,
449
+ Text : `package bax # package imported in foo.rego
450
+
451
+ import rego.v1
452
+ ` ,
530
453
},
531
454
},
532
455
}, nil )
533
456
if err != nil {
534
457
t .Fatalf ("failed to send didChange notification: %s" , err )
535
458
}
536
459
537
- // wait for bar.rego to have the correct content
538
- timeout .Reset (defaultTimeout )
539
-
540
- ticker := time .NewTicker (500 * time .Millisecond )
541
-
542
- for {
543
- var success bool
544
- select {
545
- case <- ticker .C :
546
- contents , ok := ls .cache .GetFileContents (barURI )
547
- if ! ok {
548
- t .Log ("waiting, bar.rego contents missing" )
549
-
550
- continue
551
- }
552
-
553
- if contents != contentUpdate1 {
554
- t .Log ("waiting, bar.rego contents not yet updated" )
555
-
556
- continue
557
- }
558
-
559
- success = true
560
- case <- timeout .C :
561
- t .Fatalf ("timed out waiting bar.rego content to have been updated" )
562
- }
563
-
564
- if success {
565
- break
566
- }
567
- }
568
-
569
460
// wait for foo.rego to have the correct violations
570
- timeout .Reset (defaultTimeout )
461
+ timeout .Reset (determineTimeout () )
571
462
572
463
for {
573
464
var success bool
@@ -589,58 +480,26 @@ import rego.v1
589
480
}
590
481
}
591
482
592
- contentUpdate2 := `package bar # original package to bring back the violation
593
-
594
- import rego.v1
595
- `
596
-
597
483
// update the contents of the bar.rego to bring back the violation
598
484
err = connClient .Call (ctx , "textDocument/didChange" , types.TextDocumentDidChangeParams {
599
485
TextDocument : types.TextDocumentIdentifier {
600
486
URI : barURI ,
601
487
},
602
488
ContentChanges : []types.TextDocumentContentChangeEvent {
603
489
{
604
- Text : contentUpdate2 ,
490
+ Text : `package bar # original package to bring back the violation
491
+
492
+ import rego.v1
493
+ ` ,
605
494
},
606
495
},
607
496
}, nil )
608
497
if err != nil {
609
498
t .Fatalf ("failed to send didChange notification: %s" , err )
610
499
}
611
500
612
- // wait for bar.rego to have the correct content
613
- timeout .Reset (defaultTimeout )
614
-
615
- for {
616
- var success bool
617
- select {
618
- case <- ticker .C :
619
- contents , ok := ls .cache .GetFileContents (barURI )
620
- if ! ok {
621
- t .Log ("waiting, bar.rego contents missing" )
622
-
623
- continue
624
- }
625
-
626
- if contents != contentUpdate2 {
627
- t .Log ("waiting, bar.rego contents not yet updated" )
628
-
629
- continue
630
- }
631
-
632
- success = true
633
- case <- timeout .C :
634
- t .Fatalf ("timed out waiting bar.rego content to have been updated" )
635
- }
636
-
637
- if success {
638
- break
639
- }
640
- }
641
-
642
501
// check the violation is back
643
- timeout .Reset (defaultTimeout )
502
+ timeout .Reset (determineTimeout () )
644
503
645
504
for {
646
505
var success bool
0 commit comments