Modules: chase API change, use std::chrono::seconds

This commit is contained in:
Adriaan de Groot 2019-08-01 22:59:06 +02:00
parent e2504627aa
commit a0854a999e
8 changed files with 34 additions and 29 deletions

View file

@ -34,6 +34,8 @@
QTEST_GUILESS_MAIN( ShellProcessTests )
using CommandList = CalamaresUtils::CommandList;
using std::operator""s;
ShellProcessTests::ShellProcessTests()
{
@ -68,8 +70,9 @@ ShellProcessTests::testProcessListSampleConfig()
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 3 );
QCOMPARE( cl.at(0).timeout(), -1 );
QCOMPARE( cl.at(2).timeout(), 3600 ); // slowloris
QCOMPARE( cl.at(0).timeout(), CalamaresUtils::CommandLine::TimeoutNotSet() );
QCOMPARE( cl.at(2).timeout(), 3600s ); // slowloris
}
void ShellProcessTests::testProcessListFromList()
@ -105,9 +108,10 @@ script: "ls /tmp"
)" );
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 1 );
QCOMPARE( cl.at(0).timeout(), 10 );
QCOMPARE( cl.at(0).timeout(), 10s );
QCOMPARE( cl.at(0).command(), QStringLiteral( "ls /tmp" ) );
// Not a string
@ -118,7 +122,6 @@ script: false
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( cl1.isEmpty() );
QCOMPARE( cl1.count(), 0 );
}
void ShellProcessTests::testProcessFromObject()
@ -130,9 +133,10 @@ script:
)" );
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 1 );
QCOMPARE( cl.at(0).timeout(), 20 );
QCOMPARE( cl.at(0).timeout(), 20s );
QCOMPARE( cl.at(0).command(), QStringLiteral( "ls /tmp" ) );
}
@ -148,9 +152,9 @@ script:
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 2 );
QCOMPARE( cl.at(0).timeout(), 12 );
QCOMPARE( cl.at(0).timeout(), 12s );
QCOMPARE( cl.at(0).command(), QStringLiteral( "ls /tmp" ) );
QCOMPARE( cl.at(1).timeout(), -1 ); // not set
QCOMPARE( cl.at(1).timeout(), CalamaresUtils::CommandLine::TimeoutNotSet() ); // not set
}
void ShellProcessTests::testRootSubstitution()
@ -182,30 +186,31 @@ script:
QVERIFY( gs != nullptr );
qDebug() << "Expect WARNING, ERROR, WARNING";
// Doesn't use @@ROOT@@, so no failures
QVERIFY( bool(CommandList(plainScript, false, 10 ).run()) );
QVERIFY( bool(CommandList(plainScript, false, 10s ).run()) );
// Doesn't use @@ROOT@@, but does chroot, so fails
QVERIFY( !bool(CommandList(plainScript, true, 10 ).run()) );
QVERIFY( !bool(CommandList(plainScript, true, 10s ).run()) );
// Does use @@ROOT@@, which is not set, so fails
QVERIFY( !bool(CommandList(rootScript, false, 10 ).run()) );
QVERIFY( !bool(CommandList(rootScript, false, 10s ).run()) );
// .. fails for two reasons
QVERIFY( !bool(CommandList(rootScript, true, 10 ).run()) );
QVERIFY( !bool(CommandList(rootScript, true, 10s ).run()) );
gs->insert( "rootMountPoint", "/tmp" );
// Now that the root is set, two variants work .. still can't
// chroot, unless the rootMountPoint contains a full system,
// *and* we're allowed to chroot (ie. running tests as root).
qDebug() << "Expect no output.";
QVERIFY( bool(CommandList(plainScript, false, 10 ).run()) );
QVERIFY( bool(CommandList(rootScript, false, 10 ).run()) );
QVERIFY( bool(CommandList(plainScript, false, 10s ).run()) );
QVERIFY( bool(CommandList(rootScript, false, 10s ).run()) );
qDebug() << "Expect ERROR";
// But no user set yet
QVERIFY( !bool(CommandList(userScript, false, 10 ).run()) );
QVERIFY( !bool(CommandList(userScript, false, 10s ).run()) );
// Now play dangerous games with shell expansion
gs->insert( "username", "`id -u`" );
QVERIFY( bool(CommandList(userScript, false, 10 ).run()) );
QVERIFY( bool(CommandList(userScript, false, 10s ).run()) );
}