mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-18 00:20:29 +00:00
fix: inaccruate 401 & sql busy error (#679)
* fix inaccruate 401 error on SQL db error
* init golangci-lint config
* linter autofix
* testify auto fixes
* fix sqlite busy errors
* fix naming
* more linter errors
* fix rest of linter issues
Former-commit-id: e8449b3a73
This commit is contained in:
parent
5e83b28ff5
commit
03df23d97c
62 changed files with 389 additions and 292 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func locationFactory() LocationCreate {
|
||||
|
@ -24,7 +25,7 @@ func useLocations(t *testing.T, len int) []LocationOut {
|
|||
|
||||
for i := 0; i < len; i++ {
|
||||
loc, err := tRepos.Locations.Create(context.Background(), tGroup.ID, locationFactory())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
out[i] = loc
|
||||
}
|
||||
|
||||
|
@ -42,15 +43,15 @@ func useLocations(t *testing.T, len int) []LocationOut {
|
|||
|
||||
func TestLocationRepository_Get(t *testing.T) {
|
||||
loc, err := tRepos.Locations.Create(context.Background(), tGroup.ID, locationFactory())
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Get by ID
|
||||
foundLoc, err := tRepos.Locations.Get(context.Background(), loc.ID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, loc.ID, foundLoc.ID)
|
||||
|
||||
err = tRepos.Locations.delete(context.Background(), loc.ID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestLocationRepositoryGetAllWithCount(t *testing.T) {
|
||||
|
@ -63,10 +64,10 @@ func TestLocationRepositoryGetAllWithCount(t *testing.T) {
|
|||
LocationID: result.ID,
|
||||
})
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
results, err := tRepos.Locations.GetAll(context.Background(), tGroup.ID, LocationQuery{})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, loc := range results {
|
||||
if loc.ID == result.ID {
|
||||
|
@ -80,11 +81,11 @@ func TestLocationRepository_Create(t *testing.T) {
|
|||
|
||||
// Get by ID
|
||||
foundLoc, err := tRepos.Locations.Get(context.Background(), loc.ID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, loc.ID, foundLoc.ID)
|
||||
|
||||
err = tRepos.Locations.delete(context.Background(), loc.ID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestLocationRepository_Update(t *testing.T) {
|
||||
|
@ -97,27 +98,27 @@ func TestLocationRepository_Update(t *testing.T) {
|
|||
}
|
||||
|
||||
update, err := tRepos.Locations.UpdateByGroup(context.Background(), tGroup.ID, updateData.ID, updateData)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
foundLoc, err := tRepos.Locations.Get(context.Background(), loc.ID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, update.ID, foundLoc.ID)
|
||||
assert.Equal(t, update.Name, foundLoc.Name)
|
||||
assert.Equal(t, update.Description, foundLoc.Description)
|
||||
|
||||
err = tRepos.Locations.delete(context.Background(), loc.ID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestLocationRepository_Delete(t *testing.T) {
|
||||
loc := useLocations(t, 1)[0]
|
||||
|
||||
err := tRepos.Locations.delete(context.Background(), loc.ID)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = tRepos.Locations.Get(context.Background(), loc.ID)
|
||||
assert.Error(t, err)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestItemRepository_TreeQuery(t *testing.T) {
|
||||
|
@ -130,18 +131,18 @@ func TestItemRepository_TreeQuery(t *testing.T) {
|
|||
Name: locs[0].Name,
|
||||
Description: locs[0].Description,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
locations, err := tRepos.Locations.Tree(context.Background(), tGroup.ID, TreeQuery{WithItems: true})
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, 2, len(locations))
|
||||
assert.Len(t, locations, 2)
|
||||
|
||||
// Check roots
|
||||
for _, loc := range locations {
|
||||
if loc.ID == locs[1].ID {
|
||||
assert.Equal(t, 1, len(loc.Children))
|
||||
assert.Len(t, loc.Children, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,15 +158,15 @@ func TestLocationRepository_PathForLoc(t *testing.T) {
|
|||
Name: locs[i].Name,
|
||||
Description: locs[i].Description,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
last := locs[0]
|
||||
|
||||
path, err := tRepos.Locations.PathForLoc(context.Background(), tGroup.ID, last.ID)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 3, len(path))
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, path, 3)
|
||||
|
||||
// Check path and order
|
||||
for i, loc := range path {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue