feat: start sketching out the oonirun package (#842)
This diff refactors the ./internal/cmd/miniooni pkg and moves the code for running experiments inside of the ./internal/oonirun pkg. It's the first concrete step towards https://github.com/ooni/probe/issues/2184.
This commit is contained in:
parent
e5697e641e
commit
0b4a49190a
6 changed files with 377 additions and 134 deletions
60
internal/oonirun/experiment_test.go
Normal file
60
internal/oonirun/experiment_test.go
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package oonirun
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine"
|
||||
"github.com/ooni/probe-cli/v3/internal/kvstore"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/version"
|
||||
)
|
||||
|
||||
// TODO(bassosimone): it would be cool to write unit tests. However, to do that
|
||||
// we need to ~redesign the engine package for unit-testability.
|
||||
|
||||
func newSession(ctx context.Context, t *testing.T) *engine.Session {
|
||||
config := engine.SessionConfig{
|
||||
AvailableProbeServices: []model.OOAPIService{},
|
||||
KVStore: &kvstore.Memory{},
|
||||
Logger: model.DiscardLogger,
|
||||
ProxyURL: nil,
|
||||
SoftwareName: "miniooni",
|
||||
SoftwareVersion: version.Version,
|
||||
TempDir: os.TempDir(),
|
||||
TorArgs: []string{},
|
||||
TorBinary: "",
|
||||
TunnelDir: "",
|
||||
}
|
||||
sess, err := engine.NewSession(ctx, config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return sess
|
||||
}
|
||||
|
||||
func TestExperimentRunWithExample(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
desc := &Experiment{
|
||||
Annotations: map[string]string{
|
||||
"platform": "linux",
|
||||
},
|
||||
ExtraOptions: map[string]any{
|
||||
"SleepTime": int64(10 * time.Millisecond),
|
||||
},
|
||||
Inputs: []string{},
|
||||
InputFilePaths: []string{},
|
||||
MaxRuntime: 0,
|
||||
Name: "example",
|
||||
NoCollector: true,
|
||||
NoJSON: true,
|
||||
Random: false,
|
||||
ReportFile: "",
|
||||
Session: newSession(ctx, t),
|
||||
}
|
||||
if err := desc.Run(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue