Skip to content

Commit

Permalink
✨ improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codermuss committed Jul 29, 2024
1 parent 13d0081 commit 51d0da9
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 5 deletions.
14 changes: 14 additions & 0 deletions db/mock/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions db/query/sessions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ WHERE id = $1;
-- WHERE id = $8
-- RETURNING *;

-- -- name: DeleteSession :exec
-- DELETE FROM sessions
-- WHERE id = $1;
-- name: DeleteSession :exec
DELETE FROM sessions
WHERE id = $1;
12 changes: 12 additions & 0 deletions db/sqlc/categories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ func TestGetCategory(t *testing.T) {

}

func TestGetCategories(t *testing.T) {
createRandomCategory(t)
createRandomCategory(t)
createRandomCategory(t)

categories, err := testStore.GetCategories(context.Background())
require.NoError(t, err)
require.NotEmpty(t, categories)
require.True(t, len(categories) > 2)

}

func TestUpdateCategory(t *testing.T) {
randomcategory := createRandomCategory(t)
newCategoryName := util.RandomString(6)
Expand Down
6 changes: 6 additions & 0 deletions db/sqlc/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions db/sqlc/sessions.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions db/sqlc/sessions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ func TestCreateCreateSession(t *testing.T) {

func TestGetSession(t *testing.T) {
session := createSession(t)
comments, err := testStore.GetSession(context.Background(), session.ID)
takenSession, err := testStore.GetSession(context.Background(), session.ID)
require.NoError(t, err)
require.NotEmpty(t, comments)
require.NotEmpty(t, takenSession)
}

func TestDeleteSession(t *testing.T) {
session := createSession(t)
takenSession, err := testStore.GetSession(context.Background(), session.ID)
require.NoError(t, err)
require.NotEmpty(t, takenSession)
err = testStore.DeleteSession(context.Background(), session.ID)
require.NoError(t, err)
deletedSession, err := testStore.GetSession(context.Background(), session.ID)
require.Error(t, err)
require.ErrorIs(t, err, ErrRecordNotFound)
require.Empty(t, deletedSession)
}
11 changes: 11 additions & 0 deletions db/sqlc/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ func TestGetTag(t *testing.T) {
require.Equal(t, randomtag.ID, tag.ID)
require.Equal(t, randomtag.Name, tag.Name)

}
func TestGetTags(t *testing.T) {
createRandomTag(t)
createRandomTag(t)
createRandomTag(t)

tags, err := testStore.GetTags(context.Background())
require.NoError(t, err)
require.NotEmpty(t, tags)
require.True(t, len(tags) > 2)

}

func TestUpdateTag(t *testing.T) {
Expand Down

0 comments on commit 51d0da9

Please sign in to comment.