Skip to content

Commit

Permalink
feat: add end-to-end testing to this repository (#220)
Browse files Browse the repository at this point in the history
* 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
bassosimone authored Feb 4, 2021
1 parent 26d807c commit f53b3be
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/e2eminiooni.yml
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
1 change: 1 addition & 0 deletions E2E/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*.jsonl
4 changes: 4 additions & 0 deletions E2E/README.md
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.
18 changes: 18 additions & 0 deletions E2E/miniooni.bash
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
82 changes: 82 additions & 0 deletions internal/cmd/e2epostprocess/main.go
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)
}
}

0 comments on commit f53b3be

Please sign in to comment.