Skip to content

Commit

Permalink
Prevent tests to go online
Browse files Browse the repository at this point in the history
Signed-off-by: Jo Vandeginste <[email protected]>
  • Loading branch information
jovandeginste committed Feb 28, 2024
1 parent cbaac14 commit 3993105
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pkg/database/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"gorm.io/gorm"
)

func init() { //nolint:gochecknoinits
online = false
}

func defaultUser() *User {
return &User{
Username: "my-username",
Expand Down Expand Up @@ -260,9 +264,10 @@ func TestDatabaseProfileSave(t *testing.T) {
}

func TestDatabaseUserWorkouts(t *testing.T) {
db := createMemoryDB(t)
populateGPXFS()

db := createMemoryDB(t)

u := defaultUser()
require.NoError(t, u.Create(db))

Expand Down
6 changes: 6 additions & 0 deletions pkg/database/workouts_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/tkrajina/gpxgo/gpx"
)

var online = true

// parseGPX parses a GPX file, returns GPX.
func parseGPX(gpxBytes []byte) (*gpx.GPX, error) {
gpxContent, err := gpx.ParseBytes(gpxBytes)
Expand Down Expand Up @@ -79,6 +81,10 @@ func center(gpxContent *gpx.GPX) MapCenter {
}

func (m *MapCenter) Address() *geo.Address {
if !online {
return nil
}

geocoder := openstreetmap.Geocoder()

address, err := geocoder.ReverseGeocode(m.Lat, m.Lng)
Expand Down
7 changes: 5 additions & 2 deletions pkg/database/workouts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/stretchr/testify/require"
)

func init() { //nolint:gochecknoinits
online = false
}

func defaultWorkout(t *testing.T) *Workout {
u := defaultUser()
f1, err := gpxFS.ReadFile("sample1.gpx")
Expand Down Expand Up @@ -53,8 +57,7 @@ func TestWorkout_Parse(t *testing.T) {
assert.InDelta(t, 3.297, w.Data.AverageSpeed(), 0.01)
assert.InDelta(t, 3.297, w.Data.AverageSpeedNoPause(), 0.01)
assert.Equal(t, "Untitled", w.Name)
assert.Equal(t, "US", w.Data.Address.CountryCode)
assert.Equal(t, "Washington", w.Data.Address.City)
assert.Nil(t, w.Data.Address)
}

func TestWorkout_UpdateData(t *testing.T) {
Expand Down

0 comments on commit 3993105

Please sign in to comment.