Mercurial > sci
diff 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 |
line wrap: on
line diff
--- a/tests/test-db.c Wed Jun 23 11:45:07 2021 +0200 +++ b/tests/test-db.c Wed Jun 23 14:05:36 2021 +0200 @@ -183,6 +183,80 @@ GREATEST_PASS(); } +GREATEST_TEST +test_projects_update(void) +{ + struct project proj = { + .name = "example 1", + .desc = "Example project 1", + .url = "example.org", + .script = "#!/bin/sh exit 0" + }; + struct project find; + struct db_ctx ctx; + + GREATEST_ASSERT_EQ(db_project_add(&proj), 0); + GREATEST_ASSERT(proj.id > 0); + + /* Update name. */ + memset(&find, 0, sizeof (find)); + find.id = 1; + proj.name = "updated example 1"; + + GREATEST_ASSERT_EQ(db_project_update(&proj), 0); + GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0); + GREATEST_ASSERT_STR_EQ(find.name, "updated example 1"); + GREATEST_ASSERT_STR_EQ(find.desc, "Example project 1"); + GREATEST_ASSERT_STR_EQ(find.url, "example.org"); + GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 0"); + + db_ctx_finish(&ctx); + + /* Update desc. */ + memset(&find, 0, sizeof (find)); + find.id = 1; + proj.desc = "updated Example project 1"; + + GREATEST_ASSERT_EQ(db_project_update(&proj), 0); + GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0); + GREATEST_ASSERT_STR_EQ(find.name, "updated example 1"); + GREATEST_ASSERT_STR_EQ(find.desc, "updated Example project 1"); + GREATEST_ASSERT_STR_EQ(find.url, "example.org"); + GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 0"); + + db_ctx_finish(&ctx); + + /* Update url. */ + memset(&find, 0, sizeof (find)); + find.id = 1; + proj.url = "updated example.org"; + + GREATEST_ASSERT_EQ(db_project_update(&proj), 0); + GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0); + GREATEST_ASSERT_STR_EQ(find.name, "updated example 1"); + GREATEST_ASSERT_STR_EQ(find.desc, "updated Example project 1"); + GREATEST_ASSERT_STR_EQ(find.url, "updated example.org"); + GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 0"); + + db_ctx_finish(&ctx); + + /* Update script. */ + memset(&find, 0, sizeof (find)); + find.id = 1; + proj.script = "#!/bin/sh exit 1"; + + GREATEST_ASSERT_EQ(db_project_update(&proj), 0); + GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0); + GREATEST_ASSERT_STR_EQ(find.name, "updated example 1"); + GREATEST_ASSERT_STR_EQ(find.desc, "updated Example project 1"); + GREATEST_ASSERT_STR_EQ(find.url, "updated example.org"); + GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 1"); + + db_ctx_finish(&ctx); + + GREATEST_PASS(); +} + GREATEST_SUITE(suite_projects) { GREATEST_SET_SETUP_CB(setup, NULL); @@ -191,6 +265,7 @@ GREATEST_RUN_TEST(test_projects_list); GREATEST_RUN_TEST(test_projects_find); GREATEST_RUN_TEST(test_projects_find_id); + GREATEST_RUN_TEST(test_projects_update); } GREATEST_TEST @@ -385,7 +460,6 @@ GREATEST_RUN_TEST(test_jobs_todo); } - GREATEST_TEST test_jobresults_add(void) {