d57c78bc71
This is how I did it: 1. `git clone https://github.com/ooni/probe-engine internal/engine` 2. ``` (cd internal/engine && git describe --tags) v0.23.0 ``` 3. `nvim go.mod` (merging `go.mod` with `internal/engine/go.mod` 4. `rm -rf internal/.git internal/engine/go.{mod,sum}` 5. `git add internal/engine` 6. `find . -type f -name \*.go -exec sed -i 's@/ooni/probe-engine@/ooni/probe-cli/v3/internal/engine@g' {} \;` 7. `go build ./...` (passes) 8. `go test -race ./...` (temporary failure on RiseupVPN) 9. `go mod tidy` 10. this commit message Once this piece of work is done, we can build a new version of `ooniprobe` that is using `internal/engine` directly. We need to do more work to ensure all the other functionality in `probe-engine` (e.g. making mobile packages) are still WAI. Part of https://github.com/ooni/probe/issues/1335
111 lines
2.6 KiB
Go
111 lines
2.6 KiB
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"os"
|
|
"syscall"
|
|
"testing"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/internal/fsx"
|
|
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
|
)
|
|
|
|
type InputLoaderBrokenFS struct{}
|
|
|
|
func (InputLoaderBrokenFS) Open(filepath string) (fsx.File, error) {
|
|
return InputLoaderBrokenFile{}, nil
|
|
}
|
|
|
|
type InputLoaderBrokenFile struct{}
|
|
|
|
func (InputLoaderBrokenFile) Stat() (os.FileInfo, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (InputLoaderBrokenFile) Read([]byte) (int, error) {
|
|
return 0, syscall.EFAULT
|
|
}
|
|
|
|
func (InputLoaderBrokenFile) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func TestInputLoaderReadfileScannerFailure(t *testing.T) {
|
|
il := inputLoader{}
|
|
out, err := il.readfile("", InputLoaderBrokenFS{}.Open)
|
|
if !errors.Is(err, syscall.EFAULT) {
|
|
t.Fatal("not the error we expected")
|
|
}
|
|
if out != nil {
|
|
t.Fatal("not the output we expected")
|
|
}
|
|
}
|
|
|
|
type InputLoaderBrokenSession struct {
|
|
OrchestraClient model.ExperimentOrchestraClient
|
|
Error error
|
|
}
|
|
|
|
func (InputLoaderBrokenSession) MaybeLookupLocationContext(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (ilbs InputLoaderBrokenSession) NewOrchestraClient(ctx context.Context) (model.ExperimentOrchestraClient, error) {
|
|
if ilbs.OrchestraClient != nil {
|
|
return ilbs.OrchestraClient, nil
|
|
}
|
|
return nil, io.EOF
|
|
}
|
|
|
|
func (InputLoaderBrokenSession) ProbeCC() string {
|
|
return "IT"
|
|
}
|
|
|
|
func TestInputLoaderNewOrchestraClientFailure(t *testing.T) {
|
|
il := inputLoader{}
|
|
lrc := loadRemoteConfig{
|
|
ctx: context.Background(),
|
|
session: InputLoaderBrokenSession{},
|
|
}
|
|
out, err := il.loadRemote(lrc)
|
|
if !errors.Is(err, io.EOF) {
|
|
t.Fatalf("not the error we expected: %+v", err)
|
|
}
|
|
if out != nil {
|
|
t.Fatal("expected nil output here")
|
|
}
|
|
}
|
|
|
|
type InputLoaderBrokenOrchestraClient struct{}
|
|
|
|
func (InputLoaderBrokenOrchestraClient) FetchPsiphonConfig(ctx context.Context) ([]byte, error) {
|
|
return nil, io.EOF
|
|
}
|
|
|
|
func (InputLoaderBrokenOrchestraClient) FetchTorTargets(ctx context.Context, cc string) (map[string]model.TorTarget, error) {
|
|
return nil, io.EOF
|
|
}
|
|
|
|
func (InputLoaderBrokenOrchestraClient) FetchURLList(ctx context.Context, config model.URLListConfig) ([]model.URLInfo, error) {
|
|
return nil, io.EOF
|
|
}
|
|
|
|
func TestInputLoaderFetchURLListFailure(t *testing.T) {
|
|
il := inputLoader{}
|
|
lrc := loadRemoteConfig{
|
|
ctx: context.Background(),
|
|
session: InputLoaderBrokenSession{
|
|
OrchestraClient: InputLoaderBrokenOrchestraClient{},
|
|
},
|
|
}
|
|
out, err := il.loadRemote(lrc)
|
|
if !errors.Is(err, io.EOF) {
|
|
t.Fatalf("not the error we expected: %+v", err)
|
|
}
|
|
if out != nil {
|
|
t.Fatal("expected nil output here")
|
|
}
|
|
}
|