openapi: Make file client more easy to re-use

A few notes about the change:
1. I need to initialize the fileclient once, in an init function, so I
don't have access to `testing.T` yet.
2. I want to be able to configure the openapi files that I use
3. We already have a "cache" client that wraps another client, we don't
need to re-implement caching here, one can just do:
`cache.NewClient(openapitest.NewFileClient("some/path"))` to do a cached
client. Or initialize it in an init/global var.

Since there is still some value to use the embedded file, make an
alternative constructor while using fs.FS interface to be able to
manipulate both virtual and disk-based filesystems.

Kubernetes-commit: 29503fd8d45bc2c9438e92936bf4111162529b40
This commit is contained in:
Antoine Pelisse
2023-03-28 13:40:28 -07:00
committed by Kubernetes Publisher
parent 861f50a667
commit 12beb34ceb
3 changed files with 84 additions and 51 deletions

View File

@@ -150,7 +150,7 @@ func TestOpenAPIV3Root_GVSpec(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client := openapitest.NewFileClient(t)
client := openapitest.NewEmbeddedFileClient()
root := NewRoot(client)
gvSpec, err := root.GVSpec(test.gv)
if test.err != nil {
@@ -209,8 +209,7 @@ func TestOpenAPIV3Root_GVSpecAsMap(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client := openapitest.NewFileClient(t)
root := NewRoot(client)
root := NewRoot(openapitest.NewEmbeddedFileClient())
gvSpecAsMap, err := root.GVSpecAsMap(test.gv)
if test.err != nil {
assert.True(t, reflect.DeepEqual(test.err, err))