Skip to content

Commit

Permalink
test: Add tests for the GetEntryByUid function
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Dec 21, 2024
1 parent 3515329 commit e7c4f79
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cmd/api/get-entry-by-uid_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package api

import (
"os"
"testing"

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

func TestGetEntryByUid(t *testing.T) {
init_env.Main("../../.env.test")
err := database.Connect()
assert.Equal(t, nil, err)

err = migrate_db.Main(true)
assert.Equal(t, nil, err)

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

_, err = GetEntryByUid("", "", false)
assert.NotEqual(t, nil, err)

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

err = insertPage("testingen", "testing", "")
assert.Equal(t, nil, err)

_, err = GetEntryByUid("testing", "en", true)
assert.Equal(t, nil, err)
}

0 comments on commit e7c4f79

Please sign in to comment.