2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2018-09-14 17:59:50 +02:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2017-2018 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2018-09-14 17:59:50 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2018-09-14 17:59:50 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Tests.h"
|
|
|
|
|
2019-05-14 11:52:58 +02:00
|
|
|
#include "ResizeFSJob.h"
|
|
|
|
|
2018-09-14 17:59:50 +02:00
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
|
|
|
#include "Settings.h"
|
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
2019-04-29 12:04:55 +02:00
|
|
|
#include "utils/Yaml.h"
|
2018-09-14 17:59:50 +02:00
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QStringList>
|
|
|
|
|
2019-05-14 11:52:58 +02:00
|
|
|
using SizeUnit = CalamaresUtils::Partition::SizeUnit;
|
2018-09-14 17:59:50 +02:00
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN( FSResizerTests )
|
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
FSResizerTests::FSResizerTests() {}
|
2018-09-14 17:59:50 +02:00
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
FSResizerTests::~FSResizerTests() {}
|
2018-09-14 17:59:50 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
FSResizerTests::initTestCase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
void
|
|
|
|
FSResizerTests::testConfigurationRobust()
|
2018-09-14 17:59:50 +02:00
|
|
|
{
|
|
|
|
ResizeFSJob j;
|
2019-01-11 19:49:39 +01:00
|
|
|
|
2018-09-14 17:59:50 +02:00
|
|
|
// Empty config
|
|
|
|
j.setConfigurationMap( QVariantMap() );
|
2019-05-14 11:11:07 +02:00
|
|
|
QVERIFY( j.name().isEmpty() );
|
2019-05-14 11:52:58 +02:00
|
|
|
QCOMPARE( j.size().unit(), SizeUnit::None );
|
|
|
|
QCOMPARE( j.minimumSize().unit(), SizeUnit::None );
|
2018-09-14 17:59:50 +02:00
|
|
|
|
|
|
|
// Config is missing fs and dev, so it isn't valid
|
|
|
|
YAML::Node doc0 = YAML::Load( R"(---
|
|
|
|
size: 100%
|
|
|
|
atleast: 600MiB
|
|
|
|
)" );
|
2020-03-22 23:04:12 +01:00
|
|
|
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ) );
|
2019-05-14 11:11:07 +02:00
|
|
|
QVERIFY( j.name().isEmpty() );
|
2019-05-14 11:52:58 +02:00
|
|
|
QCOMPARE( j.size().unit(), SizeUnit::None );
|
|
|
|
QCOMPARE( j.minimumSize().unit(), SizeUnit::None );
|
2019-05-14 11:11:07 +02:00
|
|
|
QCOMPARE( j.size().value(), 0 );
|
|
|
|
QCOMPARE( j.minimumSize().value(), 0 );
|
2019-01-11 19:49:39 +01:00
|
|
|
}
|
2018-09-14 17:59:50 +02:00
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
void
|
|
|
|
FSResizerTests::testConfigurationValues()
|
2018-09-14 17:59:50 +02:00
|
|
|
{
|
|
|
|
ResizeFSJob j;
|
|
|
|
|
2019-01-11 19:49:39 +01:00
|
|
|
// Check both
|
2018-09-14 17:59:50 +02:00
|
|
|
YAML::Node doc0 = YAML::Load( R"(---
|
|
|
|
fs: /
|
|
|
|
size: 100%
|
|
|
|
atleast: 600MiB
|
|
|
|
)" );
|
2020-03-22 23:04:12 +01:00
|
|
|
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ) );
|
2019-06-03 11:09:51 +02:00
|
|
|
QVERIFY( !j.name().isEmpty() );
|
2020-08-22 01:19:58 +02:00
|
|
|
QCOMPARE( j.name(), QString( "/" ) );
|
2019-05-14 11:52:58 +02:00
|
|
|
QCOMPARE( j.size().unit(), SizeUnit::Percent );
|
|
|
|
QCOMPARE( j.minimumSize().unit(), SizeUnit::MiB );
|
2019-05-14 11:11:07 +02:00
|
|
|
QCOMPARE( j.size().value(), 100 );
|
|
|
|
QCOMPARE( j.minimumSize().value(), 600 );
|
2018-09-14 17:59:50 +02:00
|
|
|
|
2019-06-03 11:09:51 +02:00
|
|
|
// Silly config has bad atleast value
|
2018-09-14 17:59:50 +02:00
|
|
|
doc0 = YAML::Load( R"(---
|
|
|
|
fs: /
|
|
|
|
dev: /dev/m00
|
|
|
|
size: 72 MiB
|
|
|
|
atleast: 127 %
|
|
|
|
)" );
|
2020-03-22 23:04:12 +01:00
|
|
|
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ) );
|
2019-05-14 11:11:07 +02:00
|
|
|
QVERIFY( !j.name().isEmpty() );
|
2020-08-22 01:19:58 +02:00
|
|
|
QCOMPARE( j.name(), QString( "/" ) );
|
2019-06-03 11:09:51 +02:00
|
|
|
QCOMPARE( j.size().unit(), SizeUnit::MiB );
|
|
|
|
QCOMPARE( j.minimumSize().unit(), SizeUnit::None );
|
|
|
|
QCOMPARE( j.size().value(), 72 );
|
|
|
|
QCOMPARE( j.minimumSize().value(), 0 );
|
|
|
|
|
|
|
|
// Silly config has bad atleast value
|
|
|
|
doc0 = YAML::Load( R"(---
|
|
|
|
dev: /dev/m00
|
|
|
|
size: 72 MiB
|
|
|
|
atleast: 127 %
|
|
|
|
)" );
|
2020-03-22 23:04:12 +01:00
|
|
|
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ) );
|
2019-06-03 11:09:51 +02:00
|
|
|
QVERIFY( !j.name().isEmpty() );
|
2020-08-22 01:19:58 +02:00
|
|
|
QCOMPARE( j.name(), QString( "/dev/m00" ) );
|
2019-05-14 11:52:58 +02:00
|
|
|
QCOMPARE( j.size().unit(), SizeUnit::MiB );
|
|
|
|
QCOMPARE( j.minimumSize().unit(), SizeUnit::None );
|
2019-05-14 11:11:07 +02:00
|
|
|
QCOMPARE( j.size().value(), 72 );
|
|
|
|
QCOMPARE( j.minimumSize().value(), 0 );
|
2018-09-14 17:59:50 +02:00
|
|
|
|
2019-06-03 11:09:51 +02:00
|
|
|
// Normal config
|
2018-09-14 17:59:50 +02:00
|
|
|
doc0 = YAML::Load( R"(---
|
|
|
|
fs: /
|
|
|
|
# dev: /dev/m00
|
|
|
|
size: 71MiB
|
|
|
|
# atleast: 127%
|
|
|
|
)" );
|
2020-03-22 23:04:12 +01:00
|
|
|
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ) );
|
2019-06-03 11:09:51 +02:00
|
|
|
QVERIFY( !j.name().isEmpty() );
|
2020-08-22 01:19:58 +02:00
|
|
|
QCOMPARE( j.name(), QString( "/" ) );
|
2019-05-14 11:52:58 +02:00
|
|
|
QCOMPARE( j.size().unit(), SizeUnit::MiB );
|
|
|
|
QCOMPARE( j.minimumSize().unit(), SizeUnit::None );
|
2019-05-14 11:11:07 +02:00
|
|
|
QCOMPARE( j.size().value(), 71 );
|
|
|
|
QCOMPARE( j.minimumSize().value(), 0 );
|
2018-09-14 17:59:50 +02:00
|
|
|
}
|