mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 15:05:20 +00:00
apply/strategy: Improve test performance
Test running time goes from 150 seconds to 7 seconds with that one simple trick. Do not re-parse openapi schema for every test, but keep one version for the whole test (specifically since it's read-only anyway).
This commit is contained in:
@@ -32,18 +32,14 @@ import (
|
||||
tst "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
|
||||
)
|
||||
|
||||
var fakeResources = tst.NewFakeResources(filepath.Join("..", "..", "..", "..", "api", "openapi-spec", "swagger.json"))
|
||||
|
||||
// run parses the openapi and runs the tests
|
||||
func run(instance apply.Strategy, recorded, local, remote, expected map[string]interface{}) {
|
||||
runWith(instance, recorded, local, remote, expected,
|
||||
filepath.Join("..", "..", "..", "..", "api", "openapi-spec", "swagger.json"))
|
||||
runWith(instance, recorded, local, remote, expected, fakeResources)
|
||||
}
|
||||
|
||||
func runWith(instance apply.Strategy, recorded, local, remote, expected map[string]interface{}, swaggerPath string) {
|
||||
fakeSchema := tst.Fake{Path: swaggerPath}
|
||||
s, err := fakeSchema.OpenAPISchema()
|
||||
Expect(err).To(BeNil())
|
||||
resources, err := openapi.NewOpenAPIData(s)
|
||||
Expect(err).To(BeNil())
|
||||
func runWith(instance apply.Strategy, recorded, local, remote, expected map[string]interface{}, resources openapi.Resources) {
|
||||
parseFactory := parse.Factory{Resources: resources}
|
||||
|
||||
parsed, err := parseFactory.CreateElement(recorded, local, remote)
|
||||
|
||||
Reference in New Issue
Block a user