From e7bb1e8df96c48502045f284b247d691b4bd90f5 Mon Sep 17 00:00:00 2001 From: Gareth Smith Date: Fri, 24 Nov 2017 10:20:07 +0000 Subject: [PATCH] Add fixtures tintegration tests Testing the lifecycle of our fixtures with the real binaries. Test if we can start the fixtures, the porcesses actually listen on the ports and if we tear down all the parts successfully again. --- .../integration/integration_suite_test.go | 19 +++++++ .../test/integration/integration_test.go | 53 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 pkg/framework/test/integration/integration_suite_test.go create mode 100644 pkg/framework/test/integration/integration_test.go diff --git a/pkg/framework/test/integration/integration_suite_test.go b/pkg/framework/test/integration/integration_suite_test.go new file mode 100644 index 000000000..397d4feee --- /dev/null +++ b/pkg/framework/test/integration/integration_suite_test.go @@ -0,0 +1,19 @@ +package integration_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "testing" + + "github.com/onsi/gomega/gexec" +) + +func TestIntegration(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Integration Suite") +} + +var _ = AfterSuite(func() { + gexec.TerminateAndWait() +}) diff --git a/pkg/framework/test/integration/integration_test.go b/pkg/framework/test/integration/integration_test.go new file mode 100644 index 000000000..52d180ac1 --- /dev/null +++ b/pkg/framework/test/integration/integration_test.go @@ -0,0 +1,53 @@ +package integration_test + +import ( + "fmt" + "net" + "os" + "path/filepath" + "time" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "k8s.io/kubectl/pkg/framework/test" +) + +var _ = Describe("Integration", func() { + It("Successfully manages the fixtures lifecycle", func() { + assetsDir, ok := os.LookupEnv("KUBE_ASSETS_DIR") + Expect(ok).To(BeTrue(), "Expected $KUBE_ASSETS_DIR to be set") + + pathToEtcd := filepath.Join(assetsDir, "etcd") + pathToApiserver := filepath.Join(assetsDir, "kube-apiserver") + + fixtures := test.NewFixtures(pathToEtcd, pathToApiserver) + + err := fixtures.Start() + Expect(err).NotTo(HaveOccurred(), "Expected fixtures to start successfully") + + Eventually(func() bool { + return isSomethingListeningOnPort(2379) + }, 5*time.Second).Should(BeTrue(), "Expected Etcd to listen on 2379") + + Eventually(func() bool { + return isSomethingListeningOnPort(8080) + }, 5*time.Second).Should(BeTrue(), "Expected APIServer to listen on 8080") + + err = fixtures.Stop() + Expect(err).NotTo(HaveOccurred(), "Expected fixtures to stop successfully") + + Expect(isSomethingListeningOnPort(2379)).To(BeFalse(), "Expected Etcd not to listen anymore") + + By("Ensuring APIServer is not listening anymore") + Expect(isSomethingListeningOnPort(8080)).To(BeFalse(), "Expected APIServer not to listen anymore") + }) +}) + +func isSomethingListeningOnPort(port int) bool { + conn, err := net.DialTimeout("tcp", net.JoinHostPort("", fmt.Sprintf("%d", port)), 1*time.Second) + if err != nil { + return false + } + conn.Close() + return true +}