openapi: Remove cache mechanism

The cache will be removed and replaced with HTTP Etag caching instead.
This patch is simply removing the existing mechanism.
This commit is contained in:
Antoine Pelisse
2017-06-05 10:28:18 -07:00
parent 90a45b2df3
commit a1d0384e82
10 changed files with 84 additions and 491 deletions

View File

@@ -18,13 +18,83 @@ package openapi_test
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync"
"gopkg.in/yaml.v2"
"github.com/googleapis/gnostic/OpenAPIv2"
"github.com/googleapis/gnostic/compiler"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
)
// Test utils
var data apiData
type apiData struct {
sync.Once
data *openapi_v2.Document
err error
}
func (d *apiData) OpenAPISchema() (*openapi_v2.Document, error) {
d.Do(func() {
// Get the path to the swagger.json file
wd, err := os.Getwd()
if err != nil {
d.err = err
return
}
abs, err := filepath.Abs(wd)
if err != nil {
d.err = err
return
}
root := filepath.Dir(filepath.Dir(filepath.Dir(filepath.Dir(filepath.Dir(abs)))))
specpath := filepath.Join(root, "api", "openapi-spec", "swagger.json")
_, err = os.Stat(specpath)
if err != nil {
d.err = err
return
}
spec, err := ioutil.ReadFile(specpath)
if err != nil {
d.err = err
return
}
var info yaml.MapSlice
err = yaml.Unmarshal(spec, &info)
if err != nil {
d.err = err
return
}
d.data, d.err = openapi_v2.NewDocument(info, compiler.NewContext("$root", nil))
})
return d.data, d.err
}
type fakeOpenAPIClient struct {
calls int
err error
}
func (f *fakeOpenAPIClient) OpenAPISchema() (*openapi_v2.Document, error) {
f.calls = f.calls + 1
if f.err != nil {
return nil, f.err
}
return data.OpenAPISchema()
}
var _ = Describe("Getting the Resources", func() {
var client *fakeOpenAPIClient
var expectedData openapi.Resources
@@ -38,7 +108,7 @@ var _ = Describe("Getting the Resources", func() {
expectedData, err = openapi.NewOpenAPIData(d)
Expect(err).To(BeNil())
instance = openapi.NewOpenAPIGetter("", "", client)
instance = openapi.NewOpenAPIGetter(client)
})
Context("when the server returns a successful result", func() {