Skip to content

Commit

Permalink
test: Add an extra test to the initDB function
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Jan 15, 2025
1 parent 1fb2346 commit 01b2ba9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package main
import (
"os"
"testing"

"github.com/Dobefu/csb/cmd/database"
"github.com/Dobefu/csb/cmd/logger"
"github.com/stretchr/testify/assert"
)

func TestMain(t *testing.T) {
Expand Down Expand Up @@ -41,3 +45,19 @@ func setArgs(args ...string) {
func TestListSubCommands(t *testing.T) {
listSubCommands()
}

func TestInitDB(t *testing.T) {
var err error
logger.SetExitOnFatal(false)

oldDb := os.Getenv("DB_CONN")
os.Setenv("DB_CONN", "file:/")
err = database.Connect()
assert.Equal(t, nil, err)

initDB()

os.Setenv("DB_CONN", oldDb)
err = database.Connect()
assert.Equal(t, nil, err)
}

0 comments on commit 01b2ba9

Please sign in to comment.