Tests passing when being run offline, still not integrated with the new API endpoints yet

This commit is contained in:
David Dworken 2022-04-28 11:26:55 -07:00
parent 8a018b71b8
commit 46d7e9e013
4 changed files with 22 additions and 4 deletions

View File

@ -85,7 +85,7 @@ func apiSubmitHandler(w http.ResponseWriter, r *http.Request) {
} }
} }
func apiEBootstrapHandler(w http.ResponseWriter, r *http.Request) { func apiBootstrapHandler(w http.ResponseWriter, r *http.Request) {
userId := r.URL.Query().Get("user_id") userId := r.URL.Query().Get("user_id")
deviceId := r.URL.Query().Get("device_id") deviceId := r.URL.Query().Get("device_id")
updateUsageData(userId, deviceId) updateUsageData(userId, deviceId)
@ -442,6 +442,7 @@ func main() {
http.Handle("/api/v1/get-dump-requests", withLogging(apiGetPendingDumpRequestsHandler)) http.Handle("/api/v1/get-dump-requests", withLogging(apiGetPendingDumpRequestsHandler))
http.Handle("/api/v1/submit-dump", withLogging(apiSubmitDumpHandler)) http.Handle("/api/v1/submit-dump", withLogging(apiSubmitDumpHandler))
http.Handle("/api/v1/query", withLogging(apiQueryHandler)) http.Handle("/api/v1/query", withLogging(apiQueryHandler))
http.Handle("/api/v1/bootstrap", withLogging(apiBootstrapHandler))
http.Handle("/api/v1/register", withLogging(apiRegisterHandler)) http.Handle("/api/v1/register", withLogging(apiRegisterHandler))
http.Handle("/api/v1/banner", withLogging(apiBannerHandler)) http.Handle("/api/v1/banner", withLogging(apiBannerHandler))
http.Handle("/api/v1/download", withLogging(apiDownloadHandler)) http.Handle("/api/v1/download", withLogging(apiDownloadHandler))

View File

@ -101,7 +101,7 @@ func TestESubmitThenQuery(t *testing.T) {
// Bootstrap handler should return 2 entries, one for each device // Bootstrap handler should return 2 entries, one for each device
w = httptest.NewRecorder() w = httptest.NewRecorder()
searchReq = httptest.NewRequest(http.MethodGet, "/?user_id="+data.UserId("key")+"&device_id="+devId1, nil) searchReq = httptest.NewRequest(http.MethodGet, "/?user_id="+data.UserId("key")+"&device_id="+devId1, nil)
apiEBootstrapHandler(w, searchReq) apiBootstrapHandler(w, searchReq)
res = w.Result() res = w.Result()
defer res.Body.Close() defer res.Body.Close()
respBody, err = ioutil.ReadAll(res.Body) respBody, err = ioutil.ReadAll(res.Body)
@ -264,6 +264,10 @@ func TestDumpRequestAndResponse(t *testing.T) {
} }
func TestUpdateReleaseVersion(t *testing.T) { func TestUpdateReleaseVersion(t *testing.T) {
if !shared.IsOnline() {
t.Skip("skipping because we're currently offline")
}
// Set up // Set up
defer shared.BackupAndRestore(t)() defer shared.BackupAndRestore(t)()
InitDB() InitDB()

View File

@ -514,6 +514,9 @@ hishtory disable`)
} }
func testUpdate(t *testing.T, tester shellTester) { func testUpdate(t *testing.T, tester shellTester) {
if !shared.IsOnline() {
t.Skip("skipping because we're currently offline")
}
if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" { if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" {
t.Skip("skipping on linux/arm64 which is unsupported") t.Skip("skipping on linux/arm64 which is unsupported")
} }
@ -731,7 +734,7 @@ func manuallySubmitHistoryEntry(t *testing.T, userSecret string, entry data.Hist
shared.Check(t, err) shared.Check(t, err)
jsonValue, err := json.Marshal([]shared.EncHistoryEntry{encEntry}) jsonValue, err := json.Marshal([]shared.EncHistoryEntry{encEntry})
shared.Check(t, err) shared.Check(t, err)
resp, err := http.Post("http://localhost:8080/api/v1/esubmit", "application/json", bytes.NewBuffer(jsonValue)) resp, err := http.Post("http://localhost:8080/api/v1/submit", "application/json", bytes.NewBuffer(jsonValue))
shared.Check(t, err) shared.Check(t, err)
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
t.Fatalf("failed to submit result to backend, status_code=%d", resp.StatusCode) t.Fatalf("failed to submit result to backend, status_code=%d", resp.StatusCode)
@ -792,6 +795,10 @@ echo other`)
} }
func testHishtoryBackgroundSaving(t *testing.T, tester shellTester) { func testHishtoryBackgroundSaving(t *testing.T, tester shellTester) {
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
t.Skip("skip testing background saving since it is too flakey on M1")
}
// Setup // Setup
defer shared.BackupAndRestore(t)() defer shared.BackupAndRestore(t)()

View File

@ -3,6 +3,7 @@ package shared
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"net/http"
"os" "os"
"os/exec" "os/exec"
"path" "path"
@ -103,7 +104,7 @@ func RunTestServer() func() {
if err != nil && err.Error() != "os: process already finished" { if err != nil && err.Error() != "os: process already finished" {
panic(fmt.Sprintf("failed to kill server process: %v", err)) panic(fmt.Sprintf("failed to kill server process: %v", err))
} }
if strings.Contains(stderr.String()+stdout.String(), "failed to") { if strings.Contains(stderr.String()+stdout.String(), "failed to") && IsOnline() {
panic(fmt.Sprintf("server failed to do something: stderr=%#v, stdout=%#v", stderr.String(), stdout.String())) panic(fmt.Sprintf("server failed to do something: stderr=%#v, stdout=%#v", stderr.String(), stdout.String()))
} }
if strings.Contains(stderr.String()+stdout.String(), "ERROR:") { if strings.Contains(stderr.String()+stdout.String(), "ERROR:") {
@ -126,3 +127,8 @@ func CheckWithInfo(t *testing.T, err error, additionalInfo string) {
t.Fatalf("Unexpected error: %v at %s:%d! Additional info: %v", err, filename, line, additionalInfo) t.Fatalf("Unexpected error: %v at %s:%d! Additional info: %v", err, filename, line, additionalInfo)
} }
} }
func IsOnline() bool {
_, err := http.Get("https://hishtory.dev")
return err == nil
}