From 2d275663fed019ba80c19e2b24cd7bdef0dad886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20H=C3=B6rl?= Date: Tue, 5 Dec 2017 12:31:03 +0000 Subject: [PATCH] Use the exposed configuration of the fixtures The fixtures now exposes the URL the API Server is listening on. We can get this with from `Fixtures.Config.APIServerURL`. When we start our client program in the test, we pass that API Server URL in via a command line flag. --- pkg/framework/test/democli/cmd/listPods.go | 20 +++++++++++++++---- .../democli/integration/integration_test.go | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/framework/test/democli/cmd/listPods.go b/pkg/framework/test/democli/cmd/listPods.go index 8274c1338..0cf42cf61 100644 --- a/pkg/framework/test/democli/cmd/listPods.go +++ b/pkg/framework/test/democli/cmd/listPods.go @@ -30,15 +30,25 @@ var listPodsCmd = &cobra.Command{ Short: "List all pods", Long: `Give a list of all pods known by the system`, Run: func(cmd *cobra.Command, args []string) { - runGetPods() + apiURL, err := cmd.Flags().GetString("api-url") + if err != nil { + panic(err) + } + runGetPods(apiURL) }, } -func runGetPods() { - config, _ := clientcmd.BuildConfigFromFlags("http://localhost:8080", "") +func runGetPods(apiURL string) { + config, err := clientcmd.BuildConfigFromFlags(apiURL, "") + if err != nil { + panic(err) + } // create the clientset - clientset, _ := kubernetes.NewForConfig(config) + clientset, err := kubernetes.NewForConfig(config) + if err != nil { + panic(err) + } pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{}) if err != nil { @@ -55,6 +65,8 @@ func init() { // Here you will define your flags and configuration settings. + listPodsCmd.Flags().String("api-url", "http://localhost:8080", "URL of the APIServer to connect to") + // Cobra supports Persistent Flags which will work for this command // and all subcommands, e.g.: // listPodsCmd.PersistentFlags().String("foo", "", "A help for foo") diff --git a/pkg/framework/test/democli/integration/integration_test.go b/pkg/framework/test/democli/integration/integration_test.go index f0cfee608..a8f474570 100644 --- a/pkg/framework/test/democli/integration/integration_test.go +++ b/pkg/framework/test/democli/integration/integration_test.go @@ -21,7 +21,8 @@ var _ = Describe("DemoCLI Integration", func() { }) It("can get a list of pods", func() { - command := exec.Command(pathToDemoCommand, "listPods") + apiURL := fixtures.Config.APIServerURL + command := exec.Command(pathToDemoCommand, "listPods", "--api-url", apiURL) session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) Eventually(session).Should(gexec.Exit(0))