~dobey/keeper/cleanup

« back to all changes in this revision

Viewing changes to tests/dbusmock/keeper-template-test.cpp

  • Committer: Bileto Bot
  • Author(s): Charles Kerr, Xavi Garcia Mena, Xavi Garcia
  • Date: 2017-02-13 08:57:25 UTC
  • mfrom: (126.1.21 keeper-tests-charles)
  • Revision ID: ci-train-bot@canonical.com-20170213085725-rpsp9eg86dk2zlvi
Adds integration tests for restore and restore cancellation.

Approved by: Charles Kerr, unity-api-1-bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
// test that the dbusmock scaffolding starts up and exits ok
40
40
TEST_F(KeeperTemplateTest, HelloWorld)
41
41
{
 
42
    // avoid FAKE_BACKUP_HELPER_PAYLOAD from fake-backup-helper.h
 
43
    (void)FAKE_BACKUP_HELPER_PAYLOAD;
42
44
}
43
45
 
44
46
 
59
61
    EXPECT_NE(QDBusMessage::ErrorMessage, msg.type()) << qPrintable(msg.errorMessage());
60
62
 
61
63
    // ask for a list of backup choices
62
 
    QDBusReply<QVariantDictMap> choices = user_iface_->call("GetBackupChoices");
63
 
    EXPECT_TRUE(choices.isValid()) << qPrintable(choices.error().message());
64
 
 
65
 
    // check the results
66
 
    const auto expected_choices = QVariantDictMap{{uuid, props}};
67
 
    ASSERT_EQ(expected_choices, choices);
68
 
}
69
 
 
70
 
 
71
 
// test that StartBackup() fails if we pass an invalid arg
72
 
TEST_F(KeeperTemplateTest, StartBackupWithInvalidArg)
73
 
{
74
 
    const auto invalid_uuid = QUuid::createUuid().toString();
75
 
 
76
 
    QDBusReply<void> reply = user_iface_->call("StartBackup", QStringList{invalid_uuid});
77
 
    EXPECT_FALSE(reply.isValid());
78
 
    EXPECT_EQ(QDBusError::InvalidArgs, reply.error().type());
79
 
}
80
 
 
81
 
 
82
 
// test GetRestoreChoices() returns what we give to AddRestoreChoice()
83
 
TEST_F(KeeperTemplateTest, RestoreChoices)
84
 
{
85
 
    // build a restore choice
86
 
    const auto uuid = QUuid::createUuid().toString();
87
 
    const auto blob = QUuid::createUuid().toByteArray();
88
 
    const QMap<QString,QVariant> props {
89
 
        { KEY_NAME, QStringLiteral("some-name") },
90
 
        { KEY_TYPE, QStringLiteral("some-type") },
91
 
        { KEY_SUBTYPE, QStringLiteral("some-subtype") },
92
 
        { KEY_HELPER, QString::fromUtf8("/dev/null") },
93
 
        { KEY_SIZE, quint64(blob.size()) },
94
 
        { KEY_CTIME, quint64(time(nullptr)) },
95
 
        { KEY_BLOB, blob }
96
 
    };
97
 
 
98
 
    // add it
99
 
    auto msg = mock_iface_->call(QStringLiteral("AddRestoreChoice"), uuid, props);
100
 
    EXPECT_NE(QDBusMessage::ErrorMessage, msg.type()) << qPrintable(msg.errorMessage());
101
 
 
102
 
    // ask for a list of restore choices
103
 
    QDBusReply<QVariantDictMap> choices = user_iface_->call("GetRestoreChoices");
104
 
    EXPECT_TRUE(choices.isValid()) << qPrintable(choices.error().message());
105
 
 
106
 
    // check the results
107
 
    const auto expected_choices = QVariantDictMap{{uuid, props}};
108
 
    ASSERT_EQ(expected_choices, choices);
109
 
}
110
 
 
111
 
 
112
 
// test that StartRestore() fails if we pass an invalid arg
113
 
TEST_F(KeeperTemplateTest, StartRestoreWithInvalidArg)
114
 
