forked from go-shiori/shiori
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(psql): save bookmarks not using passed bookmark id for the insert (…
…go-shiori#484) * fix(psql): get last inserted id from insert query book.ID was not being used, so inserts were failing. the check for book.ID was removed and it is filled with the returning id from the insert query * test(psql): added save bookmarks simple test * ci: added postgresql service * fix(typo): QueryRow -> QueryRowContext * ci: explicit postgresql port * ci(test): 1.19 only * ci: bind psql to localhost * test(pg): migrate before test * test(pg): migrate database before test * fix(pg): check no rows error on get query
- Loading branch information
Showing
5 changed files
with
79 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/go-shiori/shiori/internal/model" | ||
"github.com/golang-migrate/migrate/v4" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func init() { | ||
testPsqlURL := os.Getenv("SHIORI_TEST_PG_URL") | ||
if testPsqlURL == "" { | ||
log.Fatal("psql tests can't run without a PSQL database") | ||
} | ||
} | ||
|
||
func TestPsqlSaveBookmarkWithTag(t *testing.T) { | ||
ctx := context.TODO() | ||
pgDB, err := OpenPGDatabase(ctx, os.Getenv("SHIORI_TEST_PG_URL")) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if err := pgDB.Migrate(); err != nil && !errors.Is(migrate.ErrNoChange, err) { | ||
t.Error(err) | ||
} | ||
|
||
book := model.Bookmark{ | ||
URL: "https://github.com/go-shiori/obelisk", | ||
Title: "shiori", | ||
Tags: []model.Tag{ | ||
{ | ||
Name: "test-tag", | ||
}, | ||
}, | ||
} | ||
|
||
result, err := pgDB.SaveBookmarks(ctx, book) | ||
|
||
assert.NoError(t, err, "Save bookmarks must not fail") | ||
assert.Equal(t, book.URL, result[0].URL) | ||
assert.Equal(t, book.Tags[0].Name, result[0].Tags[0].Name) | ||
} |