273b70bacc
## Checklist - [x] I have read the [contribution guidelines](https://github.com/ooni/probe-cli/blob/master/CONTRIBUTING.md) - [x] reference issue for this pull request: https://github.com/ooni/probe/issues/1885 - [x] related ooni/spec pull request: N/A Location of the issue tracker: https://github.com/ooni/probe ## Description This PR contains a set of changes to move important interfaces and data types into the `./internal/model` package. The criteria for including an interface or data type in here is roughly that the type should be important and used by several packages. We are especially interested to move more interfaces here to increase modularity. An additional side effect is that, by reading this package, one should be able to understand more quickly how different parts of the codebase interact with each other. This is what I want to move in `internal/model`: - [x] most important interfaces from `internal/netxlite` - [x] everything that was previously part of `internal/engine/model` - [x] mocks from `internal/netxlite/mocks` should also be moved in here as a subpackage
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package nettests
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/apex/log"
|
|
engine "github.com/ooni/probe-cli/v3/internal/engine"
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
|
)
|
|
|
|
func (n WebConnectivity) lookupURLs(ctl *Controller, categories []string) ([]string, error) {
|
|
inputloader := &engine.InputLoader{
|
|
CheckInConfig: &model.OOAPICheckInConfig{
|
|
// Setting Charging and OnWiFi to true causes the CheckIn
|
|
// API to return to us as much URL as possible with the
|
|
// given RunType hint.
|
|
Charging: true,
|
|
OnWiFi: true,
|
|
RunType: ctl.RunType,
|
|
WebConnectivity: model.OOAPICheckInConfigWebConnectivity{
|
|
CategoryCodes: categories,
|
|
},
|
|
},
|
|
ExperimentName: "web_connectivity",
|
|
InputPolicy: engine.InputOrQueryBackend,
|
|
Session: ctl.Session,
|
|
SourceFiles: ctl.InputFiles,
|
|
StaticInputs: ctl.Inputs,
|
|
}
|
|
testlist, err := inputloader.Load(context.Background())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ctl.BuildAndSetInputIdxMap(ctl.Probe.DB(), testlist)
|
|
}
|
|
|
|
// WebConnectivity test implementation
|
|
type WebConnectivity struct{}
|
|
|
|
// Run starts the test
|
|
func (n WebConnectivity) Run(ctl *Controller) error {
|
|
log.Debugf("Enabled category codes are the following %v", ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes)
|
|
urls, err := n.lookupURLs(ctl, ctl.Probe.Config().Nettests.WebsitesEnabledCategoryCodes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
builder, err := ctl.Session.NewExperimentBuilder("web_connectivity")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctl.Run(builder, urls)
|
|
}
|