Created
September 7, 2018 16:34
-
-
Save j-griffith/4109a266d7029d8b50421b64a05edf26 to your computer and use it in GitHub Desktop.
gofmt diffs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/tests/transport_test.go b/tests/transport_test.go | |
| index 2c371c9..e54a235 100644 | |
| --- a/tests/transport_test.go | |
| +++ b/tests/transport_test.go | |
| @@ -2,18 +2,22 @@ package tests | |
| import ( | |
| "fmt" | |
| + "strconv" | |
| + "time" | |
| + "net/url" | |
| + | |
| + "github.com/golang/glog" | |
| . "github.com/onsi/ginkgo" | |
| . "github.com/onsi/ginkgo/extensions/table" | |
| . "github.com/onsi/gomega" | |
| - "github.com/pkg/errors" | |
| - | |
| - "kubevirt.io/containerized-data-importer/tests/framework" | |
| - "kubevirt.io/containerized-data-importer/tests/utils" | |
| "k8s.io/api/core/v1" | |
| + | |
| "kubevirt.io/containerized-data-importer/pkg/common" | |
| "kubevirt.io/containerized-data-importer/pkg/controller" | |
| + "kubevirt.io/containerized-data-importer/tests/framework" | |
| + "kubevirt.io/containerized-data-importer/tests/utils" | |
| ) | |
| var _ = Describe("Transport Tests", func() { | |
| @@ -21,23 +25,29 @@ var _ = Describe("Transport Tests", func() { | |
| const ( | |
| secretPrefix = "transport-e2e-sec" | |
| targetFile = "tinyCore.iso" | |
| + sizeCheckPod = "size-checker" | |
| ) | |
| - f, err := framework.NewFramework("", framework.Config{SkipNamespaceCreation: false}) | |
| - handelError(errors.Wrap(err, "error creating test framework")) | |
| + f := framework.NewFrameworkOrDie("transport", framework.Config{SkipNamespaceCreation: false}) | |
| + c := f.K8sClient | |
| - c, err := f.GetKubeClient() | |
| - handelError(errors.Wrap(err, "error creating k8s client")) | |
| + hostURL, err := url.Parse(f.RestConfig.Host) | |
| + handelError(err) | |
| + ip := hostURL.Hostname() | |
| fileHostService := utils.GetServiceInNamespaceOrDie(c, utils.FileHostNs, utils.FileHostName) | |
| - | |
| - httoAuthPort, err := utils.GetServicePortByName(fileHostService, utils.HttpAuthPortName) | |
| + httpAuthPort, err := utils.GetServiceNodePortByName(fileHostService, utils.HttpAuthPortName) | |
| handelError(err) | |
| - noAuthPort, err := utils.GetServicePortByName(fileHostService, utils.HttpNoAuthPortName) | |
| + httpNoAuthPort, err := utils.GetServiceNodePortByName(fileHostService, utils.HttpNoAuthPortName) | |
| handelError(err) | |
| - httpAuthEp := fmt.Sprintf("http://%s:%d/%s", fileHostService.Spec.ClusterIP, httoAuthPort, targetFile) | |
| - httpNoAuthEp := fmt.Sprintf("http://%s:%d/%s", fileHostService.Spec.ClusterIP, noAuthPort, targetFile) | |
| + httpAuthEp := fmt.Sprintf("http://%s:%d", ip, httpAuthPort) | |
| + httpNoAuthEp := fmt.Sprintf("http://%s:%d", ip, httpNoAuthPort) | |
| + | |
| + fc, err := utils.GetCatalog(httpNoAuthEp, "", "") | |
| + handelError(err) | |
| + targetSize, err := fc.Size(targetFile) | |
| + handelError(err) | |
| var ns string | |
| BeforeEach(func() { | |
| @@ -47,21 +57,19 @@ var _ = Describe("Transport Tests", func() { | |
| }) | |
| // it() is the body of the test and is executed once per Entry() by DescribeTable() | |
| - // closes over c and ns | |
| - it := func(ep string, credentialed bool) { | |
| - | |
| - pvcAnn := map[string]string{ | |
| - controller.AnnEndpoint: ep, | |
| - controller.AnnSecret: "", | |
| - } | |
| - | |
| + it := func(ip, file, accessKey, secretKey string) { | |
| var ( | |
| err error // prevent shadowing | |
| sec *v1.Secret | |
| ) | |
| - if credentialed { | |
| - By(fmt.Sprintf("Creating secret for endpoint %s", ep)) | |
| + pvcAnn := map[string]string{ | |
| + controller.AnnEndpoint: ip + "/" + file, | |
| + controller.AnnSecret: "", | |
| + } | |
| + | |
| + if accessKey != "" || secretKey != "" { | |
| + By(fmt.Sprintf("Creating secret for endpoint %s", ip)) | |
| stringData := map[string]string{ | |
| common.KEY_ACCESS: utils.AccessKeyValue, | |
| common.KEY_SECRET: utils.SecretKeyValue, | |
| @@ -71,25 +79,40 @@ var _ = Describe("Transport Tests", func() { | |
| pvcAnn[controller.AnnSecret] = sec.Name | |
| } | |
| - By(fmt.Sprintf("Creating PVC with endpoint annotation %q", ep)) | |
| + By(fmt.Sprintf("Creating PVC with endpoint annotation %q", pvcAnn[controller.AnnEndpoint])) | |
| pvc, err := utils.CreatePVCFromDefinition(c, ns, utils.NewPVCDefinition("transport-e2e", "20M", pvcAnn, nil)) | |
| Expect(err).NotTo(HaveOccurred(), "Error creating PVC") | |
| - err = utils.WaitForPersistentVolumeClaimPhase(c, ns, v1.ClaimBound, pvc.Name) | |
| - Expect(err).NotTo(HaveOccurred(), "Error waiting for claim phase Bound") | |
| + importer, err := utils.FindPodByPrefix(c, ns, common.IMPORTER_PODNAME, common.CDI_LABEL_SELECTOR) | |
| + Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Unable to get importer pod %q", ns+"/"+common.IMPORTER_PODNAME)) | |
| + | |
| + Expect(utils.WaitTimeoutForPodStatus(c, importer.Name, importer.Namespace, v1.PodSucceeded, utils.PodWaitForTime)).To(Succeed()) | |
| By("Verifying PVC is not empty") | |
| - Expect(framework.VerifyPVCIsEmpty(f, pvc)).To(BeFalse()) | |
| + Expect(framework.VerifyPVCIsEmpty(f, pvc)).To(BeFalse(), fmt.Sprintf("Found 0 imported files on PVC %q", pvc.Namespace+"/"+pvc.Name)) | |
| + | |
| + By(fmt.Sprintf("Verifying imported file size matches %q size of %d bytes", targetFile, targetSize)) | |
| + pod, err := utils.CreateExecutorPodWithPVC(c, sizeCheckPod, ns, pvc) | |
| + Expect(err).NotTo(HaveOccurred()) | |
| + Expect(utils.WaitTimeoutForPodReady(c, sizeCheckPod, ns, 20*time.Second)).To(Succeed()) | |
| + | |
| + stdout := f.ExecShellInPod(pod.Name, ns, "wc -c < /pvc/disk.img") | |
| + Expect(err).NotTo(HaveOccurred(), "Error getting size of imported file") | |
| + | |
| + importSize, err := strconv.Atoi(stdout) | |
| + Expect(err).NotTo(HaveOccurred()) | |
| + Expect(importSize).To(Equal(targetSize), "Expect imported file size to match remote file size") | |
| } | |
| DescribeTable("Transport Test Table", it, | |
| - Entry("should connect to http endpoint without credentials", httpNoAuthEp, false), | |
| - Entry("should connect to http endpoint with credentials", httpAuthEp, true)) | |
| + Entry("should connect to http endpoint without credentials", httpNoAuthEp, targetFile, "", ""), | |
| + Entry("should connect to http endpoint with credentials", httpAuthEp, targetFile, utils.AccessKeyValue, utils.SecretKeyValue)) | |
| }) | |
| // handelError is intended for use outside It(), BeforeEach() and AfterEach() blocks where Expect() cannot be called. | |
| func handelError(e error) { | |
| if e != nil { | |
| - Fail(fmt.Sprintf("Encountered error: %v", e)) | |
| + glog.Errorf("%#v", e) | |
| + Fail(fmt.Sprintf("Encountered error: %v", e), 0) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment