containerized-data-importer/tests/apiserver_test.go
Michael Henriksen 7cd9a9145a
apiserver should serve up openapi spec (#1485)
Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
2020-11-17 19:47:57 +01:00

52 lines
1.0 KiB
Go

package tests_test
import (
"crypto/tls"
"fmt"
"net/http"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"kubevirt.io/containerized-data-importer/tests/framework"
)
var _ = Describe("cdi-apiserver tests", func() {
f := framework.NewFramework("cdi-apiserver-test", framework.Config{})
Context("with apiserver", func() {
It("should serve an openapi spec", func() {
hostPort, cmd, err := startServicePortForward(f, "cdi-api")
Expect(err).ToNot(HaveOccurred())
defer func() {
cmd.Process.Kill()
cmd.Wait()
}()
url := fmt.Sprintf("https://%s/openapi/v2", hostPort)
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
Eventually(func() error {
req, err := http.NewRequest("GET", url, nil)
Expect(err).ToNot(HaveOccurred())
resp, err := client.Do(req)
if err != nil {
return err
}
Expect(resp.StatusCode).To(Equal(200))
return nil
}, 10*time.Second, 1*time.Second).ShouldNot(HaveOccurred())
})
})
})