Simple blogging system written in Go https://goblog.app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
820 B

package main
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_shortenPath(t *testing.T) {
app := &goBlog{
cfg: &config{
Db: &configDb{
File: filepath.Join(t.TempDir(), "test.db"),
},
},
}
_ = app.initDatabase(false)
db := app.db
res1, err := db.shortenPath("/a")
require.NoError(t, err)
db.spc.Delete("/a")
res2, err := db.shortenPath("/a")
require.NoError(t, err)
res3, err := db.shortenPath("/b")
require.NoError(t, err)
assert.Equal(t, res1, res2)
assert.Equal(t, "/s/1", res1)
assert.NotEqual(t, res1, res3)
assert.Equal(t, "/s/2", res3)
db.spc.Delete("/a")
db.exec("delete from shortpath where id = 1")
res4, err := db.shortenPath("/c")
require.NoError(t, err)
assert.Equal(t, "/s/1", res4)
}