2017-04-14 01:01:38 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-05-04 01:14:14 +00:00
|
|
|
package openapi_test
|
2017-04-14 01:01:38 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2017-05-04 01:14:14 +00:00
|
|
|
|
|
|
|
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
|
2017-09-06 18:34:28 +00:00
|
|
|
tst "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
|
2017-04-14 01:01:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Getting the Resources", func() {
|
2017-08-06 16:35:17 +00:00
|
|
|
var client *tst.FakeClient
|
2017-09-06 18:34:28 +00:00
|
|
|
var expectedData openapi.Resources
|
2017-05-04 01:14:14 +00:00
|
|
|
var instance openapi.Getter
|
2017-04-14 01:01:38 +00:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
2017-08-06 16:35:17 +00:00
|
|
|
client = tst.NewFakeClient(&fakeSchema)
|
|
|
|
d, err := fakeSchema.OpenAPISchema()
|
2017-04-14 01:01:38 +00:00
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
2017-09-06 18:34:28 +00:00
|
|
|
expectedData, err = openapi.NewOpenAPIData(d)
|
2017-04-14 01:01:38 +00:00
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
2017-08-08 22:00:23 +00:00
|
|
|
instance = openapi.NewOpenAPIGetter(client)
|
2017-04-14 01:01:38 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Context("when the server returns a successful result", func() {
|
|
|
|
It("should return the same data for multiple calls", func() {
|
2017-08-06 16:35:17 +00:00
|
|
|
Expect(client.Calls).To(Equal(0))
|
2017-04-14 01:01:38 +00:00
|
|
|
|
|
|
|
result, err := instance.Get()
|
|
|
|
Expect(err).To(BeNil())
|
2017-06-14 23:30:57 +00:00
|
|
|
Expect(result).To(Equal(expectedData))
|
2017-08-06 16:35:17 +00:00
|
|
|
Expect(client.Calls).To(Equal(1))
|
2017-04-14 01:01:38 +00:00
|
|
|
|
|
|
|
result, err = instance.Get()
|
|
|
|
Expect(err).To(BeNil())
|
2017-06-14 23:30:57 +00:00
|
|
|
Expect(result).To(Equal(expectedData))
|
2017-04-14 01:01:38 +00:00
|
|
|
// No additional client calls expected
|
2017-08-06 16:35:17 +00:00
|
|
|
Expect(client.Calls).To(Equal(1))
|
2017-04-14 01:01:38 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Context("when the server returns an unsuccessful result", func() {
|
|
|
|
It("should return the same instance for multiple calls.", func() {
|
2017-08-06 16:35:17 +00:00
|
|
|
Expect(client.Calls).To(Equal(0))
|
2017-04-14 01:01:38 +00:00
|
|
|
|
2017-08-06 16:35:17 +00:00
|
|
|
client.Err = fmt.Errorf("expected error")
|
2017-04-14 01:01:38 +00:00
|
|
|
_, err := instance.Get()
|
2017-08-06 16:35:17 +00:00
|
|
|
Expect(err).To(Equal(client.Err))
|
|
|
|
Expect(client.Calls).To(Equal(1))
|
2017-04-14 01:01:38 +00:00
|
|
|
|
|
|
|
_, err = instance.Get()
|
2017-08-06 16:35:17 +00:00
|
|
|
Expect(err).To(Equal(client.Err))
|
2017-04-14 01:01:38 +00:00
|
|
|
// No additional client calls expected
|
2017-08-06 16:35:17 +00:00
|
|
|
Expect(client.Calls).To(Equal(1))
|
2017-04-14 01:01:38 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|