...

Source file src/github.com/go-openapi/validate/benchmark_test.go

Documentation: github.com/go-openapi/validate

     1  package validate
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  
     7  	"github.com/go-openapi/loads"
     8  	"github.com/go-openapi/strfmt"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func Benchmark_KubernetesSpec(b *testing.B) {
    13  	fp := filepath.Join("fixtures", "go-swagger", "canary", "kubernetes", "swagger.json")
    14  	doc, err := loads.Spec(fp)
    15  	require.NoError(b, err)
    16  	require.NotNil(b, doc)
    17  
    18  	b.Run("validating kubernetes API", func(b *testing.B) {
    19  		b.ResetTimer()
    20  		b.ReportAllocs()
    21  
    22  		for i := 0; i < b.N; i++ {
    23  			validator := NewSpecValidator(doc.Schema(), strfmt.Default)
    24  			validator.Options.SkipSchemataResult = true
    25  			res, _ := validator.Validate(doc)
    26  			if res == nil || !res.IsValid() {
    27  				b.FailNow()
    28  			}
    29  		}
    30  	})
    31  }
    32  

View as plain text