[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 2/2] v2v: OVF: Add unit tests for modified OVF.get_ostype function.



This adds unit tests for commit 6f9d5dce47f8502bee5d7285faf7695b22b5300b.
---
 .gitignore            |  2 ++
 po/POTFILES-ml        |  1 +
 v2v/Makefile.am       | 45 ++++++++++++++++++++++++
 v2v/OVF.mli           |  5 +++
 v2v/v2v_unit_tests.ml | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 147 insertions(+)
 create mode 100644 v2v/v2v_unit_tests.ml

diff --git a/.gitignore b/.gitignore
index 2a3cc81..318cfa0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -567,6 +567,7 @@ Makefile.in
 /v2v/centos-7.0.img
 /v2v/fedora-20.img
 /v2v/link.sh
+/v2v/oUnit-*
 /v2v/rhel-5.10.img
 /v2v/rhel-6.5.img
 /v2v/rhel-7.0.img
@@ -576,5 +577,6 @@ Makefile.in
 /v2v/test-harness/dllv2v_test_harness.so
 /v2v/test-harness/stamp-virt-v2v-test-harness.pod
 /v2v/test-harness/virt-v2v-test-harness.1
+/v2v/v2v_unit_tests
 /v2v/virt-v2v
 /v2v/virt-v2v.1
diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index 552fff3..7f4e096 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -115,4 +115,5 @@ v2v/test-harness/v2v_test_harness.ml
 v2v/types.ml
 v2v/utils.ml
 v2v/v2v.ml
+v2v/v2v_unit_tests.ml
 v2v/xml.ml
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index f07860e..8ba5fde 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -231,6 +231,10 @@ TESTS = \
 	test-v2v-i-ova-gz.sh \
 	test-v2v-i-ova-two-disks.sh
 
+if HAVE_OCAML_PKG_OUNIT
+TESTS += v2v_unit_tests
+endif
+
 if ENABLE_APPLIANCE
 TESTS += \
 	test-v2v-i-ova.sh \
@@ -283,6 +287,47 @@ $(real_guests:%=%.img):
 
 CLEANFILES += $(real_guests:%=%.img)
 
+# Unit tests.
+check_PROGRAMS =
+if HAVE_OCAML_PKG_OUNIT
+check_PROGRAMS += v2v_unit_tests
+endif
+
+v2v_unit_tests_BOBJECTS = \
+	$(top_builddir)/mllib/config.cmo \
+	$(top_builddir)/mllib/common_gettext.cmo \
+	$(top_builddir)/mllib/common_utils.cmo \
+	stringMap.cmo \
+	types.cmo \
+	utils.cmo \
+	DOM.cmo \
+	OVF.cmo \
+	v2v_unit_tests.cmo
+v2v_unit_tests_XOBJECTS = $(v2v_unit_tests_BOBJECTS:.cmo=.cmx)
+
+v2v_unit_tests_SOURCES = $(virt_v2v_SOURCES)
+v2v_unit_tests_CPPFLAGS = $(virt_v2v_CPPFLAGS)
+v2v_unit_tests_CFLAGS = $(virt_v2v_CFLAGS)
+
+if !HAVE_OCAMLOPT
+# Can't call this v2v_unit_tests_OBJECTS because automake gets confused.
+v2v_unit_tests_THEOBJECTS = $(v2v_unit_tests_BOBJECTS)
+v2v_unit_tests.cmo: OCAMLPACKAGES += -package oUnit
+else
+v2v_unit_tests_THEOBJECTS = $(v2v_unit_tests_XOBJECTS)
+v2v_unit_tests.cmx: OCAMLPACKAGES += -package oUnit
+endif
+
+v2v_unit_tests_DEPENDENCIES = $(v2v_unit_tests_THEOBJECTS)
+v2v_unit_tests_LINK = \
+	./link.sh \
+	  $(OCAMLFIND) $(BEST) $(OCAMLFLAGS) \
+	  $(OCAMLPACKAGES) -package oUnit \
+	  $(OCAMLLINKFLAGS) \
+	  $(v2v_unit_tests_THEOBJECTS) -o $@
+
+CLEANFILES += oUnit-*
+
 # Dependencies.
 depend: .depend
 
