kubectl/pkg/framework/test/integration/integration_test.go

83 lines
2.3 KiB
Go

package integration_test
import (
"net"
"time"
"fmt"
"net/url"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/kubectl/pkg/framework/test"
)
var _ = Describe("The Testing Framework", func() {
It("Successfully manages the fixtures lifecycle", func() {
var err error
var fixtures *test.Fixtures
fixtures, err = test.NewFixtures()
Expect(err).NotTo(HaveOccurred())
By("Starting all the fixture processes")
err = fixtures.Start()
Expect(err).NotTo(HaveOccurred(), "Expected fixtures to start successfully")
var apiServerURL, etcdClientURL *url.URL
etcdUrlString, err := fixtures.APIServer.(*test.APIServer).Etcd.URL()
Expect(err).NotTo(HaveOccurred())
etcdClientURL, err = url.Parse(etcdUrlString)
Expect(err).NotTo(HaveOccurred())
urlString, err := fixtures.APIServerURL()
Expect(err).NotTo(HaveOccurred())
apiServerURL, err = url.Parse(urlString)
Expect(err).NotTo(HaveOccurred())
isEtcdListeningForClients := isSomethingListeningOnPort(etcdClientURL.Host)
isAPIServerListening := isSomethingListeningOnPort(apiServerURL.Host)
By("Ensuring Etcd is listening")
Expect(isEtcdListeningForClients()).To(BeTrue(),
fmt.Sprintf("Expected Etcd to listen for clients on %s,", etcdClientURL.Host))
By("Ensuring APIServer is listening")
Expect(isAPIServerListening()).To(BeTrue(),
fmt.Sprintf("Expected APIServer to listen on %s", apiServerURL.Host))
By("Stopping all the fixture processes")
err = fixtures.Stop()
Expect(err).NotTo(HaveOccurred(), "Expected fixtures to stop successfully")
By("Ensuring Etcd is not listening anymore")
Expect(isEtcdListeningForClients()).To(BeFalse(), "Expected Etcd not to listen for clients anymore")
By("Ensuring APIServer is not listening anymore")
Expect(isAPIServerListening()).To(BeFalse(), "Expected APIServer not to listen anymore")
})
Measure("It should be fast to bring up and tear down the fixtures", func(b Benchmarker) {
b.Time("lifecycle", func() {
fixtures, err := test.NewFixtures()
Expect(err).NotTo(HaveOccurred())
fixtures.Start()
fixtures.Stop()
})
}, 10)
})
type portChecker func() bool
func isSomethingListeningOnPort(hostAndPort string) portChecker {
return func() bool {
conn, err := net.DialTimeout("tcp", hostAndPort, 1*time.Second)
if err != nil {
return false
}
conn.Close()
return true
}
}