From b2e2f49474d9cda6e196af52a899521d2c980b9f Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Tue, 27 Aug 2024 16:22:39 +0200 Subject: [PATCH] fix tests Signed-off-by: Kristoffer Dalby --- hscontrol/db/db.go | 8 ++++--- hscontrol/db/db_test.go | 48 ++++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/hscontrol/db/db.go b/hscontrol/db/db.go index 94265c18bdf..3aaa7eebe8a 100644 --- a/hscontrol/db/db.go +++ b/hscontrol/db/db.go @@ -133,9 +133,11 @@ func NewHeadscaleDatabase( return err } } - err = tx.AutoMigrate(&types.Route{}) - if err != nil { - return err + if !tx.Migrator().HasTable(&types.Route{}) { + err = tx.AutoMigrate(&types.Route{}) + if err != nil { + return err + } } err = tx.AutoMigrate(&types.Node{}) diff --git a/hscontrol/db/db_test.go b/hscontrol/db/db_test.go index 39610092df1..b32d93cec90 100644 --- a/hscontrol/db/db_test.go +++ b/hscontrol/db/db_test.go @@ -69,29 +69,33 @@ func TestMigrations(t *testing.T) { }) assert.NoError(t, err) - assert.Len(t, routes, 25) + assert.Len(t, routes, 4) want := types.Routes{ - r(1, "0.0.0.0/0", true, true, false), - r(1, "::/0", true, true, false), - r(3, "0.0.0.0/0", true, true, false), - r(3, "::/0", true, true, false), - r(5, "0.0.0.0/0", true, true, false), - r(5, "::/0", true, true, false), - r(6, "0.0.0.0/0", true, true, false), - r(6, "::/0", true, true, false), - r(6, "10.0.0.0/8", true, false, false), - r(7, "0.0.0.0/0", true, true, false), - r(7, "::/0", true, true, false), - r(7, "10.0.0.0/8", true, false, false), - r(9, "0.0.0.0/0", true, true, false), - r(9, "::/0", true, true, false), - r(9, "10.0.0.0/8", true, true, false), - r(11, "0.0.0.0/0", true, true, false), - r(11, "::/0", true, true, false), - r(11, "10.0.0.0/8", true, true, true), - r(12, "0.0.0.0/0", true, true, false), - r(12, "::/0", true, true, false), - r(12, "10.0.0.0/8", true, false, false), + // These routes exists, but have no nodes associated with them + // when the migration starts. + // r(1, "0.0.0.0/0", true, true, false), + // r(1, "::/0", true, true, false), + // r(3, "0.0.0.0/0", true, true, false), + // r(3, "::/0", true, true, false), + // r(5, "0.0.0.0/0", true, true, false), + // r(5, "::/0", true, true, false), + // r(6, "0.0.0.0/0", true, true, false), + // r(6, "::/0", true, true, false), + // r(6, "10.0.0.0/8", true, false, false), + // r(7, "0.0.0.0/0", true, true, false), + // r(7, "::/0", true, true, false), + // r(7, "10.0.0.0/8", true, false, false), + // r(9, "0.0.0.0/0", true, true, false), + // r(9, "::/0", true, true, false), + // r(9, "10.0.0.0/8", true, true, false), + // r(11, "0.0.0.0/0", true, true, false), + // r(11, "::/0", true, true, false), + // r(11, "10.0.0.0/8", true, true, true), + // r(12, "0.0.0.0/0", true, true, false), + // r(12, "::/0", true, true, false), + // r(12, "10.0.0.0/8", true, false, false), + // + // These nodes exists, so routes should be kept. r(13, "10.0.0.0/8", true, false, false), r(13, "0.0.0.0/0", true, true, false), r(13, "::/0", true, true, false),