{
115
 
    const auto invalid_uuid = QUuid::createUuid().toString();
116
 
 
117
 
    QDBusReply<void> reply = user_iface_->call("StartRestore", QStringList{invalid_uuid});
118
 
    EXPECT_FALSE(reply.isValid());
119
 
    EXPECT_EQ(QDBusError::InvalidArgs, reply.error().type());
120
 
}
121
 
 
122
 
 
123
 
// test that Status() returns empty if we haven't done anything yet
124
 
TEST_F(KeeperTemplateTest, TestEmptyStatus)
125
 
{
126
 
    EXPECT_TRUE(user_iface_->state().isEmpty());
127
 
}
128
 
 
129
 
 
130
 
/***
131
 
****  Make a real backup
132
 
***/
133
 
 
134
 
TEST_F(KeeperTemplateTest, BackupRun)
135
 
{
136
 
    QTemporaryDir sandbox;
137
 
 
138
 
    // build a backup choice
139
 
    const auto uuid = QUuid::createUuid().toString();
140
 
    const QMap<QString,QVariant> props {
141
 
        { KEY_NAME, QStringLiteral("Music") },
142
 
        { KEY_TYPE, QStringLiteral("folder") },
143
 
        { KEY_SUBTYPE, sandbox.path() },
144
 
        { KEY_HELPER, QString::fromUtf8(FAKE_BACKUP_HELPER_EXEC) }
145
 
    };
146
 
 
147
 
    // add it
148
 
    auto msg = mock_iface_->call(QStringLiteral("AddBackupChoice"), uuid, props);
149
 
    EXPECT_NE(QDBusMessage::ErrorMessage, msg.type()) << qPrintable(msg.errorMessage());
150
 
 
151
 
    // start the backup
152
 
    QDBusReply<void> reply = user_iface_->call("StartBackup", QStringList{uuid});
153
 
    EXPECT_TRUE(reply.isValid()) << qPrintable(reply.error().message());
154
 
    ASSERT_TRUE(wait_for_tasks_to_finish());
155
 
 
156
 
    // ask keeper for the blob
157
 
    QDBusReply<QByteArray> blob = mock_iface_->call(QStringLiteral("GetBackupData"), uuid);
158
 
    EXPECT_TRUE(reply.isValid()) << qPrintable(reply.error().message());
159
 
 
160
 
    // check the results
161
 
    const auto expected_blob = QByteArray(FAKE_BACKUP_HELPER_PAYLOAD);
162
 
    ASSERT_EQ(expected_blob, blob);
163
 
}
 
64
    QDBusPendingReply<keeper::Items> choices_reply = user_iface_->call("GetBackupChoices");
 
65
    choices_reply.waitForFinished();
 
66
    if (!choices_reply.isValid())
 
67
    {
 
68
        qDebug() << "-------------------" << choices_reply.error().message();
 
69
    }
 
70
    EXPECT_TRUE(choices_reply.isValid()) << qPrintable(choices_reply.error().message());
 
71
 
 
72
    auto choices = choices_reply.value();
 
73
    // check the results
 
74
    const auto expected_choices = QVariantDictMap{{uuid, props}};
 
75
    auto iter = choices.find(uuid);
 
76
    ASSERT_NE(iter, choices.end());
 
77
 
 
78
    ASSERT_EQ((*iter), props);
 
79
}
 
80
 
 
81
 
 
82
//// test that StartBackup() fails if we pass an invalid arg
 
83
//TEST_F(KeeperTemplateTest, StartBackupWithInvalidArg)
 
84
//{
 
85
//    const auto invalid_uuid = QUuid::createUuid().toString();
 
86
//
 
87
//    QDBusReply<void> reply = user_iface_->call("StartBackup", QStringList{invalid_uuid});
 
88
//    EXPECT_FALSE(reply.isValid());
 
89
//    EXPECT_EQ(QDBusError::InvalidArgs, reply.error().type());
 
90
//}
 
91
//
 
92
//
 
93
//// test GetRestoreChoices() returns what we give to AddRestoreChoice()
 
94
//TEST_F(KeeperTemplateTest, RestoreChoices)
 
95
//{
 
96
//    // build a restore choice
 
97
//    const auto uuid = QUuid::createUuid().toString();
 
98
//    const auto blob = QUuid::createUuid().toByteArray();
 
