Skip to content

Commit

Permalink
Adding unit tests on the new clip --best option
Browse files Browse the repository at this point in the history
  • Loading branch information
lerignoux committed Aug 26, 2020
1 parent 07f6f09 commit 09ec0b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cli/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int Clip::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<
return EXIT_FAILURE;
} else {
bestEntryPath = (results.isEmpty()) ? args.at(1) : results[0];
err << QObject::tr("Matching \"%1\" entry used.").arg(bestEntryPath) << endl;
out << QObject::tr("Matching \"%1\" entry used.").arg(bestEntryPath) << endl;
}
} else {
bestEntryPath = args.at(1);
Expand Down
16 changes: 16 additions & 0 deletions tests/TestCli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ void TestCli::init()
m_dbFile2.reset(new TemporaryFile());
m_dbFile2->copyFromFile(file.arg("NewDatabase2.kdbx"));

m_dbFile2Multi.reset(new TemporaryFile());
m_dbFileMulti->copyFromFile(file.arg("NewDatabaseMulti.kdbx"));

m_xmlFile.reset(new TemporaryFile());
m_xmlFile->copyFromFile(file.arg("NewDatabase.xml"));

Expand Down Expand Up @@ -504,6 +507,19 @@ void TestCli::testClip()
setInput("a");
execCmd(clipCmd, {"clip", m_dbFile2->fileName(), "--attribute", "Username", "--totp", "/Sample Entry"});
QVERIFY(m_stderr->readAll().contains("ERROR: Please specify one of --attribute or --totp, not both.\n"));

// Best option
setInput("a");
execCmd(clipCmd, {"clip", m_dbFileMulti->fileName(), "/Multi", "-b"});
QCOMPARE(m_stdout->readAll(), QByteArray());
QVERIFY(clipCmd.name.isEmpty());
QVERIFY(m_stderr->readAll().contains("Multi Entry 1"));
QVERIFY(m_stderr->readAll().contains("Multi Entry 2"));

setInput("a");
execCmd(clipCmd, {"clip", m_dbFileMulti->fileName(), "/Entry 2", "-b"});
QCOMPARE(m_stderr->readAll(), QByteArray());
QTRY_COMPARE(clipboard->text(), QString("Password2"));
}

void TestCli::testCreate()
Expand Down
Binary file added tests/data/NewDatabaseMulti.kdbx
Binary file not shown.

0 comments on commit 09ec0b5

Please sign in to comment.