File: benchmark_test.go

package info (click to toggle)
golang-github-go-openapi-validate 0.24.0-3
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 7,040 kB
  • sloc: sh: 11; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 710 bytes parent folder | download
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
package validate

import (
	"path/filepath"
	"testing"

	"github.com/go-openapi/loads"
	"github.com/go-openapi/strfmt"
	"github.com/stretchr/testify/require"
)

func Benchmark_KubernetesSpec(b *testing.B) {
	fp := filepath.Join("fixtures", "go-swagger", "canary", "kubernetes", "swagger.json")
	doc, err := loads.Spec(fp)
	require.NoError(b, err)
	require.NotNil(b, doc)

	b.Run("validating kubernetes API", func(b *testing.B) {
		b.ResetTimer()
		b.ReportAllocs()

		for i := 0; i < b.N; i++ {
			validator := NewSpecValidator(doc.Schema(), strfmt.Default)
			validator.Options.SkipSchemataResult = true
			res, _ := validator.Validate(doc)
			if res == nil || !res.IsValid() {
				b.FailNow()
			}
		}
	})
}