-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add end-to-end testing to this repository (#220)
* feat: add end-to-end testing to this repository Part of ooni/probe-engine#1181 Motivation: we want to run this check from the repository where we work the most, such that it's unlikely it pauses due to inactivity, as it may happen for less frequently touched upon repositories. Code adapted from https://github.com/ooni/e2etesting/ * fix: correct name for main branch
- Loading branch information
1 parent
26d807c
commit f53b3be
Showing
5 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Run end-to-end testing using miniooni | ||
name: "e2eminiooni" | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
schedule: | ||
- cron: "25 */8 * * *" | ||
jobs: | ||
test: | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- uses: actions/setup-go@v1 | ||
with: | ||
go-version: "1.14" | ||
- uses: actions/checkout@v2 | ||
- run: ./E2E/miniooni.bash |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/*.jsonl |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# github.com/ooni/probe-cli/E2E | ||
|
||
This directory is used to run end-to-end tests where we run specific | ||
measurements, we fetch them back from the API, and check them. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
set -e | ||
go build -v ./internal/cmd/miniooni | ||
probeservices=() | ||
probeservices+=( "https://ps1.ooni.io" ) | ||
probeservices+=( "https://dvp6h0xblpcqp.cloudfront.net" ) | ||
probeservices+=( "https://ams-pg-test.ooni.org" ) | ||
for ps in ${probeservices[@]}; do | ||
opt="-o E2E/o.jsonl --probe-services=$ps" | ||
set -x | ||
./miniooni --yes $opt -i http://mail.google.com web_connectivity | ||
./miniooni --yes $opt tor | ||
./miniooni --yes $opt psiphon | ||
set +x | ||
done | ||
set -x | ||
go run ./internal/cmd/e2epostprocess -expected 9 | ||
set +x |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"flag" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func fatalOnError(err error) { | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
// Measurement contains a OONI measurement. | ||
type Measurement struct { | ||
ReportID string `json:"report_id"` | ||
Input *string `json:"input"` | ||
SoftwareName string `json:"software_name"` | ||
SoftwareVersion string `json:"software_version"` | ||
} | ||
|
||
func main() { | ||
expected := flag.Int("expected", 0, "Expected number of measurement files") | ||
flag.Parse() | ||
if *expected <= 0 { | ||
log.Fatal("You MUST specify `-expected N`") | ||
} | ||
// based off https://flaviocopes.com/go-list-files/ | ||
var files []string | ||
outputdir := "./E2E/" | ||
err := filepath.Walk(outputdir, func(path string, info os.FileInfo, err error) error { | ||
if strings.HasSuffix(path, ".jsonl") { | ||
files = append(files, path) | ||
} | ||
return nil | ||
}) | ||
fatalOnError(err) | ||
if len(files) <= 0 { | ||
log.Fatal("no files to process?!") | ||
} | ||
var found int | ||
for _, file := range files { | ||
data, err := ioutil.ReadFile(file) | ||
fatalOnError(err) | ||
measurements := bytes.Split(data, []byte("\n")) | ||
for _, measurement := range measurements { | ||
if len(measurement) <= 0 { | ||
continue | ||
} | ||
var entry Measurement | ||
err = json.Unmarshal(measurement, &entry) | ||
fatalOnError(err) | ||
log.Printf("processing: %+v", entry) | ||
options := []string{ | ||
"run", | ||
"./internal/cmd/apitool", | ||
"-mode", "meta", | ||
"-report-id", entry.ReportID, | ||
} | ||
found++ | ||
if entry.Input != nil { | ||
options = append(options, "-input") | ||
options = append(options, *entry.Input) | ||
} | ||
log.Printf("run: go %s", strings.Join(options, " ")) | ||
cmd := exec.Command("go", options...) | ||
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr | ||
err = cmd.Run() | ||
fatalOnError(err) | ||
} | ||
} | ||
if found != *expected { | ||
log.Fatalf("expected %d measurements, found %d measurements", *expected, found) | ||
} | ||
} |