feat: add end-to-end testing to this repository (#220)
* feat: add end-to-end testing to this repository Part of https://github.com/ooni/probe-engine/issues/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
This commit is contained in:
parent
26d807c50f
commit
f53b3be66e
18
.github/workflows/e2eminiooni.yml
vendored
Normal file
18
.github/workflows/e2eminiooni.yml
vendored
Normal file
|
@ -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
|
1
E2E/.gitignore
vendored
Normal file
1
E2E/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/*.jsonl
|
4
E2E/README.md
Normal file
4
E2E/README.md
Normal file
|
@ -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.
|
18
E2E/miniooni.bash
Executable file
18
E2E/miniooni.bash
Executable file
|
@ -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
|
82
internal/cmd/e2epostprocess/main.go
Normal file
82
internal/cmd/e2epostprocess/main.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user