diff --git a/integration/hsic/hsic.go b/integration/hsic/hsic.go index 64aaebb7ec6..5019895a3c1 100644 --- a/integration/hsic/hsic.go +++ b/integration/hsic/hsic.go @@ -348,6 +348,14 @@ func (t *HeadscaleInContainer) Shutdown() error { ) } + err = t.SaveDatabase("/tmp/control") + if err != nil { + log.Printf( + "Failed to save database from control: %s", + fmt.Errorf("failed to save database from control: %w", err), + ) + } + return t.pool.Purge(t.container) } @@ -393,6 +401,24 @@ func (t *HeadscaleInContainer) SaveMapResponses(savePath string) error { return nil } +func (t *HeadscaleInContainer) SaveDatabase(savePath string) error { + tarFile, err := t.FetchPath("/tmp/integration_test_db.sqlite3") + if err != nil { + return err + } + + err = os.WriteFile( + path.Join(savePath, t.hostname+".db.tar"), + tarFile, + os.ModePerm, + ) + if err != nil { + return err + } + + return nil +} + // Execute runs a command inside the Headscale container and returns the // result of stdout as a string. func (t *HeadscaleInContainer) Execute(