99
//    const QMap<QString,QVariant> props {
 
100
//        { KEY_NAME, QStringLiteral("some-name") },
 
101
//        { KEY_TYPE, QStringLiteral("some-type") },
 
102
//        { KEY_SUBTYPE, QStringLiteral("some-subtype") },
 
103
//        { KEY_HELPER, QString::fromUtf8("/dev/null") },
 
104
//        { KEY_SIZE, quint64(blob.size()) },
 
105
//        { KEY_CTIME, quint64(time(nullptr)) },
 
106
//        { KEY_BLOB, blob }
 
107
//    };
 
108
//
 
109
//    // add it
 
110
//    auto msg = mock_iface_->call(QStringLiteral("AddRestoreChoice"), uuid, props);
 
111
//    EXPECT_NE(QDBusMessage::ErrorMessage, msg.type()) << qPrintable(msg.errorMessage());
 
112
//
 
113
//    // ask for a list of restore choices
 
114
//    QDBusReply<QVariantDictMap> choices = user_iface_->call("GetRestoreChoices");
 
115
//    EXPECT_TRUE(choices.isValid()) << qPrintable(choices.error().message());
 
116
//
 
117
//    // check the results
 
118
//    const auto expected_choices = QVariantDictMap{{uuid, props}};
 
119
//    ASSERT_EQ(expected_choices, choices);
 
120
//}
 
121
//
 
122
//
 
123
//// test that StartRestore() fails if we pass an invalid arg
 
124
//TEST_F(KeeperTemplateTest, StartRestoreWithInvalidArg)
 
125
//{
 
126
//    const auto invalid_uuid = QUuid::createUuid().toString();
 
127
//
 
128
//    QDBusReply<void> reply = user_iface_->call("StartRestore", QStringList{invalid_uuid});
 
129
//    EXPECT_FALSE(reply.isValid());
 
130
//    EXPECT_EQ(QDBusError::InvalidArgs, reply.error().type());
 
131
//}
 
132
//
 
133
//
 
134
//// test that Status() returns empty if we haven't done anything yet
 
135
//TEST_F(KeeperTemplateTest, TestEmptyStatus)
 
136
//{
 
137
//    EXPECT_TRUE(user_iface_->state().isEmpty());
 
138
//}
 
139
//
 
140
//
 
141
///***
 
142
//****  Make a real backup
 
143
//***/
 
144
//
 
145
//TEST_F(KeeperTemplateTest, BackupRun)
 
146
//{
 
147
//    QTemporaryDir sandbox;
 
148
//
 
149
//    // build a backup choice
 
150
//    const auto uuid = QUuid::createUuid().toString();
 
151
//    const QMap<QString,QVariant> props {
 
152
//        { KEY_NAME, QStringLiteral("Music") },
 
153
//        { KEY_TYPE, QStringLiteral("folder") },
 
154
//        { KEY_SUBTYPE, sandbox.path() },
 
155
//        { KEY_HELPER, QString::fromUtf8(FAKE_BACKUP_HELPER_EXEC) }
 
156
//    };
 
157
//
 
158
//    // add it
 
159
//    auto msg = mock_iface_->call(QStringLiteral("AddBackupChoice"), uuid, props);
 
160
//    EXPECT_NE(QDBusMessage::ErrorMessage, msg.type()) << qPrintable(msg.errorMessage());
 
161
//
 
162
//    // start the backup
 
163
//    QDBusReply<void> reply = user_iface_->call("StartBackup", QStringList{uuid});
 
164
//    EXPECT_TRUE(reply.isValid()) << qPrintable(reply.error().message());
 
165
//    ASSERT_TRUE(wait_for_tasks_to_finish());
 
166
//
 
167
//    // ask keeper for the blob
 
168
//    QDBusReply<QByteArray> blob = mock_iface_->call(QStringLiteral("GetBackupData"), uuid);
 
169
//    EXPECT_TRUE(reply.isValid()) << qPrintable(reply.error().message());
 
170
//
 
171
//    // check the results
 
172
//    const auto expected_blob = QByteArray(FAKE_BACKUP_HELPER_PAYLOAD);
 
173
//    ASSERT_EQ(expected_blob, blob);
 
174
//}