mirror of
https://github.com/clearlinux/cve-check-tool.git
synced 2026-08-23 14:36:09 +00:00
tests: Add initial packaging tests for RPM functionality
Signed-off-by: Ikey Doherty <michael.i.doherty@intel.com>
This commit is contained in:
@@ -25,3 +25,4 @@ check_*.trs
|
||||
test-*.log
|
||||
.dirstamp
|
||||
check_jira_plugin
|
||||
check_packaging
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
EXTRA_DIST = ${top_srcdir}/README.md \
|
||||
${top_srcdir}/LICENSE \
|
||||
${top_srcdir}/common.mk
|
||||
${top_srcdir}/LICENSE \
|
||||
${top_srcdir}/common.mk \
|
||||
${top_srcdir}/tests/package.spec
|
||||
|
||||
NULL =
|
||||
CLEANFILES =
|
||||
|
||||
@@ -8,6 +8,7 @@ AM_CFLAGS = -fstack-protector -Wall -pedantic \
|
||||
AM_CPPFLAGS = \
|
||||
-I $(top_srcdir)/src \
|
||||
-DDATA_DIRECTORY=\"$(datadir)/cve-check-tool\" \
|
||||
-DSITE_PATH=\"$(sysconfdir)\" -DDEFAULT_PATH=\"$(datadir)/defaults/cve-check-tool\"
|
||||
-DSITE_PATH=\"$(sysconfdir)\" -DDEFAULT_PATH=\"$(datadir)/defaults/cve-check-tool\" \
|
||||
-DTOP_DIR=\"$(top_srcdir)\"
|
||||
|
||||
AUTOMAKE_OPTIONS = color-tests parallel-tests
|
||||
|
||||
+19
-2
@@ -3,11 +3,13 @@
|
||||
|
||||
TESTS = \
|
||||
check_core \
|
||||
check_jira_plugin
|
||||
check_jira_plugin \
|
||||
check_packaging
|
||||
|
||||
check_PROGRAMS = \
|
||||
check_core \
|
||||
check_jira_plugin
|
||||
check_jira_plugin \
|
||||
check_packaging
|
||||
|
||||
check_core_SOURCES = \
|
||||
check-core.c
|
||||
@@ -42,3 +44,18 @@ check_jira_plugin_LDADD = \
|
||||
$(LIBJSON_GLIB_LIBS)
|
||||
|
||||
|
||||
check_packaging_SOURCES = \
|
||||
check-packaging.c
|
||||
|
||||
check_packaging_CFLAGS = \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(GIO_CFLAGS) \
|
||||
$(LIBXML2_CFLAGS) \
|
||||
$(AM_CFLAGS) \
|
||||
$(CHECK_CFLAGS)
|
||||
|
||||
check_packaging_LDADD = \
|
||||
$(GLIB_LIBS) \
|
||||
$(GIO_LIBS) \
|
||||
$(LIBXML2_LIBS) \
|
||||
$(CHECK_LIBS)
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* This file is part of cve-check-tool
|
||||
* Copyright (C) 2015 Intel Corporation
|
||||
*
|
||||
* cve-check-tool 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.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <check.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "cve-string.c"
|
||||
#include "util.h"
|
||||
#include "util.c"
|
||||
#include "rpm.c"
|
||||
#include "eopkg.c"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
/**
|
||||
* Kept here as a no-op for now (linking)
|
||||
*/
|
||||
void cve_add_package(const char *path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy of main.c function
|
||||
*/
|
||||
static inline void package_free(void *p)
|
||||
{
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
struct source_package_t *t = p;
|
||||
if (t->issues) {
|
||||
g_list_free_full(t->issues, xmlFree);
|
||||
}
|
||||
if (t->patched) {
|
||||
g_list_free_full(t->patched, xmlFree);
|
||||
}
|
||||
if (t->path) {
|
||||
g_free(t->path);
|
||||
}
|
||||
if (t->xml) {
|
||||
xmlFree((xmlChar*)t->name);
|
||||
xmlFree((xmlChar*)t->version);
|
||||
} else {
|
||||
g_free((gchar*)t->name);
|
||||
g_free((gchar*)t->version);
|
||||
}
|
||||
if (t->extra) {
|
||||
g_strfreev(t->extra);
|
||||
}
|
||||
|
||||
free(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure parse_xml_date works
|
||||
*/
|
||||
START_TEST(cve_rpm_test)
|
||||
{
|
||||
struct source_package_t *pkg = NULL;
|
||||
|
||||
pkg = rpm_inspect_spec(TOP_DIR "/tests/package.spec");
|
||||
fail_if(!pkg, "Failed to inspect RPM spec!");
|
||||
|
||||
fail_if(!g_str_equal(pkg->name, "test-package"),
|
||||
"Invalid RPM package name");
|
||||
fail_if(!g_str_equal(pkg->version, "1.1.0"),
|
||||
"Invalid RPM package version");
|
||||
fail_if(pkg->release != 5, "Invalid RPM package release");
|
||||
|
||||
package_free(pkg);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
static Suite *core_suite(void)
|
||||
{
|
||||
Suite *s = NULL;
|
||||
TCase *tc = NULL;
|
||||
|
||||
s = suite_create("cve_packaging");
|
||||
tc = tcase_create("cve_packaging_functions");
|
||||
tcase_add_test(tc, cve_rpm_test);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Suite *s;
|
||||
SRunner *sr;
|
||||
int fail;
|
||||
|
||||
s = core_suite();
|
||||
sr = srunner_create(s);
|
||||
srunner_run_all(sr, CK_VERBOSE);
|
||||
fail = srunner_ntests_failed(sr);
|
||||
srunner_free(sr);
|
||||
|
||||
if (fail > 0) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# Mostly ensuring demacro performs correctly
|
||||
%define sub package
|
||||
%define patch 0
|
||||
%define minor 1
|
||||
%define suffix %{minor}.%{patch}
|
||||
|
||||
# test-package
|
||||
Name : test-%{sub}
|
||||
# 1.1.0
|
||||
Version : 1.%{suffix}
|
||||
Release : 5
|
||||
|
||||
%description
|
||||
Invalid RPM spec package, provided solely for testing
|
||||
Reference in New Issue
Block a user