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:
parent
e8c6a13d49
commit
2d275663fe
|
|
@ -30,15 +30,25 @@ var listPodsCmd = &cobra.Command{
|
||||||
Short: "List all pods",
|
Short: "List all pods",
|
||||||
Long: `Give a list of all pods known by the system`,
|
Long: `Give a list of all pods known by the system`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
runGetPods()
|
apiURL, err := cmd.Flags().GetString("api-url")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
runGetPods(apiURL)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func runGetPods() {
|
func runGetPods(apiURL string) {
|
||||||
config, _ := clientcmd.BuildConfigFromFlags("http://localhost:8080", "")
|
config, err := clientcmd.BuildConfigFromFlags(apiURL, "")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
// create the clientset
|
// 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{})
|
pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -55,6 +65,8 @@ func init() {
|
||||||
|
|
||||||
// Here you will define your flags and configuration settings.
|
// 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
|
// Cobra supports Persistent Flags which will work for this command
|
||||||
// and all subcommands, e.g.:
|
// and all subcommands, e.g.:
|
||||||
// listPodsCmd.PersistentFlags().String("foo", "", "A help for foo")
|
// listPodsCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ var _ = Describe("DemoCLI Integration", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("can get a list of pods", 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)
|
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Eventually(session).Should(gexec.Exit(0))
|
Eventually(session).Should(gexec.Exit(0))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue