mirror of
https://github.com/cunnie/sslip.io.git
synced 2025-10-06 08:06:53 +08:00
Integration tests work intenetless by default
This is a convenience when I'm on a flight and feel like coding and the internet connection is spotty at best.
This commit is contained in:
@@ -23,7 +23,7 @@ var serverPath, _ = Build("main.go")
|
|||||||
|
|
||||||
var _ = BeforeSuite(func() {
|
var _ = BeforeSuite(func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
serverCmd = exec.Command(serverPath, "-port", strconv.Itoa(port))
|
serverCmd = exec.Command(serverPath, "-port", strconv.Itoa(port), "-blocklistURL", "file://../../etc/blocklist.txt")
|
||||||
serverSession, err = Start(serverCmd, GinkgoWriter, GinkgoWriter)
|
serverSession, err = Start(serverCmd, GinkgoWriter, GinkgoWriter)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
// takes 0.455s to start up on macOS Big Sur 3.7 GHz Quad Core 22-nm Xeon E5-1620v2 processor (2013 Mac Pro)
|
// takes 0.455s to start up on macOS Big Sur 3.7 GHz Quad Core 22-nm Xeon E5-1620v2 processor (2013 Mac Pro)
|
||||||
|
@@ -13,6 +13,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -1068,16 +1069,31 @@ func (a Metrics) MostlyEquals(b Metrics) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (x *Xip) downloadBlockList(blocklistURL string) string {
|
func (x *Xip) downloadBlockList(blocklistURL string) string {
|
||||||
resp, err := http.Get(blocklistURL)
|
var err error
|
||||||
if err != nil {
|
var blocklistReader io.ReadCloser
|
||||||
return fmt.Sprintf(`failed to download blocklist "%s": %s`, blocklistURL, err.Error())
|
// file protocol's purpose is so I can run tests while flyiing with no internet
|
||||||
|
fileProtocolRE := regexp.MustCompile(`^file://`)
|
||||||
|
if fileProtocolRE.MatchString(blocklistURL) {
|
||||||
|
blocklistPath := strings.TrimPrefix(blocklistURL, "file://")
|
||||||
|
blocklistReader, err = os.Open(blocklistPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Sprintf(`failed to open blocklist "%s": %s`, blocklistPath, err.Error())
|
||||||
|
}
|
||||||
|
//noinspection GoUnhandledErrorResult
|
||||||
|
defer blocklistReader.Close()
|
||||||
|
} else {
|
||||||
|
resp, err := http.Get(blocklistURL)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Sprintf(`failed to download blocklist "%s": %s`, blocklistURL, err.Error())
|
||||||
|
}
|
||||||
|
blocklistReader = resp.Body
|
||||||
|
//noinspection GoUnhandledErrorResult
|
||||||
|
defer blocklistReader.Close()
|
||||||
|
if resp.StatusCode > 299 {
|
||||||
|
return fmt.Sprintf(`failed to download blocklist "%s", HTTP status: "%d"`, blocklistURL, resp.StatusCode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//noinspection GoUnhandledErrorResult
|
blocklistStrings, blocklistCIDRs, err := ReadBlocklist(blocklistReader)
|
||||||
defer resp.Body.Close()
|
|
||||||
if resp.StatusCode > 299 {
|
|
||||||
return fmt.Sprintf(`failed to download blocklist "%s", HTTP status: "%d"`, blocklistURL, resp.StatusCode)
|
|
||||||
}
|
|
||||||
blocklistStrings, blocklistCIDRs, err := ReadBlocklist(resp.Body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Sprintf(`failed to parse blocklist "%s": %s`, blocklistURL, err.Error())
|
return fmt.Sprintf(`failed to parse blocklist "%s": %s`, blocklistURL, err.Error())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user