refactor: interfaces and data types into the model package (#642)

## 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
This commit is contained in:
Simone Basso 2022-01-03 13:53:23 +01:00 committed by GitHub
commit 273b70bacc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
275 changed files with 1281 additions and 1375 deletions

View file

@ -11,7 +11,8 @@ import (
"github.com/apex/log"
"github.com/google/go-cmp/cmp"
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/model/mocks"
)
func TestNewResolverSystem(t *testing.T) {
@ -246,14 +247,14 @@ func TestResolverLogger(t *testing.T) {
count++
},
}
expected := &HTTPSSvc{
expected := &model.HTTPSSvc{
ALPN: []string{"h3"},
IPv4: []string{"1.1.1.1"},
}
r := &resolverLogger{
Logger: lo,
Resolver: &mocks.Resolver{
MockLookupHTTPS: func(ctx context.Context, domain string) (*HTTPSSvc, error) {
MockLookupHTTPS: func(ctx context.Context, domain string) (*model.HTTPSSvc, error) {
return expected, nil
},
MockNetwork: func() string {
@ -287,7 +288,7 @@ func TestResolverLogger(t *testing.T) {
r := &resolverLogger{
Logger: lo,
Resolver: &mocks.Resolver{
MockLookupHTTPS: func(ctx context.Context, domain string) (*HTTPSSvc, error) {
MockLookupHTTPS: func(ctx context.Context, domain string) (*model.HTTPSSvc, error) {
return nil, expected
},
MockNetwork: func() string {
@ -357,14 +358,14 @@ func TestResolverIDNA(t *testing.T) {
t.Run("LookupHTTPS", func(t *testing.T) {
t.Run("with valid IDNA in input", func(t *testing.T) {
expected := &HTTPSSvc{
expected := &model.HTTPSSvc{
ALPN: []string{"h3"},
IPv4: []string{"1.1.1.1"},
IPv6: []string{},
}
r := &resolverIDNA{
Resolver: &mocks.Resolver{
MockLookupHTTPS: func(ctx context.Context, domain string) (*HTTPSSvc, error) {
MockLookupHTTPS: func(ctx context.Context, domain string) (*model.HTTPSSvc, error) {
if domain != "xn--d1acpjx3f.xn--p1ai" {
return nil, errors.New("passed invalid domain")
}
@ -384,7 +385,7 @@ func TestResolverIDNA(t *testing.T) {
t.Run("with invalid punycode", func(t *testing.T) {
r := &resolverIDNA{Resolver: &mocks.Resolver{
MockLookupHTTPS: func(ctx context.Context, domain string) (*HTTPSSvc, error) {
MockLookupHTTPS: func(ctx context.Context, domain string) (*model.HTTPSSvc, error) {
return nil, errors.New("should not happen")
},
}}
@ -567,12 +568,12 @@ func TestResolverErrWrapper(t *testing.T) {
t.Run("LookupHTTPS", func(t *testing.T) {
t.Run("on success", func(t *testing.T) {
expected := &HTTPSSvc{
expected := &model.HTTPSSvc{
ALPN: []string{"h3"},
}
reso := &resolverErrWrapper{
Resolver: &mocks.Resolver{
MockLookupHTTPS: func(ctx context.Context, domain string) (*HTTPSSvc, error) {
MockLookupHTTPS: func(ctx context.Context, domain string) (*model.HTTPSSvc, error) {
return expected, nil
},
},
@ -591,7 +592,7 @@ func TestResolverErrWrapper(t *testing.T) {
expected := io.EOF
reso := &resolverErrWrapper{
Resolver: &mocks.Resolver{
MockLookupHTTPS: func(ctx context.Context, domain string) (*HTTPSSvc, error) {
MockLookupHTTPS: func(ctx context.Context, domain string) (*model.HTTPSSvc, error) {
return nil, expected
},
},