From 567e7c60fa696d3332159fc9641d54f242c42804 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 24 Jun 2019 14:45:07 -0400 Subject: Add test for generate kube on a pod with ports Signed-off-by: Matthew Heon --- test/e2e/generate_kube_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'test/e2e') diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go index 40cc534c2..760ba6851 100644 --- a/test/e2e/generate_kube_test.go +++ b/test/e2e/generate_kube_test.go @@ -10,6 +10,7 @@ import ( "github.com/ghodss/yaml" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "k8s.io/api/core/v1" ) var _ = Describe("Podman generate kube", func() { @@ -106,6 +107,49 @@ var _ = Describe("Podman generate kube", func() { Expect(err).To(BeNil()) }) + It("podman generate kube on pod with ports", func() { + podName := "test" + podSession := podmanTest.Podman("pod", "create", "--name", podName, "-p", "4000:4000", "-p", "5000:5000") + podSession.WaitWithDefaultTimeout() + Expect(podSession.ExitCode()).To(Equal(0)) + + ctr1Name := "ctr1" + ctr1Session := podmanTest.Podman("create", "--name", ctr1Name, "--pod", podName, ALPINE, "top") + ctr1Session.WaitWithDefaultTimeout() + Expect(ctr1Session.ExitCode()).To(Equal(0)) + + ctr2Name := "ctr2" + ctr2Session := podmanTest.Podman("create", "--name", ctr2Name, "--pod", podName, ALPINE, "top") + ctr2Session.WaitWithDefaultTimeout() + Expect(ctr2Session.ExitCode()).To(Equal(0)) + + kube := podmanTest.Podman([]string{"generate", "kube", podName}) + kube.WaitWithDefaultTimeout() + Expect(kube.ExitCode()).To(Equal(0)) + + pod := new(v1.Pod) + err := yaml.Unmarshal(kube.OutputToString(), pod) + Expect(err).To(BeNil()) + + foundPort4000 := 0 + foundPort5000 := 0 + foundOtherPort := 0 + for _, ctr := range pod.Spec.Containers { + for _, port := range ctr.Ports { + if port.HostPort == 4000 { + foundPort4000 = foundPort4000 + 1 + } else if port.HostPort == 5000 { + foundPort5000 = foundPort5000 + 1 + } else { + foundOtherPort = foundOtherPort + 1 + } + } + } + Expect(foundPort4000).To(Equal(1)) + Expect(foundPort5000).To(Equal(1)) + Expect(foundOtherPort).To(Equal(0)) + }) + It("podman generate and reimport kube on pod", func() { podName := "toppod" _, rc, _ := podmanTest.CreatePod(podName) -- cgit v1.2.3-54-g00ecf From 803a2b04d17165a57b31d135368a08eace370e5b Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 24 Jun 2019 14:56:41 -0400 Subject: Change Marshal -> Unmarshal in generate kube tests We need to verify that valid YAML was produced - Marshal will just pack the generated YAML even further. Signed-off-by: Matthew Heon --- test/e2e/generate_kube_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'test/e2e') diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go index 760ba6851..4a14bddfa 100644 --- a/test/e2e/generate_kube_test.go +++ b/test/e2e/generate_kube_test.go @@ -58,7 +58,8 @@ var _ = Describe("Podman generate kube", func() { kube.WaitWithDefaultTimeout() Expect(kube.ExitCode()).To(Equal(0)) - _, err := yaml.Marshal(kube.OutputToString()) + pod := new(v1.Pod) + err := yaml.Unmarshal(kube.OutputToString(), pod) Expect(err).To(BeNil()) }) @@ -71,7 +72,8 @@ var _ = Describe("Podman generate kube", func() { kube.WaitWithDefaultTimeout() Expect(kube.ExitCode()).To(Equal(0)) - _, err := yaml.Marshal(kube.OutputToString()) + pod := new(v1.Pod) + err := yaml.Unmarshal(kube.OutputToString(), pod) Expect(err).To(BeNil()) }) @@ -87,7 +89,8 @@ var _ = Describe("Podman generate kube", func() { kube.WaitWithDefaultTimeout() Expect(kube.ExitCode()).To(Equal(0)) - _, err := yaml.Marshal(kube.OutputToString()) + pod := new(v1.Pod) + err := yaml.Unmarshal(kube.OutputToString(), pod) Expect(err).To(BeNil()) }) @@ -103,8 +106,10 @@ var _ = Describe("Podman generate kube", func() { kube.WaitWithDefaultTimeout() Expect(kube.ExitCode()).To(Equal(0)) - _, err := yaml.Marshal(kube.OutputToString()) - Expect(err).To(BeNil()) + // TODO: How do we test unmarshal with a service? We have two + // structs that need to be unmarshalled... + // _, err := yaml.Marshal(kube.OutputToString()) + // Expect(err).To(BeNil()) }) It("podman generate kube on pod with ports", func() { -- cgit v1.2.3-54-g00ecf From 79d835457da1b3498c355f0200b7d02d1069415f Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 24 Jun 2019 15:23:38 -0400 Subject: Fix tests Signed-off-by: Matthew Heon --- test/e2e/generate_kube_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test/e2e') diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go index 4a14bddfa..7871546c7 100644 --- a/test/e2e/generate_kube_test.go +++ b/test/e2e/generate_kube_test.go @@ -59,7 +59,7 @@ var _ = Describe("Podman generate kube", func() { Expect(kube.ExitCode()).To(Equal(0)) pod := new(v1.Pod) - err := yaml.Unmarshal(kube.OutputToString(), pod) + err := yaml.Unmarshal([]byte(kube.OutputToString()), pod) Expect(err).To(BeNil()) }) @@ -73,7 +73,7 @@ var _ = Describe("Podman generate kube", func() { Expect(kube.ExitCode()).To(Equal(0)) pod := new(v1.Pod) - err := yaml.Unmarshal(kube.OutputToString(), pod) + err := yaml.Unmarshal([]byte(kube.OutputToString()), pod) Expect(err).To(BeNil()) }) @@ -90,7 +90,7 @@ var _ = Describe("Podman generate kube", func() { Expect(kube.ExitCode()).To(Equal(0)) pod := new(v1.Pod) - err := yaml.Unmarshal(kube.OutputToString(), pod) + err := yaml.Unmarshal([]byte(kube.OutputToString()), pod) Expect(err).To(BeNil()) }) @@ -114,17 +114,17 @@ var _ = Describe("Podman generate kube", func() { It("podman generate kube on pod with ports", func() { podName := "test" - podSession := podmanTest.Podman("pod", "create", "--name", podName, "-p", "4000:4000", "-p", "5000:5000") + podSession := podmanTest.Podman([]string{"pod", "create", "--name", podName, "-p", "4000:4000", "-p", "5000:5000"}) podSession.WaitWithDefaultTimeout() Expect(podSession.ExitCode()).To(Equal(0)) ctr1Name := "ctr1" - ctr1Session := podmanTest.Podman("create", "--name", ctr1Name, "--pod", podName, ALPINE, "top") + ctr1Session := podmanTest.Podman([]string{"create", "--name", ctr1Name, "--pod", podName, ALPINE, "top"}) ctr1Session.WaitWithDefaultTimeout() Expect(ctr1Session.ExitCode()).To(Equal(0)) ctr2Name := "ctr2" - ctr2Session := podmanTest.Podman("create", "--name", ctr2Name, "--pod", podName, ALPINE, "top") + ctr2Session := podmanTest.Podman([]string{"create", "--name", ctr2Name, "--pod", podName, ALPINE, "top"}) ctr2Session.WaitWithDefaultTimeout() Expect(ctr2Session.ExitCode()).To(Equal(0)) @@ -133,7 +133,7 @@ var _ = Describe("Podman generate kube", func() { Expect(kube.ExitCode()).To(Equal(0)) pod := new(v1.Pod) - err := yaml.Unmarshal(kube.OutputToString(), pod) + err := yaml.Unmarshal([]byte(kube.OutputToString()), pod) Expect(err).To(BeNil()) foundPort4000 := 0 -- cgit v1.2.3-54-g00ecf From 101a5cd7556433f81238032bf9c44bbbb6b4cabc Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Tue, 25 Jun 2019 10:10:57 -0400 Subject: Use a different method to retrieve YAML output in tests OutputToString() was mangling newlines, which made YAML parsers very, very angry. But not angry enough to actually error, that would be too easy. Just angry enough to silently not decode anything. Signed-off-by: Matthew Heon --- test/e2e/generate_kube_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/e2e') diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go index 7871546c7..a51b42d9a 100644 --- a/test/e2e/generate_kube_test.go +++ b/test/e2e/generate_kube_test.go @@ -133,7 +133,7 @@ var _ = Describe("Podman generate kube", func() { Expect(kube.ExitCode()).To(Equal(0)) pod := new(v1.Pod) - err := yaml.Unmarshal([]byte(kube.OutputToString()), pod) + err := yaml.Unmarshal(kube.Out.Contents(), pod) Expect(err).To(BeNil()) foundPort4000 := 0 -- cgit v1.2.3-54-g00ecf From 068d3bb3bfe4fb68fee6ecbef13469e36e4a9a04 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Tue, 25 Jun 2019 11:15:03 -0400 Subject: Update 'generate kube' tests to verify YAML Signed-off-by: Matthew Heon --- test/e2e/generate_kube_test.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'test/e2e') diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go index a51b42d9a..1df54f753 100644 --- a/test/e2e/generate_kube_test.go +++ b/test/e2e/generate_kube_test.go @@ -59,8 +59,14 @@ var _ = Describe("Podman generate kube", func() { Expect(kube.ExitCode()).To(Equal(0)) pod := new(v1.Pod) - err := yaml.Unmarshal([]byte(kube.OutputToString()), pod) + err := yaml.Unmarshal(kube.Out.Contents(), pod) Expect(err).To(BeNil()) + + numContainers := 0 + for range pod.Spec.Containers { + numContainers = numContainers + 1 + } + Expect(numContainers).To(Equal(1)) }) It("podman generate service kube on container", func() { @@ -72,9 +78,11 @@ var _ = Describe("Podman generate kube", func() { kube.WaitWithDefaultTimeout() Expect(kube.ExitCode()).To(Equal(0)) - pod := new(v1.Pod) - err := yaml.Unmarshal([]byte(kube.OutputToString()), pod) - Expect(err).To(BeNil()) + // TODO - test generated YAML - service produces multiple + // structs. + // pod := new(v1.Pod) + // err := yaml.Unmarshal([]byte(kube.OutputToString()), pod) + // Expect(err).To(BeNil()) }) It("podman generate kube on pod", func() { @@ -90,8 +98,14 @@ var _ = Describe("Podman generate kube", func() { Expect(kube.ExitCode()).To(Equal(0)) pod := new(v1.Pod) - err := yaml.Unmarshal([]byte(kube.OutputToString()), pod) + err := yaml.Unmarshal(kube.Out.Contents(), pod) Expect(err).To(BeNil()) + + numContainers := 0 + for range pod.Spec.Containers { + numContainers = numContainers + 1 + } + Expect(numContainers).To(Equal(1)) }) It("podman generate service kube on pod", func() { -- cgit v1.2.3-54-g00ecf