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.
This commit is contained in:
Hannes Hörl 2017-12-05 12:31:03 +00:00 committed by Gareth Smith
parent e8c6a13d49
commit 2d275663fe
2 changed files with 18 additions and 5 deletions

View File

@ -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")

View File

@ -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))