...

Source file src/kubevirt.io/client-go/kubecli/version_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 2018 Red Hat, Inc.
    17   *
    18   */
    19  
    20  package kubecli
    21  
    22  import (
    23  	"fmt"
    24  	"net/http"
    25  	"path"
    26  	"runtime"
    27  	"time"
    28  
    29  	. "github.com/onsi/ginkgo/v2"
    30  	. "github.com/onsi/gomega"
    31  	"github.com/onsi/gomega/ghttp"
    32  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    33  
    34  	"kubevirt.io/client-go/version"
    35  )
    36  
    37  var _ = Describe("Kubevirt Version Client", func() {
    38  	var server *ghttp.Server
    39  	proxyPath := "/proxy/path"
    40  
    41  	BeforeEach(func() {
    42  		server = ghttp.NewServer()
    43  	})
    44  
    45  	AfterEach(func() {
    46  		server.Close()
    47  	})
    48  
    49  	DescribeTable("should fetch version", func(proxyPath string) {
    50  		client, err := GetKubevirtClientFromFlags(server.URL()+proxyPath, "")
    51  		Expect(err).ToNot(HaveOccurred())
    52  
    53  		groupInfo := metav1.APIGroup{
    54  			Name:             ApiGroupName,
    55  			PreferredVersion: metav1.GroupVersionForDiscovery{GroupVersion: ApiGroupName + "/v1alpha3", Version: "v1alpha3"},
    56  		}
    57  
    58  		info := version.Info{GitVersion: "v0.5.1-alpha.1.43+fda30004223b51-clean",
    59  			GitCommit:    "fda30004223b51f9e604276419a2b376652cb5ad",
    60  			GitTreeState: "clear",
    61  			BuildDate:    time.Now().Format("%Y-%m-%dT%H:%M:%SZ"),
    62  			GoVersion:    runtime.Version(),
    63  			Compiler:     runtime.Compiler,
    64  			Platform:     fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)}
    65  
    66  		server.AppendHandlers(
    67  			ghttp.CombineHandlers(
    68  				ghttp.VerifyRequest("GET", path.Join(proxyPath, ApiGroupName)),
    69  				ghttp.RespondWithJSONEncoded(http.StatusOK, groupInfo),
    70  			),
    71  			ghttp.CombineHandlers(
    72  				ghttp.VerifyRequest("GET", path.Join(proxyPath, "/apis"+groupInfo.PreferredVersion.GroupVersion+"/version")),
    73  				ghttp.RespondWithJSONEncoded(http.StatusOK, info),
    74  			),
    75  		)
    76  
    77  		fetchedVersion, err := client.ServerVersion().Get()
    78  		Expect(err).ToNot(HaveOccurred())
    79  		Expect(fetchedVersion.Compiler).To(Equal(runtime.Compiler))
    80  		Expect(fetchedVersion.GitTreeState).To(Equal(info.GitTreeState))
    81  		Expect(fetchedVersion.BuildDate).To(Equal(info.BuildDate))
    82  		Expect(fetchedVersion.GoVersion).To(Equal(info.GoVersion))
    83  		Expect(fetchedVersion.Platform).To(Equal(info.Platform))
    84  	},
    85  		Entry("with regular server URL", ""),
    86  		Entry("with proxied server URL", proxyPath),
    87  	)
    88  })
    89  

View as plain text