...
1
19
20 package kubecli
21
22 import (
23 "fmt"
24 "net/http"
25 "path"
26
27 . "github.com/onsi/ginkgo/v2"
28 . "github.com/onsi/gomega"
29 "github.com/onsi/gomega/ghttp"
30 k8sv1 "k8s.io/api/core/v1"
31 v1 "kubevirt.io/api/core/v1"
32 )
33
34 var _ = Describe("Kubevirt ExpandSpec Client", func() {
35
36 var server *ghttp.Server
37 expandSpecPath := fmt.Sprintf("/apis/subresources.kubevirt.io/%s/namespaces/%s/expand-vm-spec", v1.SubresourceStorageGroupVersion.Version, k8sv1.NamespaceDefault)
38 proxyPath := "/proxy/path"
39
40 BeforeEach(func() {
41 server = ghttp.NewServer()
42 })
43
44 DescribeTable("should expand a VirtualMachine", func(proxyPath string) {
45 client, err := GetKubevirtClientFromFlags(server.URL()+proxyPath, "")
46 Expect(err).ToNot(HaveOccurred())
47
48 vm := NewMinimalVM("testvm")
49 server.AppendHandlers(ghttp.CombineHandlers(
50 ghttp.VerifyRequest("PUT", path.Join(proxyPath, expandSpecPath)),
51 ghttp.RespondWithJSONEncoded(http.StatusOK, vm),
52 ))
53 expandedVM, err := client.ExpandSpec(k8sv1.NamespaceDefault).ForVirtualMachine(vm)
54
55 Expect(server.ReceivedRequests()).To(HaveLen(1))
56 Expect(err).ToNot(HaveOccurred())
57 Expect(expandedVM).To(Equal(vm))
58 },
59 Entry("with regular server URL", ""),
60 Entry("with proxied server URL", proxyPath),
61 )
62
63 AfterEach(func() {
64 server.Close()
65 })
66 })
67
View as plain text