diff --git a/v2v/OVF.mli b/v2v/OVF.mli
index d894991..0a354e7 100644
--- a/v2v/OVF.mli
+++ b/v2v/OVF.mli
@@ -28,3 +28,8 @@ val create_meta_files : bool -> Types.output_allocation -> string -> string list
 
 val create_ovf : bool -> Types.source -> Types.target list -> Types.guestcaps -> Types.inspect -> Types.output_allocation -> Types.vmtype option -> string -> string list -> string list -> string -> DOM.doc
 (** Create the OVF file. *)
+
+(**/**)
+
+(* For use by v2v_unit_tests only. *)
+val get_ostype : Types.inspect -> string
diff --git a/v2v/v2v_unit_tests.ml b/v2v/v2v_unit_tests.ml
new file mode 100644
index 0000000..5c3b63a
--- /dev/null
+++ b/v2v/v2v_unit_tests.ml
@@ -0,0 +1,94 @@
+(* virt-resize
+ * Copyright (C) 2011 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.
+ *)
+
+(* This file tests individual virt-v2v functions. *)
+
+open OUnit2
+open Types
+
+let prog = "v2v_unit_tests"
+
+external identity : 'a -> 'a = "%identity"
+
+let test_get_ostype ctx =
+  let i = { i_type = ""; i_distro = ""; i_arch = "";
+            i_major_version = 0; i_minor_version = 0;
+            i_root = ""; i_package_format = ""; i_package_management = "";
+            i_product_name = ""; i_product_variant = ""; i_mountpoints = [];
+            i_apps = []; i_apps_map = StringMap.empty; i_uefi = false } in
+  assert_equal ~printer:identity "RHEL6"
+               (OVF.get_ostype { i with i_type = "linux"; i_distro = "rhel";
+                                        i_major_version = 6;
+                                        i_minor_version = 0;
+                                        i_arch = "i386" });
+  assert_equal ~printer:identity "RHEL6x64"
+               (OVF.get_ostype { i with i_type = "linux"; i_distro = "rhel";
+                                        i_major_version = 6;
+                                        i_minor_version = 0;
+                                        i_arch = "x86_64" });
+  assert_equal ~printer:identity "rhel_7x64"
+               (OVF.get_ostype { i with i_type = "linux"; i_distro = "rhel";
+                                        i_major_version = 7;
+                                        i_minor_version = 0;
+                                        i_arch = "x86_64" });
+  assert_equal ~printer:identity "Windows7"
+               (OVF.get_ostype { i with i_type = "windows";
+                                        i_major_version = 6;
+                                        i_minor_version = 1;
+                                        i_product_variant = "Client";
+                                        i_arch = "i386" });
+  assert_equal ~printer:identity "Windows7x64"
+               (OVF.get_ostype { i with i_type = "windows";
+                                        i_major_version = 6;
+                                        i_minor_version = 1;
+                                        i_product_variant = "Client";
+                                        i_arch = "x86_64" });
+  assert_equal ~printer:identity "windows_8"
+               (OVF.get_ostype { i with i_type = "windows";
+                                        i_major_version = 6;
+                                        i_minor_version = 2;
+                                        i_product_variant = "Client";
+                                        i_arch = "i386" });
+  assert_equal ~printer:identity "windows_8x64"
+               (OVF.get_ostype { i with i_type = "windows";
+                                        i_major_version = 6;
+                                        i_minor_version = 2;
+                                        i_product_variant = "Client";
+                                        i_arch = "x86_64" });
+  assert_equal ~printer:identity "windows_2012x64"
+               (OVF.get_ostype { i with i_type = "windows";
+                                        i_major_version = 6;
+                                        i_minor_version = 2;
+                                        i_product_variant = "Server";
+                                        i_arch = "x86_64" });
+  assert_equal ~printer:identity "windows_2012R2x64"
+               (OVF.get_ostype { i with i_type = "windows";
+                                        i_major_version = 6;
+                                        i_minor_version = 3;
+                                        i_product_variant = "Server";
+                                        i_arch = "x86_64" })
+
+(* Suites declaration. *)
+let suite =
+  "virt-v2v" >:::
+    [
+      "OVF.get_ostype" >:: test_get_ostype;
+    ]
+
+let () =
+  run_test_tt_main suite
-- 
2.3.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]