Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Aug 27, 2024
1 parent bb38e10 commit b2e2f49
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
8 changes: 5 additions & 3 deletions hscontrol/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
48 changes: 26 additions & 22 deletions hscontrol/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit b2e2f49

Please sign in to comment.