mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
erlang: Add more tests.
Since I made lots of changes to the Erlang bindings (prompted by Coverity), I wasn't confident that something didn't break because there were no real tests before.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -95,6 +95,7 @@ Makefile.in
|
||||
/erlang/examples/stamp-guestfs-erlang.pod
|
||||
/erlang/guestfs.beam
|
||||
/erlang/guestfs.erl
|
||||
/erlang/test.img
|
||||
/examples/copy_over
|
||||
/examples/create_disk
|
||||
/examples/display_icon
|
||||
|
||||
@@ -60,7 +60,12 @@ TESTS_ENVIRONMENT = $(top_builddir)/run --test
|
||||
TESTS = run-bindtests
|
||||
|
||||
if ENABLE_APPLIANCE
|
||||
TESTS += tests/010-load.erl
|
||||
TESTS += \
|
||||
tests/010-load.erl \
|
||||
tests/030-config.erl \
|
||||
tests/050-lvcreate.erl \
|
||||
tests/060-readdir.erl \
|
||||
tests/070-optargs.erl
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env escript
|
||||
%! -smp enable -sname create_disk debug verbose
|
||||
%! -smp enable -sname test debug verbose
|
||||
|
||||
% libguestfs Erlang tests -*- erlang -*-
|
||||
% Copyright (C) 2009-2012 Red Hat Inc.
|
||||
|
||||
41
erlang/tests/030-config.erl
Executable file
41
erlang/tests/030-config.erl
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env escript
|
||||
%! -smp enable -sname test debug verbose
|
||||
|
||||
% libguestfs Erlang tests -*- erlang -*-
|
||||
% Copyright (C) 2009-2012 Red Hat Inc.
|
||||
%
|
||||
% This program is free software; you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation; either version 2 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% This program is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License along
|
||||
% with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
main(_) ->
|
||||
{ok, G} = guestfs:create(),
|
||||
|
||||
ok = guestfs:set_verbose(G, true),
|
||||
true = guestfs:get_verbose(G),
|
||||
ok = guestfs:set_verbose(G, false),
|
||||
false = guestfs:get_verbose(G),
|
||||
|
||||
ok = guestfs:set_autosync(G, true),
|
||||
true = guestfs:get_autosync(G),
|
||||
ok = guestfs:set_autosync(G, false),
|
||||
false = guestfs:get_autosync(G),
|
||||
|
||||
ok = guestfs:set_path(G, "."),
|
||||
"." = guestfs:get_path(G),
|
||||
ok = guestfs:set_path(G, undefined),
|
||||
"" /= guestfs:get_path(G),
|
||||
|
||||
ok = guestfs:add_drive(G, "/dev/null"),
|
||||
|
||||
ok = guestfs:close(G).
|
||||
42
erlang/tests/050-lvcreate.erl
Executable file
42
erlang/tests/050-lvcreate.erl
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env escript
|
||||
%! -smp enable -sname test debug verbose
|
||||
|
||||
% libguestfs Erlang tests -*- erlang -*-
|
||||
% Copyright (C) 2009-2012 Red Hat Inc.
|
||||
%
|
||||
% This program is free software; you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation; either version 2 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% This program is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License along
|
||||
% with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
main(_) ->
|
||||
{ok, G} = guestfs:create(),
|
||||
|
||||
Disk_image = "test.img",
|
||||
|
||||
{ok, File} = file:open(Disk_image, [raw, write, binary]),
|
||||
{ok, _} = file:position(File, 512 * 1024 * 1024 - 1),
|
||||
ok = file:write(File, " "),
|
||||
ok = file:close(File),
|
||||
|
||||
ok = guestfs:add_drive(G, Disk_image),
|
||||
ok = guestfs:launch(G),
|
||||
ok = guestfs:pvcreate(G, "/dev/sda"),
|
||||
ok = guestfs:vgcreate(G, "VG", ["/dev/sda"]),
|
||||
ok = guestfs:lvcreate(G, "LV1", "VG", 200),
|
||||
ok = guestfs:lvcreate(G, "LV2", "VG", 200),
|
||||
|
||||
["/dev/VG/LV1", "/dev/VG/LV2"] = guestfs:lvs(G),
|
||||
|
||||
ok = guestfs:shutdown(G),
|
||||
ok = guestfs:close(G),
|
||||
file:delete(Disk_image).
|
||||
49
erlang/tests/060-readdir.erl
Executable file
49
erlang/tests/060-readdir.erl
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env escript
|
||||
%! -smp enable -sname test debug verbose
|
||||
|
||||
% libguestfs Erlang tests -*- erlang -*-
|
||||
% Copyright (C) 2009-2012 Red Hat Inc.
|
||||
%
|
||||
% This program is free software; you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation; either version 2 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% This program is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License along
|
||||
% with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
main(_) ->
|
||||
{ok, G} = guestfs:create(),
|
||||
|
||||
Disk_image = "test.img",
|
||||
|
||||
{ok, File} = file:open(Disk_image, [raw, write, binary]),
|
||||
{ok, _} = file:position(File, 10 * 1024 * 1024 - 1),
|
||||
ok = file:write(File, " "),
|
||||
ok = file:close(File),
|
||||
|
||||
ok = guestfs:add_drive(G, Disk_image),
|
||||
ok = guestfs:launch(G),
|
||||
ok = guestfs:part_disk(G, "/dev/sda", "mbr"),
|
||||
ok = guestfs:mkfs(G, "ext2", "/dev/sda1"),
|
||||
ok = guestfs:mount(G, "/dev/sda1", "/"),
|
||||
ok = guestfs:mkdir(G, "/p"),
|
||||
ok = guestfs:mkdir(G, "/q"),
|
||||
|
||||
Dirs = guestfs:readdir(G, "/"),
|
||||
[[_, $d, "."],
|
||||
[_, $d, ".."],
|
||||
[_, $d, "lost+found"],
|
||||
[_, $d, "p"],
|
||||
[_, $d, "q"]]
|
||||
= lists:sort(Dirs),
|
||||
|
||||
ok = guestfs:shutdown(G),
|
||||
ok = guestfs:close(G),
|
||||
file:delete(Disk_image).
|
||||
29
erlang/tests/070-optargs.erl
Executable file
29
erlang/tests/070-optargs.erl
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env escript
|
||||
%! -smp enable -sname test debug verbose
|
||||
|
||||
% libguestfs Erlang tests -*- erlang -*-
|
||||
% Copyright (C) 2009-2012 Red Hat Inc.
|
||||
%
|
||||
% This program is free software; you can redistribute it and/or modify
|
||||
% it under the terms of the GNU General Public License as published by
|
||||
% the Free Software Foundation; either version 2 of the License, or
|
||||
% (at your option) any later version.
|
||||
%
|
||||
% This program is distributed in the hope that it will be useful,
|
||||
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
% GNU General Public License for more details.
|
||||
%
|
||||
% You should have received a copy of the GNU General Public License along
|
||||
% with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
main(_) ->
|
||||
{ok, G} = guestfs:create(),
|
||||
|
||||
ok = guestfs:add_drive(G, "/dev/null"),
|
||||
ok = guestfs:add_drive(G, "/dev/null", [{readonly, true}]),
|
||||
ok = guestfs:add_drive(G, "/dev/null",
|
||||
[{format, "raw"}, {readonly, false}]),
|
||||
|
||||
ok = guestfs:close(G).
|
||||
Reference in New Issue
Block a user