...
1
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