comparison tests/test-db.c @ 9:3ef8128e244f

sci: add project-update command
author David Demelier <markand@malikania.fr>
date Wed, 23 Jun 2021 14:05:36 +0200
parents 566bc028cdcb
children 081e1c258e64
comparison
equal deleted inserted replaced
8:ec800a5fb7e3 9:3ef8128e244f
181 db_ctx_finish(&ctx); 181 db_ctx_finish(&ctx);
182 182
183 GREATEST_PASS(); 183 GREATEST_PASS();
184 } 184 }
185 185
186 GREATEST_TEST
187 test_projects_update(void)
188 {
189 struct project proj = {
190 .name = "example 1",
191 .desc = "Example project 1",
192 .url = "example.org",
193 .script = "#!/bin/sh exit 0"
194 };
195 struct project find;
196 struct db_ctx ctx;
197
198 GREATEST_ASSERT_EQ(db_project_add(&proj), 0);
199 GREATEST_ASSERT(proj.id > 0);
200
201 /* Update name. */
202 memset(&find, 0, sizeof (find));
203 find.id = 1;
204 proj.name = "updated example 1";
205
206 GREATEST_ASSERT_EQ(db_project_update(&proj), 0);
207 GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0);
208 GREATEST_ASSERT_STR_EQ(find.name, "updated example 1");
209 GREATEST_ASSERT_STR_EQ(find.desc, "Example project 1");
210 GREATEST_ASSERT_STR_EQ(find.url, "example.org");
211 GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 0");
212
213 db_ctx_finish(&ctx);
214
215 /* Update desc. */
216 memset(&find, 0, sizeof (find));
217 find.id = 1;
218 proj.desc = "updated Example project 1";
219
220 GREATEST_ASSERT_EQ(db_project_update(&proj), 0);
221 GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0);
222 GREATEST_ASSERT_STR_EQ(find.name, "updated example 1");
223 GREATEST_ASSERT_STR_EQ(find.desc, "updated Example project 1");
224 GREATEST_ASSERT_STR_EQ(find.url, "example.org");
225 GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 0");
226
227 db_ctx_finish(&ctx);
228
229 /* Update url. */
230 memset(&find, 0, sizeof (find));
231 find.id = 1;
232 proj.url = "updated example.org";
233
234 GREATEST_ASSERT_EQ(db_project_update(&proj), 0);
235 GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0);
236 GREATEST_ASSERT_STR_EQ(find.name, "updated example 1");
237 GREATEST_ASSERT_STR_EQ(find.desc, "updated Example project 1");
238 GREATEST_ASSERT_STR_EQ(find.url, "updated example.org");
239 GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 0");
240
241 db_ctx_finish(&ctx);
242
243 /* Update script. */
244 memset(&find, 0, sizeof (find));
245 find.id = 1;
246 proj.script = "#!/bin/sh exit 1";
247
248 GREATEST_ASSERT_EQ(db_project_update(&proj), 0);
249 GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0);
250 GREATEST_ASSERT_STR_EQ(find.name, "updated example 1");
251 GREATEST_ASSERT_STR_EQ(find.desc, "updated Example project 1");
252 GREATEST_ASSERT_STR_EQ(find.url, "updated example.org");
253 GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 1");
254
255 db_ctx_finish(&ctx);
256
257 GREATEST_PASS();
258 }
259
186 GREATEST_SUITE(suite_projects) 260 GREATEST_SUITE(suite_projects)
187 { 261 {
188 GREATEST_SET_SETUP_CB(setup, NULL); 262 GREATEST_SET_SETUP_CB(setup, NULL);
189 GREATEST_SET_TEARDOWN_CB(teardown, NULL); 263 GREATEST_SET_TEARDOWN_CB(teardown, NULL);
190 GREATEST_RUN_TEST(test_projects_add); 264 GREATEST_RUN_TEST(test_projects_add);
191 GREATEST_RUN_TEST(test_projects_list); 265 GREATEST_RUN_TEST(test_projects_list);
192 GREATEST_RUN_TEST(test_projects_find); 266 GREATEST_RUN_TEST(test_projects_find);
193 GREATEST_RUN_TEST(test_projects_find_id); 267 GREATEST_RUN_TEST(test_projects_find_id);
268 GREATEST_RUN_TEST(test_projects_update);
194 } 269 }
195 270
196 GREATEST_TEST 271 GREATEST_TEST
197 test_workers_add(void) 272 test_workers_add(void)
198 { 273 {
382 GREATEST_SET_SETUP_CB(setup, NULL); 457 GREATEST_SET_SETUP_CB(setup, NULL);
383 GREATEST_SET_TEARDOWN_CB(teardown, NULL); 458 GREATEST_SET_TEARDOWN_CB(teardown, NULL);
384 GREATEST_RUN_TEST(test_jobs_add); 459 GREATEST_RUN_TEST(test_jobs_add);
385 GREATEST_RUN_TEST(test_jobs_todo); 460 GREATEST_RUN_TEST(test_jobs_todo);
386 } 461 }
387
388 462
389 GREATEST_TEST 463 GREATEST_TEST
390 test_jobresults_add(void) 464 test_jobresults_add(void)
391 { 465 {
392 struct project projs[] = { 466 struct project projs[] = {