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.
This commit is contained in:
Gareth Smith 2017-11-24 10:20:07 +00:00
parent 8a92d310ba
commit e7bb1e8df9
2 changed files with 72 additions and 0 deletions

View File

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

View File

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