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:
Antoine Pelisse
2017-10-23 16:46:35 -07:00
parent e95672de45
commit ed38f43495
4 changed files with 22 additions and 13 deletions

View File

@@ -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)