summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-08-14 21:28:20 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-08-14 21:28:20 +0200
commitbf5d6aaec3da5cf06cdb33792a34ff155f01ef78 (patch)
tree6e921ab14f1231455b32c7de7fd5f118a1077524 /web
parent9b62eec13fb391a3055253422cc58252db820d99 (diff)
refactor: centralize test database setup
Diffstat (limited to 'web')
-rw-r--r--web/server_test.go52
1 files changed, 2 insertions, 50 deletions
diff --git a/web/server_test.go b/web/server_test.go
index e8c3012..9ecda80 100644
--- a/web/server_test.go
+++ b/web/server_test.go
@@ -16,67 +16,19 @@ import (
"github.com/jftuga/geodist"
"github.com/martinlehoux/biking_home/config"
+ "github.com/martinlehoux/biking_home/internal/dbtest"
"github.com/martinlehoux/biking_home/mountain_pass"
"github.com/martinlehoux/biking_home/official_climb"
"github.com/martinlehoux/biking_home/ride"
"github.com/martinlehoux/biking_home/rides"
"github.com/martinlehoux/biking_home/strava"
- _ "github.com/mattn/go-sqlite3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func newWebTestServer(t *testing.T) (*Server, *sql.DB) {
t.Helper()
- db, err := sql.Open("sqlite3", ":memory:")
- require.NoError(t, err)
- t.Cleanup(func() { db.Close() })
- _, err = db.Exec(`
- create table rides (
- id integer primary key,
- external_id text unique not null,
- gpx_path text not null,
- name text not null,
- type text not null,
- start_date text not null,
- distance_m real not null,
- moving_time_s integer not null,
- elapsed_time_s integer not null,
- total_elevation_gain_m real not null,
- average_speed_mps real not null,
- cotacol_score real,
- cotacol_algo_version text,
- created_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
- updated_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
- )
- `)
- require.NoError(t, err)
- _, err = db.Exec(`
- create table mountain_passes (
- id integer primary key,
- external_id text unique not null,
- name text not null,
- country_code text not null,
- department_code text not null,
- elevation integer not null,
- latitude real,
- longitude real
- )
- `)
- require.NoError(t, err)
- _, err = db.Exec(`
- create table official_climbs (
- id integer primary key,
- name text not null,
- start_latitude real not null,
- start_longitude real not null,
- end_latitude real not null,
- end_longitude real not null,
- created_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
- updated_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
- )
- `)
- require.NoError(t, err)
+ db := dbtest.New(t)
configPath := filepath.Join(t.TempDir(), "config.yaml")
appConfig := config.Default()
appConfig.Strava.ClientID = "123"