@@ -7,9 +7,10 @@ package jsonschema_test
7
7
import (
8
8
"bytes"
9
9
"context"
10
- "crypto/tls"
11
10
"encoding/json"
12
11
"errors"
12
+ "github.com/hashicorp/go-retryablehttp"
13
+ "github.com/ory/jsonschema/v3/httploader"
13
14
"io"
14
15
"io/ioutil"
15
16
"net/http"
@@ -27,6 +28,8 @@ import (
27
28
28
29
var draft4 , draft6 , draft7 []byte
29
30
31
+ var ctx = context .WithValue (context .Background (), httploader .ContextKey , retryablehttp .NewClient ())
32
+
30
33
func init () {
31
34
var err error
32
35
draft4 , err = ioutil .ReadFile ("testdata/draft4.json" )
@@ -66,7 +69,6 @@ type testGroup struct {
66
69
}
67
70
68
71
func testFolder (t * testing.T , folder string , draft * jsonschema.Draft ) {
69
- ctx := context .Background ()
70
72
server := & http.Server {Addr : "localhost:1234" , Handler : http .FileServer (http .Dir ("testdata/remotes" ))}
71
73
go func () {
72
74
if err := server .ListenAndServe (); err != http .ErrServerClosed {
@@ -174,7 +176,6 @@ func testFolder(t *testing.T, folder string, draft *jsonschema.Draft) {
174
176
}
175
177
176
178
func TestInvalidSchema (t * testing.T ) {
177
- ctx := context .Background ()
178
179
t .Run ("MustCompile with panic" , func (t * testing.T ) {
179
180
defer func () {
180
181
if r := recover (); r == nil {
@@ -242,18 +243,14 @@ func TestInvalidSchema(t *testing.T) {
242
243
}
243
244
244
245
func TestCompileURL (t * testing.T ) {
245
- ctx := context .Background ()
246
- tr := http .DefaultTransport .(* http.Transport )
247
- if tr .TLSClientConfig == nil {
248
- tr .TLSClientConfig = & tls.Config {}
249
- }
250
- tr .TLSClientConfig .InsecureSkipVerify = true
251
-
252
246
handler := http .FileServer (http .Dir ("testdata" ))
253
247
httpServer := httptest .NewServer (handler )
254
248
defer httpServer .Close ()
255
249
httpsServer := httptest .NewTLSServer (handler )
256
250
defer httpsServer .Close ()
251
+ c := retryablehttp .NewClient ()
252
+ c .HTTPClient = httpsServer .Client ()
253
+ ctx := context .WithValue (context .Background (), httploader .ContextKey , c )
257
254
258
255
validTests := []struct {
259
256
schema , doc string
@@ -301,8 +298,6 @@ func TestCompileURL(t *testing.T) {
301
298
}
302
299
303
300
func TestValidateInterface (t * testing.T ) {
304
- ctx := context .Background ()
305
-
306
301
files := []string {
307
302
"testdata/draft4/type.json" ,
308
303
"testdata/draft4/minimum.json" ,
@@ -359,7 +354,6 @@ func TestValidateInterface(t *testing.T) {
359
354
}
360
355
361
356
func TestInvalidJsonTypeError (t * testing.T ) {
362
- ctx := context .Background ()
363
357
compiler := jsonschema .NewCompiler ()
364
358
err := compiler .AddResource ("test.json" , strings .NewReader (`{ "type": "string"}` ))
365
359
if err != nil {
@@ -380,7 +374,6 @@ func TestInvalidJsonTypeError(t *testing.T) {
380
374
}
381
375
382
376
func TestExtractAnnotations (t * testing.T ) {
383
- ctx := context .Background ()
384
377
t .Run ("false" , func (t * testing.T ) {
385
378
compiler := jsonschema .NewCompiler ()
386
379
@@ -467,7 +460,6 @@ func toFileURL(path string) string {
467
460
468
461
// TestPanic tests https://github.com/ory/jsonschema/issues/18
469
462
func TestPanic (t * testing.T ) {
470
- ctx := context .Background ()
471
463
schema_d := `
472
464
{
473
465
"type": "object",
@@ -505,7 +497,6 @@ func TestPanic(t *testing.T) {
505
497
}
506
498
507
499
func TestNonStringFormat (t * testing.T ) {
508
- ctx := context .Background ()
509
500
jsonschema .Formats ["even-number" ] = func (v interface {}) bool {
510
501
switch v := v .(type ) {
511
502
case json.Number :
@@ -536,7 +527,6 @@ func TestNonStringFormat(t *testing.T) {
536
527
}
537
528
538
529
func TestCompiler_LoadURL (t * testing.T ) {
539
- ctx := context .Background ()
540
530
const (
541
531
base = `{ "type": "string" }`
542
532
schema = `{ "allOf": [{ "$ref": "base.json" }, { "maxLength": 3 }] }`
@@ -566,7 +556,6 @@ func TestCompiler_LoadURL(t *testing.T) {
566
556
}
567
557
568
558
func TestSchemaReferencesDrafts (t * testing.T ) {
569
- ctx := context .Background ()
570
559
c := jsonschema .NewCompiler ()
571
560
file := "testdata/reference_draft.json"
572
561
t .Log (filepath .Base (file ))
0 commit comments