@@ -7,9 +7,10 @@ package jsonschema_test
77import (
88 "bytes"
99 "context"
10- "crypto/tls"
1110 "encoding/json"
1211 "errors"
12+ "github.com/hashicorp/go-retryablehttp"
13+ "github.com/ory/jsonschema/v3/httploader"
1314 "io"
1415 "io/ioutil"
1516 "net/http"
@@ -27,6 +28,8 @@ import (
2728
2829var draft4 , draft6 , draft7 []byte
2930
31+ var ctx = context .WithValue (context .Background (), httploader .ContextKey , retryablehttp .NewClient ())
32+
3033func init () {
3134 var err error
3235 draft4 , err = ioutil .ReadFile ("testdata/draft4.json" )
@@ -66,7 +69,6 @@ type testGroup struct {
6669}
6770
6871func testFolder (t * testing.T , folder string , draft * jsonschema.Draft ) {
69- ctx := context .Background ()
7072 server := & http.Server {Addr : "localhost:1234" , Handler : http .FileServer (http .Dir ("testdata/remotes" ))}
7173 go func () {
7274 if err := server .ListenAndServe (); err != http .ErrServerClosed {
@@ -174,7 +176,6 @@ func testFolder(t *testing.T, folder string, draft *jsonschema.Draft) {
174176}
175177
176178func TestInvalidSchema (t * testing.T ) {
177- ctx := context .Background ()
178179 t .Run ("MustCompile with panic" , func (t * testing.T ) {
179180 defer func () {
180181 if r := recover (); r == nil {
@@ -242,18 +243,14 @@ func TestInvalidSchema(t *testing.T) {
242243}
243244
244245func 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-
252246 handler := http .FileServer (http .Dir ("testdata" ))
253247 httpServer := httptest .NewServer (handler )
254248 defer httpServer .Close ()
255249 httpsServer := httptest .NewTLSServer (handler )
256250 defer httpsServer .Close ()
251+ c := retryablehttp .NewClient ()
252+ c .HTTPClient = httpsServer .Client ()
253+ ctx := context .WithValue (context .Background (), httploader .ContextKey , c )
257254
258255 validTests := []struct {
259256 schema , doc string
@@ -301,8 +298,6 @@ func TestCompileURL(t *testing.T) {
301298}
302299
303300func TestValidateInterface (t * testing.T ) {
304- ctx := context .Background ()
305-
306301 files := []string {
307302 "testdata/draft4/type.json" ,
308303 "testdata/draft4/minimum.json" ,
@@ -359,7 +354,6 @@ func TestValidateInterface(t *testing.T) {
359354}
360355
361356func TestInvalidJsonTypeError (t * testing.T ) {
362- ctx := context .Background ()
363357 compiler := jsonschema .NewCompiler ()
364358 err := compiler .AddResource ("test.json" , strings .NewReader (`{ "type": "string"}` ))
365359 if err != nil {
@@ -380,7 +374,6 @@ func TestInvalidJsonTypeError(t *testing.T) {
380374}
381375
382376func TestExtractAnnotations (t * testing.T ) {
383- ctx := context .Background ()
384377 t .Run ("false" , func (t * testing.T ) {
385378 compiler := jsonschema .NewCompiler ()
386379
@@ -467,7 +460,6 @@ func toFileURL(path string) string {
467460
468461// TestPanic tests https://github.com/ory/jsonschema/issues/18
469462func TestPanic (t * testing.T ) {
470- ctx := context .Background ()
471463 schema_d := `
472464 {
473465 "type": "object",
@@ -505,7 +497,6 @@ func TestPanic(t *testing.T) {
505497}
506498
507499func TestNonStringFormat (t * testing.T ) {
508- ctx := context .Background ()
509500 jsonschema .Formats ["even-number" ] = func (v interface {}) bool {
510501 switch v := v .(type ) {
511502 case json.Number :
@@ -536,7 +527,6 @@ func TestNonStringFormat(t *testing.T) {
536527}
537528
538529func TestCompiler_LoadURL (t * testing.T ) {
539- ctx := context .Background ()
540530 const (
541531 base = `{ "type": "string" }`
542532 schema = `{ "allOf": [{ "$ref": "base.json" }, { "maxLength": 3 }] }`
@@ -566,7 +556,6 @@ func TestCompiler_LoadURL(t *testing.T) {
566556}
567557
568558func TestSchemaReferencesDrafts (t * testing.T ) {
569- ctx := context .Background ()
570559 c := jsonschema .NewCompiler ()
571560 file := "testdata/reference_draft.json"
572561 t .Log (filepath .Base (file ))
0 commit comments