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:
@@ -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() {
|
||||
|
Reference in New Issue
Block a user