diff --git a/internal/engine/experiment_test.go b/internal/engine/experiment_test.go index 84298039fb..e8f5112d3b 100644 --- a/internal/engine/experiment_test.go +++ b/internal/engine/experiment_test.go @@ -3,12 +3,12 @@ package engine import ( "testing" - "github.com/ooni/probe-cli/v3/internal/geolocate" + "github.com/ooni/probe-cli/v3/internal/enginelocate" "github.com/ooni/probe-cli/v3/internal/model" ) func TestExperimentHonoursSharingDefaults(t *testing.T) { - measure := func(info *geolocate.Results) *model.Measurement { + measure := func(info *enginelocate.Results) *model.Measurement { sess := &Session{location: info} builder, err := sess.NewExperimentBuilder("example") if err != nil { @@ -19,48 +19,48 @@ func TestExperimentHonoursSharingDefaults(t *testing.T) { } type spec struct { name string - locationInfo *geolocate.Results + locationInfo *enginelocate.Results expect func(*model.Measurement) bool } allspecs := []spec{{ name: "probeIP", - locationInfo: &geolocate.Results{ProbeIP: "8.8.8.8"}, + locationInfo: &enginelocate.Results{ProbeIP: "8.8.8.8"}, expect: func(m *model.Measurement) bool { return m.ProbeIP == model.DefaultProbeIP }, }, { name: "probeASN", - locationInfo: &geolocate.Results{ASN: 30722}, + locationInfo: &enginelocate.Results{ASN: 30722}, expect: func(m *model.Measurement) bool { return m.ProbeASN == "AS30722" }, }, { name: "probeCC", - locationInfo: &geolocate.Results{CountryCode: "IT"}, + locationInfo: &enginelocate.Results{CountryCode: "IT"}, expect: func(m *model.Measurement) bool { return m.ProbeCC == "IT" }, }, { name: "probeNetworkName", - locationInfo: &geolocate.Results{NetworkName: "Vodafone Italia"}, + locationInfo: &enginelocate.Results{NetworkName: "Vodafone Italia"}, expect: func(m *model.Measurement) bool { return m.ProbeNetworkName == "Vodafone Italia" }, }, { name: "resolverIP", - locationInfo: &geolocate.Results{ResolverIP: "9.9.9.9"}, + locationInfo: &enginelocate.Results{ResolverIP: "9.9.9.9"}, expect: func(m *model.Measurement) bool { return m.ResolverIP == "9.9.9.9" }, }, { name: "resolverASN", - locationInfo: &geolocate.Results{ResolverASN: 44}, + locationInfo: &enginelocate.Results{ResolverASN: 44}, expect: func(m *model.Measurement) bool { return m.ResolverASN == "AS44" }, }, { name: "resolverNetworkName", - locationInfo: &geolocate.Results{ResolverNetworkName: "Google LLC"}, + locationInfo: &enginelocate.Results{ResolverNetworkName: "Google LLC"}, expect: func(m *model.Measurement) bool { return m.ResolverNetworkName == "Google LLC" }, diff --git a/internal/engine/session.go b/internal/engine/session.go index fb988b31b0..423369c5a0 100644 --- a/internal/engine/session.go +++ b/internal/engine/session.go @@ -13,7 +13,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/bytecounter" "github.com/ooni/probe-cli/v3/internal/checkincache" - "github.com/ooni/probe-cli/v3/internal/geolocate" + "github.com/ooni/probe-cli/v3/internal/enginelocate" "github.com/ooni/probe-cli/v3/internal/kvstore" "github.com/ooni/probe-cli/v3/internal/model" "github.com/ooni/probe-cli/v3/internal/netxlite" @@ -60,7 +60,7 @@ type Session struct { byteCounter *bytecounter.Counter httpDefaultTransport model.HTTPTransport kvStore model.KeyValueStore - location *geolocate.Results + location *enginelocate.Results logger model.Logger proxyURL *url.URL queryProbeServicesCount *atomic.Int64 @@ -79,7 +79,7 @@ type Session struct { // testLookupLocationContext is a an optional hook for testing // allowing us to mock LookupLocationContext. - testLookupLocationContext func(ctx context.Context) (*geolocate.Results, error) + testLookupLocationContext func(ctx context.Context) (*enginelocate.Results, error) // testMaybeLookupBackendsContext is an optional hook for testing // allowing us to mock MaybeLookupBackendsContext. @@ -676,8 +676,8 @@ func (s *Session) MaybeLookupBackendsContext(ctx context.Context) error { // LookupLocationContext performs a location lookup. If you want memoisation // of the results, you should use MaybeLookupLocationContext. -func (s *Session) LookupLocationContext(ctx context.Context) (*geolocate.Results, error) { - task := geolocate.NewTask(geolocate.Config{ +func (s *Session) LookupLocationContext(ctx context.Context) (*enginelocate.Results, error) { + task := enginelocate.NewTask(enginelocate.Config{ Logger: s.Logger(), Resolver: s.resolver, UserAgent: s.UserAgent(), @@ -687,7 +687,7 @@ func (s *Session) LookupLocationContext(ctx context.Context) (*geolocate.Results // lookupLocationContext calls testLookupLocationContext if set and // otherwise calls LookupLocationContext. -func (s *Session) lookupLocationContext(ctx context.Context) (*geolocate.Results, error) { +func (s *Session) lookupLocationContext(ctx context.Context) (*enginelocate.Results, error) { if s.testLookupLocationContext != nil { return s.testLookupLocationContext(ctx) } diff --git a/internal/engine/session_internal_test.go b/internal/engine/session_internal_test.go index 6361484f31..454ccd5219 100644 --- a/internal/engine/session_internal_test.go +++ b/internal/engine/session_internal_test.go @@ -11,9 +11,9 @@ import ( "github.com/apex/log" "github.com/google/go-cmp/cmp" "github.com/ooni/probe-cli/v3/internal/checkincache" + "github.com/ooni/probe-cli/v3/internal/enginelocate" "github.com/ooni/probe-cli/v3/internal/experiment/webconnectivity" "github.com/ooni/probe-cli/v3/internal/experiment/webconnectivitylte" - "github.com/ooni/probe-cli/v3/internal/geolocate" "github.com/ooni/probe-cli/v3/internal/kvstore" "github.com/ooni/probe-cli/v3/internal/model" "github.com/ooni/probe-cli/v3/internal/registry" @@ -85,7 +85,7 @@ func TestSessionCheckInSuccessful(t *testing.T) { }, } s := &Session{ - location: &geolocate.Results{ + location: &enginelocate.Results{ ASN: 137, CountryCode: "IT", }, @@ -136,7 +136,7 @@ func TestSessionCheckInNetworkError(t *testing.T) { Error: expect, } s := &Session{ - location: &geolocate.Results{ + location: &enginelocate.Results{ ASN: 137, CountryCode: "IT", }, @@ -178,7 +178,7 @@ func TestSessionCheckInCannotLookupLocation(t *testing.T) { func TestSessionCheckInCannotCreateProbeServicesClient(t *testing.T) { errMocked := errors.New("mocked error") s := &Session{ - location: &geolocate.Results{ + location: &enginelocate.Results{ ASN: 137, CountryCode: "IT", }, @@ -240,7 +240,7 @@ func TestSessionNewSubmitterWithCancelledContext(t *testing.T) { func TestSessionMaybeLookupLocationContextLookupLocationContextFailure(t *testing.T) { errMocked := errors.New("mocked error") sess := newSessionForTestingNoLookups(t) - sess.testLookupLocationContext = func(ctx context.Context) (*geolocate.Results, error) { + sess.testLookupLocationContext = func(ctx context.Context) (*enginelocate.Results, error) { return nil, errMocked } err := sess.MaybeLookupLocationContext(context.Background()) diff --git a/internal/geolocate/cloudflare.go b/internal/enginelocate/cloudflare.go similarity index 97% rename from internal/geolocate/cloudflare.go rename to internal/enginelocate/cloudflare.go index 3de61a538b..17a69112a1 100644 --- a/internal/geolocate/cloudflare.go +++ b/internal/enginelocate/cloudflare.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/internal/geolocate/cloudflare_test.go b/internal/enginelocate/cloudflare_test.go similarity index 96% rename from internal/geolocate/cloudflare_test.go rename to internal/enginelocate/cloudflare_test.go index 4f0b44da41..c3213c5060 100644 --- a/internal/geolocate/cloudflare_test.go +++ b/internal/enginelocate/cloudflare_test.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/internal/geolocate/fake_test.go b/internal/enginelocate/fake_test.go similarity index 96% rename from internal/geolocate/fake_test.go rename to internal/enginelocate/fake_test.go index 5dc683f70b..72933e9ab9 100644 --- a/internal/geolocate/fake_test.go +++ b/internal/enginelocate/fake_test.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "net/http" diff --git a/internal/geolocate/geolocate.go b/internal/enginelocate/geolocate.go similarity index 97% rename from internal/geolocate/geolocate.go rename to internal/enginelocate/geolocate.go index a9c6f5f23d..ce3d282667 100644 --- a/internal/geolocate/geolocate.go +++ b/internal/enginelocate/geolocate.go @@ -1,5 +1,5 @@ -// Package geolocate implements IP lookup, resolver lookup, and geolocation. -package geolocate +// Package enginelocate implements IP lookup, resolver lookup, and geolocation. +package enginelocate import ( "context" diff --git a/internal/geolocate/geolocate_test.go b/internal/enginelocate/geolocate_test.go similarity index 99% rename from internal/geolocate/geolocate_test.go rename to internal/enginelocate/geolocate_test.go index 9d10917531..7a69a68fd1 100644 --- a/internal/geolocate/geolocate_test.go +++ b/internal/enginelocate/geolocate_test.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/internal/geolocate/invalid_test.go b/internal/enginelocate/invalid_test.go similarity index 92% rename from internal/geolocate/invalid_test.go rename to internal/enginelocate/invalid_test.go index bb62404328..a6ac6b7f97 100644 --- a/internal/geolocate/invalid_test.go +++ b/internal/enginelocate/invalid_test.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/internal/geolocate/iplookup.go b/internal/enginelocate/iplookup.go similarity index 99% rename from internal/geolocate/iplookup.go rename to internal/enginelocate/iplookup.go index 3d9711f323..e82adb1415 100644 --- a/internal/geolocate/iplookup.go +++ b/internal/enginelocate/iplookup.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/internal/geolocate/iplookup_test.go b/internal/enginelocate/iplookup_test.go similarity index 98% rename from internal/geolocate/iplookup_test.go rename to internal/enginelocate/iplookup_test.go index 2739a95305..e3c11d6935 100644 --- a/internal/geolocate/iplookup_test.go +++ b/internal/enginelocate/iplookup_test.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/internal/geolocate/mmdblookup.go b/internal/enginelocate/mmdblookup.go similarity index 92% rename from internal/geolocate/mmdblookup.go rename to internal/enginelocate/mmdblookup.go index 14e901f3fa..25af99d9dd 100644 --- a/internal/geolocate/mmdblookup.go +++ b/internal/enginelocate/mmdblookup.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "github.com/ooni/probe-cli/v3/internal/geoipx" diff --git a/internal/geolocate/resolverlookup.go b/internal/enginelocate/resolverlookup.go similarity index 97% rename from internal/geolocate/resolverlookup.go rename to internal/enginelocate/resolverlookup.go index 85da4dee3d..fe93b2a21e 100644 --- a/internal/geolocate/resolverlookup.go +++ b/internal/enginelocate/resolverlookup.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/internal/geolocate/resolverlookup_test.go b/internal/enginelocate/resolverlookup_test.go similarity index 97% rename from internal/geolocate/resolverlookup_test.go rename to internal/enginelocate/resolverlookup_test.go index 8d741e7101..c02110a221 100644 --- a/internal/geolocate/resolverlookup_test.go +++ b/internal/enginelocate/resolverlookup_test.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/internal/geolocate/stun.go b/internal/enginelocate/stun.go similarity index 99% rename from internal/geolocate/stun.go rename to internal/enginelocate/stun.go index d6133a1096..b0600b65e5 100644 --- a/internal/geolocate/stun.go +++ b/internal/enginelocate/stun.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/internal/geolocate/stun_test.go b/internal/enginelocate/stun_test.go similarity index 99% rename from internal/geolocate/stun_test.go rename to internal/enginelocate/stun_test.go index d8c571fc27..5efb96207b 100644 --- a/internal/geolocate/stun_test.go +++ b/internal/enginelocate/stun_test.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/internal/geolocate/ubuntu.go b/internal/enginelocate/ubuntu.go similarity index 97% rename from internal/geolocate/ubuntu.go rename to internal/enginelocate/ubuntu.go index 0f75afb4e0..de59ec9d89 100644 --- a/internal/geolocate/ubuntu.go +++ b/internal/enginelocate/ubuntu.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/internal/geolocate/ubuntu_test.go b/internal/enginelocate/ubuntu_test.go similarity index 98% rename from internal/geolocate/ubuntu_test.go rename to internal/enginelocate/ubuntu_test.go index d6edf7c015..e385b1b0f2 100644 --- a/internal/geolocate/ubuntu_test.go +++ b/internal/enginelocate/ubuntu_test.go @@ -1,4 +1,4 @@ -package geolocate +package enginelocate import ( "context" diff --git a/pkg/oonimkall/session_integration_test.go b/pkg/oonimkall/session_integration_test.go index a86eac412f..ab1bf45b30 100644 --- a/pkg/oonimkall/session_integration_test.go +++ b/pkg/oonimkall/session_integration_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - "github.com/ooni/probe-cli/v3/internal/geolocate" + "github.com/ooni/probe-cli/v3/internal/enginelocate" "github.com/ooni/probe-cli/v3/internal/model" "github.com/ooni/probe-cli/v3/pkg/oonimkall" ) @@ -50,7 +50,7 @@ func ReduceErrorForGeolocate(err error) error { if errors.Is(err, context.Canceled) { return nil // when we have not downloaded the resources yet } - if !errors.Is(err, geolocate.ErrAllIPLookuppersFailed) { + if !errors.Is(err, enginelocate.ErrAllIPLookuppersFailed) { return nil // otherwise } return fmt.Errorf("not the error we expected: %w", err) @@ -295,7 +295,7 @@ func TestCheckInLookupLocationFailure(t *testing.T) { config.WebConnectivity.AddCategory("CULTR") ctx.Cancel() // immediate failure result, err := sess.CheckIn(ctx, &config) - if !errors.Is(err, geolocate.ErrAllIPLookuppersFailed) { + if !errors.Is(err, enginelocate.ErrAllIPLookuppersFailed) { t.Fatalf("not the error we expected: %+v", err) } if result != nil { diff --git a/script/gorenamepkg.bash b/script/gorenamepkg.bash deleted file mode 100755 index 3dc476ed84..0000000000 --- a/script/gorenamepkg.bash +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -set -euo pipefail - -if [[ $# -ne 2 ]]; then - echo "usage: $0 {name-before} {name-after}" 1>&2 - exit 1 -fi -name_before=$1 -shift -name_after=$1 -shift - -basename_before=$(basename $name_before) -basename_after=$(basename $name_after) - -echo "git mv $name_before $name_after" -git mv $name_before $name_after - -for file in $(find $name_after -type f -name \*.go); do - echo "replacing the package name of $file" - cat $file | sed -e "s|^package $basename_before|package $basename_after|g" \ - -e "s|^// Package $basename_before|// Package $basename_after|g" > $file.tmp - cat $file.tmp > $file - rm $file.tmp -done - -pkg_prefix=github.com/ooni/probe-cli/v3 -pkg_before=$pkg_prefix/$name_before -pkg_after=$pkg_prefix/$name_after - -for file in $(find . -type f -name \*.go); do - echo "editing the import path of $file" - cat $file | sed -e "s|\"$pkg_before|\"$pkg_after|g" > $file.tmp - cat $file.tmp > $file - rm $file.tmp -done