forked from quic-go/quic-go
add an integration test downloading a small file with Chrome
This commit is contained in:
committed by
Lucas Clemente
parent
8b845fada9
commit
251c0eed8f
@@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/tebeka/selenium"
|
||||
|
||||
@@ -114,9 +116,28 @@ var _ = Describe("Chrome tests", func() {
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}).ShouldNot(HaveOccurred())
|
||||
}, 5).ShouldNot(HaveOccurred())
|
||||
close(done)
|
||||
}, 10)
|
||||
|
||||
It("downloads a small file", func(done Done) {
|
||||
var err error
|
||||
err = wd.Get("https://quic.clemente.io/data")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
var file *os.File
|
||||
Eventually(func() error {
|
||||
file, err = os.Open(filepath.Join(downloadDir, "data"))
|
||||
return err
|
||||
}, 30, 0.1).ShouldNot(HaveOccurred())
|
||||
fi, err := file.Stat()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Eventually(fi.Size(), 10, 0.1).Should(Equal(int64(dataLen)))
|
||||
contents := make([]byte, dataLen)
|
||||
_, err = file.Read(contents)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(contents).To(Equal(data))
|
||||
close(done)
|
||||
}, 60)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -4,9 +4,12 @@ import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -28,9 +31,10 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
server *h2quic.Server
|
||||
data []byte
|
||||
port string
|
||||
server *h2quic.Server
|
||||
data []byte
|
||||
port string
|
||||
downloadDir string
|
||||
|
||||
docker *gexec.Session
|
||||
)
|
||||
@@ -43,6 +47,7 @@ func TestIntegration(t *testing.T) {
|
||||
var _ = BeforeSuite(func() {
|
||||
setupHTTPHandlers()
|
||||
setupQuicServer()
|
||||
setupDownloadDir()
|
||||
setupSelenium()
|
||||
})
|
||||
|
||||
@@ -51,8 +56,13 @@ var _ = AfterSuite(func() {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
stopSelenium()
|
||||
removeDownloadDir()
|
||||
}, 5)
|
||||
|
||||
var _ = AfterEach(func() {
|
||||
clearDownloadDir()
|
||||
})
|
||||
|
||||
func setupHTTPHandlers() {
|
||||
defer GinkgoRecover()
|
||||
data = make([]byte, dataLen)
|
||||
@@ -111,6 +121,7 @@ func setupSelenium() {
|
||||
"-i",
|
||||
"--rm",
|
||||
"-p=4444:4444",
|
||||
fmt.Sprintf("-v=%s/:/home/seluser/Downloads/", downloadDir),
|
||||
"lclemente/standalone-chrome:latest",
|
||||
)
|
||||
docker, err = gexec.Start(dockerCmd, GinkgoWriter, GinkgoWriter)
|
||||
@@ -161,3 +172,31 @@ func GetLocalIP() string {
|
||||
}
|
||||
panic("no addr")
|
||||
}
|
||||
|
||||
// create a temporary directory for Chrome downloads
|
||||
// Docker will mount the Chrome download directory here
|
||||
func setupDownloadDir() {
|
||||
var err error
|
||||
downloadDir, err = ioutil.TempDir("/tmp", "quicgodownloads")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
// delete all files in the download directory
|
||||
func clearDownloadDir() {
|
||||
d, err := os.Open(downloadDir)
|
||||
defer d.Close()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
filenames, err := d.Readdirnames(-1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
for _, filename := range filenames {
|
||||
err := os.Remove(filepath.Join(downloadDir, filename))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
}
|
||||
|
||||
// delete the download directory
|
||||
// must be empty when calling this function
|
||||
func removeDownloadDir() {
|
||||
err := os.Remove(downloadDir)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user