feat(channels): add auto-disable-only channel test mode (#6728)
This commit is contained in:
@@ -1049,6 +1049,9 @@ func selectChannelsForAutomaticTest(channels []*model.Channel, mode string) []*m
|
||||
if channel.Status == common.ChannelStatusManuallyDisabled {
|
||||
continue
|
||||
}
|
||||
if mode == operation_setting.ChannelTestModeAutoBanOnly && !channel.GetAutoBan() {
|
||||
continue
|
||||
}
|
||||
if mode == operation_setting.ChannelTestModePassiveRecovery && channel.Status != common.ChannelStatusAutoDisabled {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -312,6 +312,24 @@ func TestSelectChannelsForAutomaticTestScheduledSkipsManualDisabled(t *testing.T
|
||||
require.Equal(t, 2, selected[1].Id)
|
||||
}
|
||||
|
||||
func TestSelectChannelsForAutomaticTestAutoBanOnlyUsesEligibleChannels(t *testing.T) {
|
||||
autoBanEnabled := 1
|
||||
autoBanDisabled := 0
|
||||
channels := []*model.Channel{
|
||||
{Id: 1, Status: common.ChannelStatusEnabled, AutoBan: &autoBanEnabled},
|
||||
{Id: 2, Status: common.ChannelStatusEnabled, AutoBan: &autoBanDisabled},
|
||||
{Id: 3, Status: common.ChannelStatusAutoDisabled, AutoBan: &autoBanEnabled},
|
||||
{Id: 4, Status: common.ChannelStatusManuallyDisabled, AutoBan: &autoBanEnabled},
|
||||
{Id: 5, Status: common.ChannelStatusEnabled},
|
||||
}
|
||||
|
||||
selected := selectChannelsForAutomaticTest(channels, operation_setting.ChannelTestModeAutoBanOnly)
|
||||
|
||||
require.Len(t, selected, 2)
|
||||
require.Equal(t, 1, selected[0].Id)
|
||||
require.Equal(t, 3, selected[1].Id)
|
||||
}
|
||||
|
||||
func TestTestAllChannelsRejectsExistingActiveTask(t *testing.T) {
|
||||
db := setupModelListControllerTestDB(t)
|
||||
require.NoError(t, db.AutoMigrate(&model.SystemTask{}, &model.SystemTaskLock{}))
|
||||
|
||||
Reference in New Issue
Block a user