add test for StreamInterface
Add test for the newly added StreamInterface
@@ -22,6 +22,7 @@ package kubecli
import (
"net/http"
+ "github.com/gorilla/websocket"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
@@ -37,6 +38,7 @@ import (
var _ = Describe("Kubevirt VM Client", func() {
+ var upgrader websocket.Upgrader
var server *ghttp.Server
var client KubevirtClient
basePath := "/apis/kubevirt.io/v1alpha1/namespaces/default/virtualmachines"
@@ -125,6 +127,35 @@ var _ = Describe("Kubevirt VM Client", func() {
Expect(err).ToNot(HaveOccurred())
})
+ It("should allow to connect a stream to a VM", func() {
+ vncPath := "/apis/subresources.kubevirt.io/v1alpha1/namespaces/default/virtualmachines/testvm/vnc"
+
+ server.AppendHandlers(ghttp.CombineHandlers(
+ ghttp.VerifyRequest("GET", vncPath),
+ func(w http.ResponseWriter, r *http.Request) {
+ _, err := upgrader.Upgrade(w, r, nil)
+ if err != nil {
+ return
+ }
+ },
+ ))
+ _, err := client.VM(k8sv1.NamespaceDefault).VNC("testvm")
+ Expect(err).ToNot(HaveOccurred())
+ })
+
+ It("should handle a failure connecting to the VM", func() {
+ vncPath := "/apis/subresources.kubevirt.io/v1alpha1/namespaces/default/virtualmachines/testvm/vnc"
+
+ server.AppendHandlers(ghttp.CombineHandlers(
+ ghttp.VerifyRequest("GET", vncPath),
+ func(w http.ResponseWriter, r *http.Request) {
+ return
+ },
+ ))
+ _, err := client.VM(k8sv1.NamespaceDefault).VNC("testvm")
+ Expect(err).To(HaveOccurred())
+ })
+
AfterEach(func() {
server.Close()
})
