2 * Copyright (C) 2016 J. Ali Harlow <ali@juiblex.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <plover/plover.h>
25 LUALIB_API int luaopen_posix(lua_State *L);
27 static void test_install(void)
29 char *pkgs[]={"zip",NULL};
30 gchar *root,*root_uri;
33 root=g_strdup("razor-test-dir-XXXXXX");
34 g_assert(mkdtemp(root));
35 file=g_file_new_for_path(root);
36 root_uri=g_file_get_uri(file);
38 g_setenv("RAZOR_ROOT",root_uri,TRUE);
40 if (!plover_install("../yum-repo-test-dir","/test",pkgs,&err))
42 g_assert(err && err->message);
43 g_error("test-install: %s",err->message);
46 g_unsetenv("RAZOR_ROOT");
50 static void test_install_bad_rpm(void)
52 gboolean installed_bad_rpm;
53 char *pkgs[]={"zip",NULL};
56 root=g_strdup("razor-test-dir-XXXXXX");
57 g_assert(mkdtemp(root));
58 g_setenv("RAZOR_ROOT",root,TRUE);
59 chmod("../yum-repo-test-dir/rpms/zip-1-1.noarch.rpm",0);
60 installed_bad_rpm=plover_install("../yum-repo-test-dir","/test",pkgs,&err);
61 chmod("../yum-repo-test-dir/rpms/zip-1-1.noarch.rpm",0666);
62 g_assert(!installed_bad_rpm);
63 g_assert(err && err->message);
64 g_unsetenv("RAZOR_ROOT");
68 static void test_update_noop(void)
70 gchar *root,*root_uri;
73 root=g_strdup("razor-test-dir-XXXXXX");
74 g_assert(mkdtemp(root));
75 file=g_file_new_for_path(root);
76 root_uri=g_file_get_uri(file);
78 g_setenv("RAZOR_ROOT",root_uri,TRUE);
80 if (!plover_update("../yum-repo-test-dir","/test",NULL,&err))
82 g_assert(err && err->message);
83 g_error("test-update-noop: %s",err->message);
86 g_unsetenv("RAZOR_ROOT");
90 static void test_update_nonexistant(void)
92 char *pkgs[]={"nonexistant",NULL};
93 gchar *root,*root_uri;
96 root=g_strdup("razor-test-dir-XXXXXX");
97 g_assert(mkdtemp(root));
98 file=g_file_new_for_path(root);
99 root_uri=g_file_get_uri(file);
100 g_object_unref(file);
101 g_setenv("RAZOR_ROOT",root_uri,TRUE);
103 g_assert(!plover_update("../yum-repo-test-dir","/test",pkgs,&err));
104 g_assert(g_error_matches(err,PLOVER_GENERAL_ERROR,
105 PLOVER_GENERAL_ERROR_NO_SUCH_PACKAGE));
107 g_unsetenv("RAZOR_ROOT");
111 static void test_remove(void)
113 char *pkgs[]={"zip",NULL};
114 gchar *root,*root_uri;
117 root=g_strdup("razor-test-dir-XXXXXX");
118 g_assert(mkdtemp(root));
119 file=g_file_new_for_path(root);
120 root_uri=g_file_get_uri(file);
121 g_object_unref(file);
122 g_setenv("RAZOR_ROOT",root_uri,TRUE);
124 if (!plover_install("../yum-repo-test-dir","/test",pkgs,&err))
125 g_error("test-remove: %s",err->message);
126 if (!plover_remove(pkgs,&err))
128 g_assert(err && err->message);
129 g_error("test-remove: %s",err->message);
132 g_unsetenv("RAZOR_ROOT");
136 static void test_remove_noop(void)
138 gchar *root,*root_uri;
141 root=g_strdup("razor-test-dir-XXXXXX");
142 g_assert(mkdtemp(root));
143 file=g_file_new_for_path(root);
144 root_uri=g_file_get_uri(file);
145 g_object_unref(file);
146 g_setenv("RAZOR_ROOT",root_uri,TRUE);
148 if (!plover_remove(NULL,&err))
150 g_assert(err && err->message);
151 g_error("test-remove-noop: %s",err->message);
154 g_unsetenv("RAZOR_ROOT");
158 static void test_remove_nonexistant(void)
160 char *pkgs[]={"nonexistant",NULL};
161 gchar *root,*root_uri;
164 root=g_strdup("razor-test-dir-XXXXXX");
165 g_assert(mkdtemp(root));
166 file=g_file_new_for_path(root);
167 root_uri=g_file_get_uri(file);
168 g_object_unref(file);
169 g_setenv("RAZOR_ROOT",root_uri,TRUE);
171 g_assert(!plover_remove(pkgs,&err));
172 g_assert(g_error_matches(err,PLOVER_GENERAL_ERROR,
173 PLOVER_GENERAL_ERROR_NO_SUCH_PACKAGE));
175 g_unsetenv("RAZOR_ROOT");
179 static void test_remove_warning(void)
181 char *pkgs[]={"badpostun",NULL};
182 gchar *root,*root_uri;
185 root=g_strdup("razor-test-dir-XXXXXX");
186 g_assert(mkdtemp(root));
187 file=g_file_new_for_path(root);
188 root_uri=g_file_get_uri(file);
189 g_object_unref(file);
190 g_setenv("RAZOR_ROOT",root_uri,TRUE);
192 if (!plover_install("../yum-repo-test-dir","/test",pkgs,&err))
193 g_error("test-remove-warning: %s",err->message);
194 if (!plover_remove(pkgs,&err))
196 g_assert(err && err->message);
197 g_error("test-remove-warning: %s",err->message);
200 g_unsetenv("RAZOR_ROOT");
204 static void test_prefix(void)
208 file=g_file_new_for_path("../razor-test-dir");
209 root_uri=g_file_get_uri(file);
210 g_object_unref(file);
211 g_setenv("RAZOR_ROOT",root_uri,TRUE);
213 g_assert(plover_installed_files_match_prefix("/usr//"));
214 g_assert(!plover_installed_files_match_prefix("/tmp"));
215 g_unsetenv("RAZOR_ROOT");
218 static void test_prefix_none(void)
220 gchar *root,*root_uri;
222 root=g_strdup("razor-test-dir-XXXXXX");
223 g_assert(mkdtemp(root));
224 file=g_file_new_for_path(root);
225 root_uri=g_file_get_uri(file);
226 g_object_unref(file);
227 g_setenv("RAZOR_ROOT",root_uri,TRUE);
229 g_assert(plover_installed_files_match_prefix("/any-prefix"));
230 g_unsetenv("RAZOR_ROOT");
234 int main(int argc,char **argv)
237 g_test_init(&argc,&argv,NULL);
238 razor_set_lua_loader("posix",(void (*)())luaopen_posix);
239 g_test_bug_base("mailto:ali@juiblex.co.uk");
240 g_test_add_func("/razor/install",test_install);
241 g_test_add_func("/razor/install-bad-rpm",test_install_bad_rpm);
242 g_test_add_func("/razor/update-noop",test_update_noop);
243 g_test_add_func("/razor/update-nonexistant",test_update_nonexistant);
244 g_test_add_func("/razor/remove",test_remove);
245 g_test_add_func("/razor/remove-noop",test_remove_noop);
246 g_test_add_func("/razor/remove-nonexistant",test_remove_nonexistant);
247 g_test_add_func("/razor/remove-warning",test_remove_warning);
248 g_test_add_func("/razor/prefix",test_prefix);
249 g_test_add_func("/razor/prefix-none",test_prefix_none);