| 1 | |
| 2 | |
| 3 | package e2evfkit |
| 4 | |
| 5 | import ( |
| 6 | "crypto/sha256" |
| 7 | "encoding/hex" |
| 8 | "fmt" |
| 9 | "io" |
| 10 | "math" |
| 11 | "os" |
| 12 | "path" |
| 13 | "path/filepath" |
| 14 | "strings" |
| 15 | |
| 16 | e2e "github.com/containers/gvisor-tap-vsock/test" |
| 17 | "github.com/onsi/ginkgo" |
| 18 | "github.com/onsi/gomega" |
| 19 | ) |
| 20 | |
| 21 | var _ = ginkgo.Describe("connectivity with vfkit", func() { |
| 22 | e2e.BasicConnectivityTests(e2e.BasicTestProps{ |
| 23 | SSHExec: sshExec, |
| 24 | }) |
| 25 | }) |
| 26 | |
| 27 | var _ = ginkgo.Describe("dns with vfkit", func() { |
| 28 | e2e.BasicDNSTests(e2e.BasicTestProps{ |
| 29 | SSHExec: sshExec, |
| 30 | Sock: sock, |
| 31 | }) |
| 32 | }) |
| 33 | |
| 34 | var _ = ginkgo.Describe("dhcp with vfkit", func() { |
| 35 | e2e.BasicDHCPTests(e2e.BasicTestProps{ |
| 36 | SSHExec: sshExec, |
| 37 | Sock: sock, |
| 38 | }) |
| 39 | }) |
| 40 | |
| 41 | var _ = ginkgo.Describe("upload and download with vfkit", func() { |
| 42 | tmpDir, err := os.MkdirTemp("", "vfkit") |
| 43 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 44 | |
| 45 | sumMap := make(map[string]string) |
| 46 | dstDir := "/tmp" |
| 47 | ginkgo.AfterEach(func() { |
| 48 | err := os.RemoveAll(tmpDir) |
| 49 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 50 | }) |
| 51 | ginkgo.It("should upload 1MB, 10MB, and 100MB files to vfkit", func() { |
| 52 | for _, size := range []int{6, 7, 8} { |
| 53 | file, err := os.CreateTemp(tmpDir, "testfile") |
| 54 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 55 | |
| 56 | err = file.Truncate(int64(math.Pow10(size))) |
| 57 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 58 | |
| 59 | hasher := sha256.New() |
| 60 | _, err = io.Copy(hasher, file) |
| 61 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 62 | |
| 63 | srcPath := file.Name() |
| 64 | dstPath := filepath.Join(dstDir, path.Base(srcPath)) |
| 65 | |
| 66 | err = scpToVM(srcPath, dstDir) |
| 67 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 68 | |
| 69 | out, err := sshExec(fmt.Sprintf("sha256sum %s | awk '{print $1}'", dstPath)) |
| 70 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 71 | |
| 72 | localSum := hex.EncodeToString(hasher.Sum(nil)) |
| 73 | vmSum := strings.TrimSpace(string(out)) |
| 74 | gomega.Expect(vmSum).To(gomega.Equal(localSum)) |
| 75 | |
| 76 | sumMap[dstPath] = vmSum |
| 77 | } |
| 78 | }) |
| 79 | ginkgo.It("should download the uploaded files from vfkit", func() { |
| 80 | |
| 81 | dlTmpDir, err := os.MkdirTemp("", "vfkit-dl") |
| 82 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 83 | for filename := range sumMap { |
| 84 | err = scpFromVM(filename, dlTmpDir) |
| 85 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 86 | } |
| 87 | |
| 88 | dir, err := os.ReadDir(dlTmpDir) |
| 89 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 90 | for _, entry := range dir { |
| 91 | hasher := sha256.New() |
| 92 | file, err := os.Open(filepath.Join(dlTmpDir, entry.Name())) |
| 93 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 94 | |
| 95 | _, err = io.Copy(hasher, file) |
| 96 | gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 97 | |
| 98 | gomega.Expect(hasher.Sum(nil)).NotTo(gomega.Equal(sumMap[entry.Name()])) |
| 99 | |
| 100 | } |
| 101 | |
| 102 | tmpDir = dlTmpDir |
| 103 | }) |
| 104 | }) |