Fixed: Don't try to show diskspace usage non-existing drives.

fixes #1639
This commit is contained in:
Taloth Saldono 2017-02-07 23:06:14 +01:00
parent 657730f4d2
commit 812999423b
3 changed files with 140 additions and 2 deletions

View File

@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.DiskSpace;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.DiskSpace
{
[TestFixture]
public class DiskSpaceServiceFixture : CoreTest<DiskSpaceService>
{
private string _seriesFolder;
private string _seriesFolder2;
private string _droneFactoryFolder;
[SetUp]
public void SetUp()
{
_seriesFolder = @"G:\fasdlfsdf\series".AsOsAgnostic();
_seriesFolder2 = @"G:\fasdlfsdf\series2".AsOsAgnostic();
_droneFactoryFolder = @"G:\dronefactory".AsOsAgnostic();
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.GetMounts())
.Returns(new List<IMount>());
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.GetPathRoot(It.IsAny<string>()))
.Returns(@"G:\".AsOsAgnostic());
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.GetAvailableSpace(It.IsAny<string>()))
.Returns(0);
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.GetTotalSize(It.IsAny<string>()))
.Returns(0);
GivenSeries();
}
private void GivenSeries(params Series[] series)
{
Mocker.GetMock<ISeriesService>()
.Setup(v => v.GetAllSeries())
.Returns(series.ToList());
}
private void GivenExistingFolder(string folder)
{
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.FolderExists(folder))
.Returns(true);
}
[Test]
public void should_check_diskspace_for_series_folders()
{
GivenSeries(new Series { Path = _seriesFolder });
GivenExistingFolder(_seriesFolder);
var freeSpace = Subject.GetFreeSpace();
freeSpace.Should().NotBeEmpty();
}
[Test]
public void should_check_diskspace_for_same_root_folder_only_once()
{
GivenSeries(new Series { Path = _seriesFolder }, new Series { Path = _seriesFolder2 });
GivenExistingFolder(_seriesFolder);
GivenExistingFolder(_seriesFolder2);
var freeSpace = Subject.GetFreeSpace();
freeSpace.Should().HaveCount(1);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetAvailableSpace(It.IsAny<string>()), Times.Once());
}
[Test]
public void should_not_check_diskspace_for_missing_series_folders()
{
GivenSeries(new Series { Path = _seriesFolder });
var freeSpace = Subject.GetFreeSpace();
freeSpace.Should().BeEmpty();
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetAvailableSpace(It.IsAny<string>()), Times.Never());
}
[Test]
public void should_check_diskspace_for_dronefactory_folder()
{
Mocker.GetMock<IConfigService>()
.SetupGet(v => v.DownloadedEpisodesFolder)
.Returns(_droneFactoryFolder);
GivenExistingFolder(_droneFactoryFolder);
var freeSpace = Subject.GetFreeSpace();
freeSpace.Should().NotBeEmpty();
}
[Test]
public void should_not_check_diskspace_for_missing_dronefactory_folder()
{
Mocker.GetMock<IConfigService>()
.SetupGet(v => v.DownloadedEpisodesFolder)
.Returns(_droneFactoryFolder);
var freeSpace = Subject.GetFreeSpace();
freeSpace.Should().BeEmpty();
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetAvailableSpace(It.IsAny<string>()), Times.Never());
}
}
}

View File

@ -165,6 +165,7 @@
<Compile Include="DecisionEngineTests\SameEpisodesSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\RawDiskSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\UpgradeDiskSpecificationFixture.cs" />
<Compile Include="DiskSpace\DiskSpaceServiceFixture.cs" />
<Compile Include="Download\CompletedDownloadServiceFixture.cs" />
<Compile Include="Download\DownloadApprovedReportsTests\DownloadApprovedFixture.cs" />
<Compile Include="Download\DownloadClientTests\Blackhole\ScanWatchFolderFixture.cs" />

View File

@ -42,14 +42,17 @@ namespace NzbDrone.Core.DiskSpace
private IEnumerable<DiskSpace> GetSeriesFreeSpace()
{
var seriesRootPaths = _seriesService.GetAllSeries().Select(s => _diskProvider.GetPathRoot(s.Path)).Distinct();
var seriesRootPaths = _seriesService.GetAllSeries()
.Where(s => _diskProvider.FolderExists(s.Path))
.Select(s => _diskProvider.GetPathRoot(s.Path))
.Distinct();
return GetDiskSpace(seriesRootPaths);
}
private IEnumerable<DiskSpace> GetDroneFactoryFreeSpace()
{
if (!string.IsNullOrWhiteSpace(_configService.DownloadedEpisodesFolder))
if (_configService.DownloadedEpisodesFolder.IsNotNullOrWhiteSpace() && _diskProvider.FolderExists(_configService.DownloadedEpisodesFolder))
{
return GetDiskSpace(new[] { _diskProvider.GetPathRoot(_configService.DownloadedEpisodesFolder) });
}