Skip to content

Commit

Permalink
test output
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkuhn committed Nov 18, 2024
1 parent 57e9ff4 commit 4acf0a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/punch.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var punchCmd = &cobra.Command{
return err
}
}
punchOpts.Out = rootCmd.OutOrStdout()
t := tracker.New(&punchOpts)
return t.PunchReport(cmd.Context())
},
Expand Down
12 changes: 12 additions & 0 deletions cmd/punch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ func TestSum(t *testing.T) {
"",
"cannot parse",
},
"ok-2-args": {
[]string{"4h5m", "2024-11-11"},
"Monday",
"",
},
"ok-1-arg": {
[]string{"4h5m"},
"Monday",
"",
},
}

for name, te := range tests {
Expand All @@ -45,6 +55,8 @@ func TestSum(t *testing.T) {
err := rootCmd.Execute()
if te.error != "" {
assert.ErrorContains(t, err, te.error)
} else {
assert.NoError(t, err)
}
assert.Contains(t, actual.String(), te.out)
})
Expand Down
4 changes: 4 additions & 0 deletions pkg/tracker/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ var initSQL string

// initDB initializes SQLite DB in local filesystem
func initDB(opts *Options) (*sqlx.DB, error) {
if err := os.MkdirAll(opts.AppDir(), os.ModePerm); err != nil {
return nil, fmt.Errorf("cannot create app dir %s: %w", opts.AppDir(), err)
}
dbFile := filepath.Join(opts.AppDir(), "db.sqlite3")

log.Printf("🥫 Open database file=%s sqlite=%s", dbFile, sqlite3.SQLITE_VERSION)
db, err := sqlx.Open("sqlite", dbFile)
if err != nil {
Expand Down

0 comments on commit 4acf0a2

Please sign in to comment.