Skip to content

Commit

Permalink
Fix bug in test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlewi committed Sep 20, 2024
1 parent 84f5f37 commit acf5f50
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 10 additions & 1 deletion app/pkg/analyze/session_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package analyze
import (
"context"
"database/sql"
"os"
"path/filepath"
"testing"
"time"

Expand Down Expand Up @@ -40,7 +42,14 @@ func setup() (testTuple, error) {
return testTuple{}, errors.Wrapf(err, "failed to create config")
}

db, err := sql.Open(SQLLiteDriver, cfg.GetSessionsDB())
// If the directory doesn't exit opening the SQLLite database will fail.
sessionsDBFile := cfg.GetSessionsDB()
dbDir := filepath.Dir(sessionsDBFile)
if err := os.MkdirAll(dbDir, 0755); err != nil {
return testTuple{}, errors.Wrapf(err, "Failed to create directory: %v", dbDir)
}

db, err := sql.Open(SQLLiteDriver, sessionsDBFile)
if err != nil {
return testTuple{}, errors.Wrapf(err, "Failed to open database")
}
Expand Down
9 changes: 8 additions & 1 deletion app/pkg/application/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"github.com/jlewi/monogo/helpers"

Check failure on line 7 in app/pkg/application/app.go

View workflow job for this annotation

GitHub Actions / golang test & build

File is not `goimports`-ed (goimports)
"io"
"net/http"
"os"
Expand Down Expand Up @@ -380,7 +381,13 @@ func (a *App) SetupAnalyzer() (*analyze.Analyzer, error) {
return nil, errors.New("Config is nil; call LoadConfig first")
}

db, err := sql.Open(analyze.SQLLiteDriver, a.Config.GetSessionsDB())
// If the directory doesn't exit opening the SQLLite database will fail.
sessionsDBFile := a.Config.GetSessionsDB()
dbDir := filepath.Dir(sessionsDBFile)
if err := os.MkdirAll(dbDir, helpers.UserGroupAllPerm); err != nil {
return nil, errors.Wrapf(err, "Failed to create directory: %v", dbDir)
}
db, err := sql.Open(analyze.SQLLiteDriver, sessionsDBFile)

if err != nil {
return nil, errors.Wrapf(err, "Failed to open database: %v", a.Config.GetSessionsDB())
Expand Down

0 comments on commit acf5f50

Please sign in to comment.