mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
fix(actions): reject if client is disabled (#1626)
* fix(actions): error on disabled client * fix(actions): sql scan args * refactor: download client cache for actions * fix: tests client store * fix: tests client store and int conversion * fix: tests revert findbyid ctx timeout * fix: tests row.err * feat: add logging to download client cache
This commit is contained in:
parent
77e1c2c305
commit
861f30c144
30 changed files with 928 additions and 680 deletions
|
@ -89,9 +89,10 @@ func TestReleaseRepo_Store(t *testing.T) {
|
|||
|
||||
t.Run(fmt.Sprintf("StoreReleaseActionStatus_Succeeds [%s]", dbType), func(t *testing.T) {
|
||||
// Setup
|
||||
createdClient, err := downloadClientRepo.Store(context.Background(), getMockDownloadClient())
|
||||
mock := getMockDownloadClient()
|
||||
err := downloadClientRepo.Store(context.Background(), &mock)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, createdClient)
|
||||
assert.NotNil(t, mock)
|
||||
|
||||
err = filterRepo.Store(context.Background(), getMockFilter())
|
||||
assert.NoError(t, err)
|
||||
|
@ -101,7 +102,7 @@ func TestReleaseRepo_Store(t *testing.T) {
|
|||
assert.NotNil(t, createdFilters)
|
||||
|
||||
actionMockData.FilterID = createdFilters[0].ID
|
||||
actionMockData.ClientID = int32(createdClient.ID)
|
||||
actionMockData.ClientID = mock.ID
|
||||
mockData.FilterID = createdFilters[0].ID
|
||||
|
||||
// Execute
|
||||
|
@ -124,7 +125,7 @@ func TestReleaseRepo_Store(t *testing.T) {
|
|||
_ = repo.Delete(context.Background(), &domain.DeleteReleaseRequest{OlderThan: 0})
|
||||
_ = actionRepo.Delete(context.Background(), &domain.DeleteActionRequest{ActionId: createdAction.ID})
|
||||
_ = filterRepo.Delete(context.Background(), createdFilters[0].ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), createdClient.ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), mock.ID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -144,9 +145,10 @@ func TestReleaseRepo_StoreReleaseActionStatus(t *testing.T) {
|
|||
|
||||
t.Run(fmt.Sprintf("StoreReleaseActionStatus_Succeeds [%s]", dbType), func(t *testing.T) {
|
||||
// Setup
|
||||
createdClient, err := downloadClientRepo.Store(context.Background(), getMockDownloadClient())
|
||||
mock := getMockDownloadClient()
|
||||
err := downloadClientRepo.Store(context.Background(), &mock)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, createdClient)
|
||||
assert.NotNil(t, mock)
|
||||
|
||||
err = filterRepo.Store(context.Background(), getMockFilter())
|
||||
assert.NoError(t, err)
|
||||
|
@ -156,7 +158,7 @@ func TestReleaseRepo_StoreReleaseActionStatus(t *testing.T) {
|
|||
assert.NotNil(t, createdFilters)
|
||||
|
||||
actionMockData.FilterID = createdFilters[0].ID
|
||||
actionMockData.ClientID = int32(createdClient.ID)
|
||||
actionMockData.ClientID = mock.ID
|
||||
mockData.FilterID = createdFilters[0].ID
|
||||
|
||||
// Execute
|
||||
|
@ -179,7 +181,7 @@ func TestReleaseRepo_StoreReleaseActionStatus(t *testing.T) {
|
|||
_ = repo.Delete(context.Background(), &domain.DeleteReleaseRequest{OlderThan: 0})
|
||||
_ = actionRepo.Delete(context.Background(), &domain.DeleteActionRequest{ActionId: createdAction.ID})
|
||||
_ = filterRepo.Delete(context.Background(), createdFilters[0].ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), createdClient.ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), mock.ID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -199,9 +201,10 @@ func TestReleaseRepo_Find(t *testing.T) {
|
|||
|
||||
t.Run(fmt.Sprintf("FindReleases_Succeeds [%s]", dbType), func(t *testing.T) {
|
||||
// Setup
|
||||
createdClient, err := downloadClientRepo.Store(context.Background(), getMockDownloadClient())
|
||||
mock := getMockDownloadClient()
|
||||
err := downloadClientRepo.Store(context.Background(), &mock)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, createdClient)
|
||||
assert.NotNil(t, mock)
|
||||
|
||||
err = filterRepo.Store(context.Background(), getMockFilter())
|
||||
assert.NoError(t, err)
|
||||
|
@ -211,7 +214,7 @@ func TestReleaseRepo_Find(t *testing.T) {
|
|||
assert.NotNil(t, createdFilters)
|
||||
|
||||
actionMockData.FilterID = createdFilters[0].ID
|
||||
actionMockData.ClientID = int32(createdClient.ID)
|
||||
actionMockData.ClientID = mock.ID
|
||||
mockData.FilterID = createdFilters[0].ID
|
||||
|
||||
// Execute
|
||||
|
@ -238,7 +241,7 @@ func TestReleaseRepo_Find(t *testing.T) {
|
|||
// Cleanup
|
||||
_ = repo.Delete(context.Background(), &domain.DeleteReleaseRequest{OlderThan: 0})
|
||||
_ = filterRepo.Delete(context.Background(), createdFilters[0].ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), createdClient.ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), mock.ID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -258,9 +261,10 @@ func TestReleaseRepo_FindRecent(t *testing.T) {
|
|||
|
||||
t.Run(fmt.Sprintf("FindRecent_Succeeds [%s]", dbType), func(t *testing.T) {
|
||||
// Setup
|
||||
createdClient, err := downloadClientRepo.Store(context.Background(), getMockDownloadClient())
|
||||
mock := getMockDownloadClient()
|
||||
err := downloadClientRepo.Store(context.Background(), &mock)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, createdClient)
|
||||
assert.NotNil(t, mock)
|
||||
|
||||
err = filterRepo.Store(context.Background(), getMockFilter())
|
||||
assert.NoError(t, err)
|
||||
|
@ -270,7 +274,7 @@ func TestReleaseRepo_FindRecent(t *testing.T) {
|
|||
assert.NotNil(t, createdFilters)
|
||||
|
||||
actionMockData.FilterID = createdFilters[0].ID
|
||||
actionMockData.ClientID = int32(createdClient.ID)
|
||||
actionMockData.ClientID = mock.ID
|
||||
mockData.FilterID = createdFilters[0].ID
|
||||
|
||||
// Execute
|
||||
|
@ -286,7 +290,7 @@ func TestReleaseRepo_FindRecent(t *testing.T) {
|
|||
// Cleanup
|
||||
_ = repo.Delete(context.Background(), &domain.DeleteReleaseRequest{OlderThan: 0})
|
||||
_ = filterRepo.Delete(context.Background(), createdFilters[0].ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), createdClient.ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), mock.ID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -306,9 +310,10 @@ func TestReleaseRepo_GetIndexerOptions(t *testing.T) {
|
|||
|
||||
t.Run(fmt.Sprintf("GetIndexerOptions_Succeeds [%s]", dbType), func(t *testing.T) {
|
||||
// Setup
|
||||
createdClient, err := downloadClientRepo.Store(context.Background(), getMockDownloadClient())
|
||||
mock := getMockDownloadClient()
|
||||
err := downloadClientRepo.Store(context.Background(), &mock)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, createdClient)
|
||||
assert.NotNil(t, mock)
|
||||
|
||||
err = filterRepo.Store(context.Background(), getMockFilter())
|
||||
assert.NoError(t, err)
|
||||
|
@ -318,7 +323,7 @@ func TestReleaseRepo_GetIndexerOptions(t *testing.T) {
|
|||
assert.NotNil(t, createdFilters)
|
||||
|
||||
actionMockData.FilterID = createdFilters[0].ID
|
||||
actionMockData.ClientID = int32(createdClient.ID)
|
||||
actionMockData.ClientID = mock.ID
|
||||
mockData.FilterID = createdFilters[0].ID
|
||||
|
||||
err = repo.Store(context.Background(), mockData)
|
||||
|
@ -344,7 +349,7 @@ func TestReleaseRepo_GetIndexerOptions(t *testing.T) {
|
|||
_ = repo.Delete(context.Background(), &domain.DeleteReleaseRequest{OlderThan: 0})
|
||||
_ = actionRepo.Delete(context.Background(), &domain.DeleteActionRequest{ActionId: createdAction.ID})
|
||||
_ = filterRepo.Delete(context.Background(), createdFilters[0].ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), createdClient.ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), mock.ID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -364,9 +369,10 @@ func TestReleaseRepo_GetActionStatusByReleaseID(t *testing.T) {
|
|||
|
||||
t.Run(fmt.Sprintf("GetActionStatusByReleaseID_Succeeds [%s]", dbType), func(t *testing.T) {
|
||||
// Setup
|
||||
createdClient, err := downloadClientRepo.Store(context.Background(), getMockDownloadClient())
|
||||
mock := getMockDownloadClient()
|
||||
err := downloadClientRepo.Store(context.Background(), &mock)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, createdClient)
|
||||
assert.NotNil(t, mock)
|
||||
|
||||
err = filterRepo.Store(context.Background(), getMockFilter())
|
||||
assert.NoError(t, err)
|
||||
|
@ -376,7 +382,7 @@ func TestReleaseRepo_GetActionStatusByReleaseID(t *testing.T) {
|
|||
assert.NotNil(t, createdFilters)
|
||||
|
||||
actionMockData.FilterID = createdFilters[0].ID
|
||||
actionMockData.ClientID = int32(createdClient.ID)
|
||||
actionMockData.ClientID = mock.ID
|
||||
mockData.FilterID = createdFilters[0].ID
|
||||
|
||||
err = repo.Store(context.Background(), mockData)
|
||||
|
@ -403,7 +409,7 @@ func TestReleaseRepo_GetActionStatusByReleaseID(t *testing.T) {
|
|||
_ = repo.Delete(context.Background(), &domain.DeleteReleaseRequest{OlderThan: 0})
|
||||
_ = actionRepo.Delete(context.Background(), &domain.DeleteActionRequest{ActionId: createdAction.ID})
|
||||
_ = filterRepo.Delete(context.Background(), createdFilters[0].ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), createdClient.ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), mock.ID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -423,9 +429,10 @@ func TestReleaseRepo_Get(t *testing.T) {
|
|||
|
||||
t.Run(fmt.Sprintf("Get_Succeeds [%s]", dbType), func(t *testing.T) {
|
||||
// Setup
|
||||
createdClient, err := downloadClientRepo.Store(context.Background(), getMockDownloadClient())
|
||||
mock := getMockDownloadClient()
|
||||
err := downloadClientRepo.Store(context.Background(), &mock)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, createdClient)
|
||||
assert.NotNil(t, mock)
|
||||
|
||||
err = filterRepo.Store(context.Background(), getMockFilter())
|
||||
assert.NoError(t, err)
|
||||
|
@ -435,7 +442,7 @@ func TestReleaseRepo_Get(t *testing.T) {
|
|||
assert.NotNil(t, createdFilters)
|
||||
|
||||
actionMockData.FilterID = createdFilters[0].ID
|
||||
actionMockData.ClientID = int32(createdClient.ID)
|
||||
actionMockData.ClientID = mock.ID
|
||||
mockData.FilterID = createdFilters[0].ID
|
||||
|
||||
err = repo.Store(context.Background(), mockData)
|
||||
|
@ -462,7 +469,7 @@ func TestReleaseRepo_Get(t *testing.T) {
|
|||
_ = repo.Delete(context.Background(), &domain.DeleteReleaseRequest{OlderThan: 0})
|
||||
_ = actionRepo.Delete(context.Background(), &domain.DeleteActionRequest{ActionId: createdAction.ID})
|
||||
_ = filterRepo.Delete(context.Background(), createdFilters[0].ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), createdClient.ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), mock.ID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -482,9 +489,10 @@ func TestReleaseRepo_Stats(t *testing.T) {
|
|||
|
||||
t.Run(fmt.Sprintf("Stats_Succeeds [%s]", dbType), func(t *testing.T) {
|
||||
// Setup
|
||||
createdClient, err := downloadClientRepo.Store(context.Background(), getMockDownloadClient())
|
||||
mock := getMockDownloadClient()
|
||||
err := downloadClientRepo.Store(context.Background(), &mock)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, createdClient)
|
||||
assert.NotNil(t, mock)
|
||||
|
||||
err = filterRepo.Store(context.Background(), getMockFilter())
|
||||
assert.NoError(t, err)
|
||||
|
@ -494,7 +502,7 @@ func TestReleaseRepo_Stats(t *testing.T) {
|
|||
assert.NotNil(t, createdFilters)
|
||||
|
||||
actionMockData.FilterID = createdFilters[0].ID
|
||||
actionMockData.ClientID = int32(createdClient.ID)
|
||||
actionMockData.ClientID = mock.ID
|
||||
mockData.FilterID = createdFilters[0].ID
|
||||
|
||||
err = repo.Store(context.Background(), mockData)
|
||||
|
@ -521,7 +529,7 @@ func TestReleaseRepo_Stats(t *testing.T) {
|
|||
_ = repo.Delete(context.Background(), &domain.DeleteReleaseRequest{OlderThan: 0})
|
||||
_ = actionRepo.Delete(context.Background(), &domain.DeleteActionRequest{ActionId: createdAction.ID})
|
||||
_ = filterRepo.Delete(context.Background(), createdFilters[0].ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), createdClient.ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), mock.ID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -541,9 +549,10 @@ func TestReleaseRepo_Delete(t *testing.T) {
|
|||
|
||||
t.Run(fmt.Sprintf("Delete_Succeeds [%s]", dbType), func(t *testing.T) {
|
||||
// Setup
|
||||
createdClient, err := downloadClientRepo.Store(context.Background(), getMockDownloadClient())
|
||||
mock := getMockDownloadClient()
|
||||
err := downloadClientRepo.Store(context.Background(), &mock)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, createdClient)
|
||||
assert.NotNil(t, mock)
|
||||
|
||||
err = filterRepo.Store(context.Background(), getMockFilter())
|
||||
assert.NoError(t, err)
|
||||
|
@ -553,7 +562,7 @@ func TestReleaseRepo_Delete(t *testing.T) {
|
|||
assert.NotNil(t, createdFilters)
|
||||
|
||||
actionMockData.FilterID = createdFilters[0].ID
|
||||
actionMockData.ClientID = int32(createdClient.ID)
|
||||
actionMockData.ClientID = mock.ID
|
||||
mockData.FilterID = createdFilters[0].ID
|
||||
|
||||
err = repo.Store(context.Background(), mockData)
|
||||
|
@ -577,7 +586,7 @@ func TestReleaseRepo_Delete(t *testing.T) {
|
|||
// Cleanup
|
||||
_ = actionRepo.Delete(context.Background(), &domain.DeleteActionRequest{ActionId: createdAction.ID})
|
||||
_ = filterRepo.Delete(context.Background(), createdFilters[0].ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), createdClient.ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), mock.ID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -597,9 +606,10 @@ func TestReleaseRepo_CheckSmartEpisodeCanDownloadShow(t *testing.T) {
|
|||
|
||||
t.Run(fmt.Sprintf("Check_Smart_Episode_Can_Download [%s]", dbType), func(t *testing.T) {
|
||||
// Setup
|
||||
createdClient, err := downloadClientRepo.Store(context.Background(), getMockDownloadClient())
|
||||
mock := getMockDownloadClient()
|
||||
err := downloadClientRepo.Store(context.Background(), &mock)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, createdClient)
|
||||
assert.NotNil(t, mock)
|
||||
|
||||
err = filterRepo.Store(context.Background(), getMockFilter())
|
||||
assert.NoError(t, err)
|
||||
|
@ -609,7 +619,7 @@ func TestReleaseRepo_CheckSmartEpisodeCanDownloadShow(t *testing.T) {
|
|||
assert.NotNil(t, createdFilters)
|
||||
|
||||
actionMockData.FilterID = createdFilters[0].ID
|
||||
actionMockData.ClientID = int32(createdClient.ID)
|
||||
actionMockData.ClientID = mock.ID
|
||||
mockData.FilterID = createdFilters[0].ID
|
||||
|
||||
err = repo.Store(context.Background(), mockData)
|
||||
|
@ -644,7 +654,7 @@ func TestReleaseRepo_CheckSmartEpisodeCanDownloadShow(t *testing.T) {
|
|||
_ = repo.Delete(context.Background(), &domain.DeleteReleaseRequest{OlderThan: 0})
|
||||
_ = actionRepo.Delete(context.Background(), &domain.DeleteActionRequest{ActionId: createdAction.ID})
|
||||
_ = filterRepo.Delete(context.Background(), createdFilters[0].ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), createdClient.ID)
|
||||
_ = downloadClientRepo.Delete(context.Background(), mock.ID)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue