mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #51546 from apelisse/remove-duplicate-fake-openapi
Automatic merge from submit-queue (batch tested with PRs 51682, 51546, 51369, 50924, 51827) Remove duplicate fake and unused openapi **What this PR does / why we need it**: Follow-up on PR #50404 **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
0f2a72f9f5
@ -36,13 +36,10 @@ go_test(
|
|||||||
deps = [
|
deps = [
|
||||||
":go_default_library",
|
":go_default_library",
|
||||||
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
|
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
|
||||||
"//vendor/github.com/googleapis/gnostic/OpenAPIv2:go_default_library",
|
|
||||||
"//vendor/github.com/googleapis/gnostic/compiler:go_default_library",
|
|
||||||
"//vendor/github.com/onsi/ginkgo:go_default_library",
|
"//vendor/github.com/onsi/ginkgo:go_default_library",
|
||||||
"//vendor/github.com/onsi/ginkgo/config:go_default_library",
|
"//vendor/github.com/onsi/ginkgo/config:go_default_library",
|
||||||
"//vendor/github.com/onsi/ginkgo/types:go_default_library",
|
"//vendor/github.com/onsi/ginkgo/types:go_default_library",
|
||||||
"//vendor/github.com/onsi/gomega:go_default_library",
|
"//vendor/github.com/onsi/gomega:go_default_library",
|
||||||
"//vendor/gopkg.in/yaml.v2:go_default_library",
|
|
||||||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -18,15 +18,7 @@ package openapi_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"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/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
@ -34,68 +26,6 @@ import (
|
|||||||
tst "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
|
tst "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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 _ = Describe("Getting the Resources", func() {
|
||||||
var client *tst.FakeClient
|
var client *tst.FakeClient
|
||||||
var expectedData openapi.Resources
|
var expectedData openapi.Resources
|
||||||
|
Loading…
Reference in New Issue
Block a user