...

Source file src/kubevirt.io/client-go/kubecli/instancetype_test.go

Documentation: kubevirt.io/client-go/kubecli

     1  /*
     2   * This file is part of the KubeVirt project
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   * Copyright 2022 Red Hat, Inc.
    17   *
    18   */
    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