Mercurial > sci
annotate tests/test-db.c @ 37:62aefd02ac59
make: remove config.mk
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 07 Aug 2022 08:41:06 +0200 |
parents | 081e1c258e64 |
children |
rev | line source |
---|---|
5
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
1 /* |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
2 * test-db.c -- test database access |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
3 * |
32
081e1c258e64
misc: update copyright years
David Demelier <markand@malikania.fr>
parents:
9
diff
changeset
|
4 * Copyright (c) 2021-2022 David Demelier <markand@malikania.fr> |
5
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
5 * |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
6 * Permission to use, copy, modify, and/or distribute this software for any |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
7 * purpose with or without fee is hereby granted, provided that the above |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
8 * copyright notice and this permission notice appear in all copies. |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
9 * |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
17 */ |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
18 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
19 #include <stdio.h> |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
20 #include <string.h> |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
21 #include <err.h> |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
22 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
23 #define GREATEST_USE_ABBREVS 0 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
24 #include <greatest.h> |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
25 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
26 #include "db.h" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
27 #include "types.h" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
28 #include "util.h" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
29 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
30 #define DB "test.db" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
31 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
32 static void |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
33 setup(void *data) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
34 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
35 (void)data; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
36 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
37 remove(DB); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
38 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
39 if (db_open(DB) < 0) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
40 err(1, "unable to create database"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
41 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
42 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
43 static void |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
44 teardown(void *data) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
45 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
46 (void)data; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
47 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
48 db_finish(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
49 remove(DB); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
50 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
51 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
52 GREATEST_TEST |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
53 test_projects_add(void) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
54 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
55 struct project proj = {0}; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
56 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
57 proj.name = "test"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
58 proj.desc = "Test project"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
59 proj.url = "example.org"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
60 proj.script = "#!/bin/sh exit 0"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
61 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
62 GREATEST_ASSERT_EQ(db_project_add(&proj), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
63 GREATEST_ASSERT(proj.id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
64 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
65 GREATEST_PASS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
66 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
67 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
68 GREATEST_TEST |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
69 test_projects_list(void) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
70 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
71 struct project projs[] = { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
72 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
73 .name = "example 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
74 .desc = "Example project 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
75 .url = "example.org", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
76 .script = "#!/bin/sh exit 0" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
77 }, |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
78 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
79 .name = "example 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
80 .desc = "Example project 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
81 .url = "example.org", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
82 .script = "#!/bin/sh exit 0" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
83 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
84 }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
85 struct db_ctx ctx; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
86 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
87 for (size_t i = 0; i < UTIL_SIZE(projs); ++i) { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
88 GREATEST_ASSERT_EQ(db_project_add(&projs[i]), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
89 GREATEST_ASSERT(projs[i].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
90 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
91 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
92 memset(projs, 0, sizeof (projs)); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
93 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
94 GREATEST_ASSERT_EQ(db_project_list(&ctx, projs, UTIL_SIZE(projs)), 2LL); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
95 GREATEST_ASSERT(projs[0].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
96 GREATEST_ASSERT_STR_EQ(projs[0].name, "example 1"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
97 GREATEST_ASSERT_STR_EQ(projs[0].desc, "Example project 1"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
98 GREATEST_ASSERT_STR_EQ(projs[0].url, "example.org"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
99 GREATEST_ASSERT_STR_EQ(projs[0].script, "#!/bin/sh exit 0"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
100 GREATEST_ASSERT(projs[1].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
101 GREATEST_ASSERT_STR_EQ(projs[1].name, "example 2"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
102 GREATEST_ASSERT_STR_EQ(projs[1].desc, "Example project 2"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
103 GREATEST_ASSERT_STR_EQ(projs[1].url, "example.org"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
104 GREATEST_ASSERT_STR_EQ(projs[1].script, "#!/bin/sh exit 0"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
105 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
106 db_ctx_finish(&ctx); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
107 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
108 GREATEST_PASS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
109 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
110 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
111 GREATEST_TEST |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
112 test_projects_find(void) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
113 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
114 struct project projs[] = { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
115 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
116 .name = "example 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
117 .desc = "Example project 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
118 .url = "example.org", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
119 .script = "#!/bin/sh exit 0" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
120 }, |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
121 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
122 .name = "example 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
123 .desc = "Example project 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
124 .url = "example.org", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
125 .script = "#!/bin/sh exit 0" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
126 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
127 }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
128 struct project find = { .name = "example 2" }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
129 struct db_ctx ctx; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
130 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
131 for (size_t i = 0; i < UTIL_SIZE(projs); ++i) { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
132 GREATEST_ASSERT_EQ(db_project_add(&projs[i]), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
133 GREATEST_ASSERT(projs[i].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
134 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
135 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
136 GREATEST_ASSERT_EQ(db_project_find(&ctx, &find), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
137 GREATEST_ASSERT_EQ(find.id, 2); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
138 GREATEST_ASSERT_STR_EQ(find.name, "example 2"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
139 GREATEST_ASSERT_STR_EQ(find.desc, "Example project 2"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
140 GREATEST_ASSERT_STR_EQ(find.url, "example.org"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
141 GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 0"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
142 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
143 db_ctx_finish(&ctx); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
144 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
145 GREATEST_PASS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
146 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
147 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
148 GREATEST_TEST |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
149 test_projects_find_id(void) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
150 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
151 struct project projs[] = { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
152 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
153 .name = "example 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
154 .desc = "Example project 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
155 .url = "example.org", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
156 .script = "#!/bin/sh exit 0" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
157 }, |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
158 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
159 .name = "example 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
160 .desc = "Example project 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
161 .url = "example.org", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
162 .script = "#!/bin/sh exit 0" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
163 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
164 }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
165 struct project find = { .id = 2 }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
166 struct db_ctx ctx; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
167 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
168 for (size_t i = 0; i < UTIL_SIZE(projs); ++i) { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
169 GREATEST_ASSERT_EQ(db_project_add(&projs[i]), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
170 GREATEST_ASSERT(projs[i].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
171 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
172 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
173 /* First generated id should start at 1. */ |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
174 GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
175 GREATEST_ASSERT_EQ(find.id, 2); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
176 GREATEST_ASSERT_STR_EQ(find.name, "example 2"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
177 GREATEST_ASSERT_STR_EQ(find.desc, "Example project 2"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
178 GREATEST_ASSERT_STR_EQ(find.url, "example.org"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
179 GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 0"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
180 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
181 db_ctx_finish(&ctx); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
182 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
183 GREATEST_PASS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
184 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
185 |
9
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
186 GREATEST_TEST |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
187 test_projects_update(void) |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
188 { |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
189 struct project proj = { |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
190 .name = "example 1", |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
191 .desc = "Example project 1", |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
192 .url = "example.org", |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
193 .script = "#!/bin/sh exit 0" |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
194 }; |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
195 struct project find; |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
196 struct db_ctx ctx; |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
197 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
198 GREATEST_ASSERT_EQ(db_project_add(&proj), 0); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
199 GREATEST_ASSERT(proj.id > 0); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
200 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
201 /* Update name. */ |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
202 memset(&find, 0, sizeof (find)); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
203 find.id = 1; |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
204 proj.name = "updated example 1"; |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
205 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
206 GREATEST_ASSERT_EQ(db_project_update(&proj), 0); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
207 GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
208 GREATEST_ASSERT_STR_EQ(find.name, "updated example 1"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
209 GREATEST_ASSERT_STR_EQ(find.desc, "Example project 1"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
210 GREATEST_ASSERT_STR_EQ(find.url, "example.org"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
211 GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 0"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
212 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
213 db_ctx_finish(&ctx); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
214 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
215 /* Update desc. */ |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
216 memset(&find, 0, sizeof (find)); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
217 find.id = 1; |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
218 proj.desc = "updated Example project 1"; |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
219 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
220 GREATEST_ASSERT_EQ(db_project_update(&proj), 0); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
221 GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
222 GREATEST_ASSERT_STR_EQ(find.name, "updated example 1"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
223 GREATEST_ASSERT_STR_EQ(find.desc, "updated Example project 1"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
224 GREATEST_ASSERT_STR_EQ(find.url, "example.org"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
225 GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 0"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
226 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
227 db_ctx_finish(&ctx); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
228 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
229 /* Update url. */ |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
230 memset(&find, 0, sizeof (find)); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
231 find.id = 1; |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
232 proj.url = "updated example.org"; |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
233 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
234 GREATEST_ASSERT_EQ(db_project_update(&proj), 0); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
235 GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
236 GREATEST_ASSERT_STR_EQ(find.name, "updated example 1"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
237 GREATEST_ASSERT_STR_EQ(find.desc, "updated Example project 1"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
238 GREATEST_ASSERT_STR_EQ(find.url, "updated example.org"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
239 GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 0"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
240 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
241 db_ctx_finish(&ctx); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
242 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
243 /* Update script. */ |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
244 memset(&find, 0, sizeof (find)); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
245 find.id = 1; |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
246 proj.script = "#!/bin/sh exit 1"; |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
247 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
248 GREATEST_ASSERT_EQ(db_project_update(&proj), 0); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
249 GREATEST_ASSERT_EQ(db_project_find_id(&ctx, &find), 0); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
250 GREATEST_ASSERT_STR_EQ(find.name, "updated example 1"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
251 GREATEST_ASSERT_STR_EQ(find.desc, "updated Example project 1"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
252 GREATEST_ASSERT_STR_EQ(find.url, "updated example.org"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
253 GREATEST_ASSERT_STR_EQ(find.script, "#!/bin/sh exit 1"); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
254 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
255 db_ctx_finish(&ctx); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
256 |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
257 GREATEST_PASS(); |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
258 } |
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
259 |
5
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
260 GREATEST_SUITE(suite_projects) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
261 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
262 GREATEST_SET_SETUP_CB(setup, NULL); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
263 GREATEST_SET_TEARDOWN_CB(teardown, NULL); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
264 GREATEST_RUN_TEST(test_projects_add); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
265 GREATEST_RUN_TEST(test_projects_list); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
266 GREATEST_RUN_TEST(test_projects_find); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
267 GREATEST_RUN_TEST(test_projects_find_id); |
9
3ef8128e244f
sci: add project-update command
David Demelier <markand@malikania.fr>
parents:
5
diff
changeset
|
268 GREATEST_RUN_TEST(test_projects_update); |
5
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
269 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
270 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
271 GREATEST_TEST |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
272 test_workers_add(void) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
273 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
274 struct worker wk = {0}; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
275 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
276 wk.name = "test"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
277 wk.desc = "Test worker"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
278 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
279 GREATEST_ASSERT_EQ(db_worker_add(&wk), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
280 GREATEST_ASSERT(wk.id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
281 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
282 GREATEST_PASS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
283 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
284 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
285 GREATEST_TEST |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
286 test_workers_list(void) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
287 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
288 struct worker wks[] = { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
289 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
290 .name = "example 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
291 .desc = "Example worker 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
292 }, |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
293 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
294 .name = "example 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
295 .desc = "Example worker 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
296 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
297 }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
298 struct db_ctx ctx; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
299 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
300 for (size_t i = 0; i < UTIL_SIZE(wks); ++i) { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
301 GREATEST_ASSERT_EQ(db_worker_add(&wks[i]), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
302 GREATEST_ASSERT(wks[i].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
303 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
304 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
305 memset(wks, 0, sizeof (wks)); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
306 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
307 GREATEST_ASSERT_EQ(db_worker_list(&ctx, wks, UTIL_SIZE(wks)), 2LL); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
308 GREATEST_ASSERT(wks[0].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
309 GREATEST_ASSERT_STR_EQ(wks[0].name, "example 1"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
310 GREATEST_ASSERT_STR_EQ(wks[0].desc, "Example worker 1"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
311 GREATEST_ASSERT(wks[1].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
312 GREATEST_ASSERT_STR_EQ(wks[1].name, "example 2"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
313 GREATEST_ASSERT_STR_EQ(wks[1].desc, "Example worker 2"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
314 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
315 db_ctx_finish(&ctx); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
316 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
317 GREATEST_PASS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
318 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
319 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
320 GREATEST_TEST |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
321 test_workers_find(void) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
322 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
323 struct worker wks[] = { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
324 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
325 .name = "example 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
326 .desc = "Example worker 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
327 }, |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
328 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
329 .name = "example 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
330 .desc = "Example worker 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
331 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
332 }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
333 struct worker find = { .name = "example 1" }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
334 struct db_ctx ctx; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
335 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
336 for (size_t i = 0; i < UTIL_SIZE(wks); ++i) { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
337 GREATEST_ASSERT_EQ(db_worker_add(&wks[i]), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
338 GREATEST_ASSERT(wks[i].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
339 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
340 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
341 GREATEST_ASSERT_EQ(db_worker_find(&ctx, &find), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
342 GREATEST_ASSERT_EQ(find.id, 1); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
343 GREATEST_ASSERT_STR_EQ(find.name, "example 1"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
344 GREATEST_ASSERT_STR_EQ(find.desc, "Example worker 1"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
345 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
346 db_ctx_finish(&ctx); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
347 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
348 GREATEST_PASS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
349 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
350 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
351 GREATEST_TEST |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
352 test_workers_find_id(void) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
353 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
354 struct worker wks[] = { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
355 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
356 .name = "example 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
357 .desc = "Example worker 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
358 }, |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
359 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
360 .name = "example 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
361 .desc = "Example worker 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
362 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
363 }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
364 struct worker find = { .id = 1 }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
365 struct db_ctx ctx; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
366 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
367 for (size_t i = 0; i < UTIL_SIZE(wks); ++i) { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
368 GREATEST_ASSERT_EQ(db_worker_add(&wks[i]), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
369 GREATEST_ASSERT(wks[i].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
370 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
371 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
372 /* First generated id should start at 1. */ |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
373 GREATEST_ASSERT_EQ(db_worker_find_id(&ctx, &find), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
374 GREATEST_ASSERT_EQ(find.id, 1); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
375 GREATEST_ASSERT_STR_EQ(find.name, "example 1"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
376 GREATEST_ASSERT_STR_EQ(find.desc, "Example worker 1"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
377 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
378 db_ctx_finish(&ctx); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
379 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
380 GREATEST_PASS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
381 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
382 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
383 GREATEST_SUITE(suite_workers) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
384 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
385 GREATEST_SET_SETUP_CB(setup, NULL); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
386 GREATEST_SET_TEARDOWN_CB(teardown, NULL); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
387 GREATEST_RUN_TEST(test_workers_add); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
388 GREATEST_RUN_TEST(test_workers_list); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
389 GREATEST_RUN_TEST(test_workers_find); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
390 GREATEST_RUN_TEST(test_workers_find_id); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
391 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
392 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
393 GREATEST_TEST |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
394 test_jobs_add(void) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
395 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
396 struct project proj = {0}; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
397 struct job job = {0}; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
398 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
399 proj.name = "test"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
400 proj.desc = "Test project"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
401 proj.url = "example.org"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
402 proj.script = "#!/bin/sh exit 0"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
403 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
404 GREATEST_ASSERT_EQ(db_project_add(&proj), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
405 GREATEST_ASSERT(proj.id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
406 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
407 job.project_id = proj.id; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
408 job.tag = "123456"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
409 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
410 GREATEST_ASSERT_EQ(db_job_add(&job), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
411 GREATEST_ASSERT(job.id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
412 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
413 GREATEST_PASS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
414 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
415 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
416 GREATEST_TEST |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
417 test_jobs_todo(void) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
418 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
419 struct project proj = {0}; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
420 struct job job = {0}; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
421 struct worker wk = {0}; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
422 struct job todo[16] = {0}; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
423 struct db_ctx ctx; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
424 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
425 proj.name = "test"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
426 proj.desc = "Test project"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
427 proj.url = "example.org"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
428 proj.script = "#!/bin/sh exit 0"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
429 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
430 GREATEST_ASSERT_EQ(db_project_add(&proj), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
431 GREATEST_ASSERT(proj.id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
432 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
433 job.project_id = proj.id; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
434 job.tag = "123456"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
435 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
436 GREATEST_ASSERT_EQ(db_job_add(&job), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
437 GREATEST_ASSERT(job.id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
438 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
439 wk.name = "test"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
440 wk.desc = "Test worker"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
441 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
442 GREATEST_ASSERT_EQ(db_worker_add(&wk), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
443 GREATEST_ASSERT(wk.id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
444 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
445 GREATEST_ASSERT_EQ(db_job_todo(&ctx, todo, UTIL_SIZE(todo), wk.id), 1); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
446 GREATEST_ASSERT(todo[0].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
447 GREATEST_ASSERT_STR_EQ(todo[0].tag, "123456"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
448 GREATEST_ASSERT_EQ(todo[0].project_id, proj.id); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
449 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
450 db_ctx_finish(&ctx); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
451 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
452 GREATEST_PASS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
453 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
454 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
455 GREATEST_SUITE(suite_jobs) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
456 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
457 GREATEST_SET_SETUP_CB(setup, NULL); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
458 GREATEST_SET_TEARDOWN_CB(teardown, NULL); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
459 GREATEST_RUN_TEST(test_jobs_add); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
460 GREATEST_RUN_TEST(test_jobs_todo); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
461 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
462 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
463 GREATEST_TEST |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
464 test_jobresults_add(void) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
465 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
466 struct project projs[] = { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
467 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
468 .name = "example 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
469 .desc = "Example project 1", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
470 .url = "example.org", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
471 .script = "#!/bin/sh exit 0" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
472 }, |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
473 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
474 .name = "example 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
475 .desc = "Example project 2", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
476 .url = "example.org", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
477 .script = "#!/bin/sh exit 0" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
478 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
479 }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
480 struct job jobs[] = { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
481 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
482 .project_id = 0, /* will be project 1 */ |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
483 .tag = "123456" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
484 }, |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
485 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
486 .project_id = 0, /* will be project 2 */ |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
487 .tag = "abcdef" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
488 }, |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
489 }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
490 struct worker wks[] = { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
491 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
492 .name = "alpine-aarch64", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
493 .desc = "alpine-aarch64" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
494 }, |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
495 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
496 .name = "alpine-armhf", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
497 .desc = "alpine-armhf" |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
498 }, |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
499 }; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
500 struct job todo[16] = {0}; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
501 struct jobresult res = {0}; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
502 struct db_ctx ctx; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
503 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
504 for (size_t i = 0; i < UTIL_SIZE(projs); ++i) { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
505 GREATEST_ASSERT_EQ(db_project_add(&projs[i]), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
506 GREATEST_ASSERT(projs[i].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
507 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
508 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
509 /* Update jobs with newly created projects. */ |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
510 jobs[0].project_id = projs[0].id; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
511 jobs[1].project_id = projs[1].id; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
512 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
513 for (size_t i = 0; i < UTIL_SIZE(jobs); ++i) { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
514 GREATEST_ASSERT_EQ(db_job_add(&jobs[i]), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
515 GREATEST_ASSERT(jobs[i].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
516 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
517 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
518 for (size_t i = 0; i < UTIL_SIZE(wks); ++i) { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
519 GREATEST_ASSERT_EQ(db_worker_add(&wks[i]), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
520 GREATEST_ASSERT(wks[i].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
521 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
522 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
523 /* |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
524 * Now add a jobresult for worker alpine-aarch64 and the job "abcdef", |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
525 * this means that this worker will only have the job "123456" to do |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
526 * while the other worker will have all to do. |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
527 */ |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
528 res.job_id = jobs[1].id; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
529 res.worker_id = wks[0].id; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
530 res.exitcode = 0; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
531 res.log = "Success"; |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
532 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
533 GREATEST_ASSERT_EQ(db_jobresult_add(&res), 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
534 GREATEST_ASSERT(res.id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
535 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
536 /* 1 job left for alpine-aarch64 -> [123456]. */ |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
537 GREATEST_ASSERT_EQ(db_job_todo(&ctx, todo, UTIL_SIZE(todo), wks[0].id), 1); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
538 GREATEST_ASSERT(todo[0].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
539 GREATEST_ASSERT_STR_EQ(todo[0].tag, "123456"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
540 GREATEST_ASSERT_EQ(todo[0].project_id, projs[0].id); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
541 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
542 db_ctx_finish(&ctx); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
543 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
544 /* 2 jobs left for alpine-armhf -> [123456, abcdef]. */ |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
545 GREATEST_ASSERT_EQ(db_job_todo(&ctx, todo, UTIL_SIZE(todo), wks[1].id), 2); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
546 GREATEST_ASSERT(todo[0].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
547 GREATEST_ASSERT_STR_EQ(todo[0].tag, "123456"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
548 GREATEST_ASSERT_EQ(todo[0].project_id, projs[0].id); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
549 GREATEST_ASSERT(todo[1].id > 0); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
550 GREATEST_ASSERT_STR_EQ(todo[1].tag, "abcdef"); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
551 GREATEST_ASSERT_EQ(todo[1].project_id, projs[1].id); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
552 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
553 db_ctx_finish(&ctx); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
554 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
555 GREATEST_PASS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
556 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
557 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
558 GREATEST_SUITE(suite_jobresults) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
559 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
560 GREATEST_SET_SETUP_CB(setup, NULL); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
561 GREATEST_SET_TEARDOWN_CB(teardown, NULL); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
562 GREATEST_RUN_TEST(test_jobresults_add); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
563 } |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
564 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
565 GREATEST_MAIN_DEFS(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
566 |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
567 int |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
568 main(int argc, char **argv) |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
569 { |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
570 GREATEST_MAIN_BEGIN(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
571 GREATEST_RUN_SUITE(suite_projects); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
572 GREATEST_RUN_SUITE(suite_workers); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
573 GREATEST_RUN_SUITE(suite_jobs); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
574 GREATEST_RUN_SUITE(suite_jobresults); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
575 GREATEST_MAIN_END(); |
566bc028cdcb
tests: initial tests coming
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
576 } |