1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/*
* This file is part of libmodulemd
* Copyright (C) 2021 Red Hat, Inc.
*
* Fedora-License-Identifier: MIT
* SPDX-2.0-License-Identifier: MIT
* SPDX-3.0-License-Identifier: MIT
*
* This program is free software.
* For more information on the license, see COPYING.
* For more information on free software, see <https://www.gnu.org/philosophy/free-sw.en.html>.
*/
#include <locale.h>
#include <glib.h>
#include "modulemd.h"
#include "config.h"
static void
test_modulemd_v3_context_valid (void)
{
const gchar *yaml_string = NULL;
g_autoptr (GError) error = NULL;
g_autoptr (GObject) object = NULL;
GType type = G_TYPE_INVALID;
yaml_string =
"---\n"
"document: modulemd-packager\n"
"version: 3\n"
"data:\n"
" name: trivialname\n"
" stream: trivialstream\n"
" summary: Trivial Summary\n"
" description: >-\n"
" Trivial Description\n"
" license: [DUMMY]\n"
" configurations:\n"
" - context: a234567890\n"
" platform: foo\n"
"...\n";
type = modulemd_read_packager_string (yaml_string, &object, &error);
g_assert_true (type == MODULEMD_TYPE_PACKAGER_V3);
g_assert_no_error (error);
}
static void
test_modulemd_v3_context_overlong (void)
{
const gchar *yaml_string = NULL;
g_autoptr (GError) error = NULL;
g_autoptr (GObject) object = NULL;
GType type = G_TYPE_INVALID;
yaml_string =
"---\n"
"document: modulemd-packager\n"
"version: 3\n"
"data:\n"
" name: trivialname\n"
" stream: trivialstream\n"
" summary: Trivial Summary\n"
" description: >-\n"
" Trivial Description\n"
" license: [DUMMY]\n"
" configurations:\n"
" - context: a2345678901\n"
" platform: foo\n"
"...\n";
type = modulemd_read_packager_string (yaml_string, &object, &error);
g_assert_true (type == G_TYPE_INVALID);
g_assert_error (error, MODULEMD_ERROR, MMD_ERROR_VALIDATE);
}
static void
test_modulemd_v3_context_bad_underscore (void)
{
const gchar *yaml_string = NULL;
g_autoptr (GError) error = NULL;
g_autoptr (GObject) object = NULL;
GType type = G_TYPE_INVALID;
yaml_string =
"---\n"
"document: modulemd-packager\n"
"version: 3\n"
"data:\n"
" name: trivialname\n"
" stream: trivialstream\n"
" summary: Trivial Summary\n"
" description: >-\n"
" Trivial Description\n"
" license: [DUMMY]\n"
" configurations:\n"
" - context: _\n"
" platform: foo\n"
"...\n";
type = modulemd_read_packager_string (yaml_string, &object, &error);
g_assert_true (type == G_TYPE_INVALID);
g_assert_error (error, MODULEMD_ERROR, MMD_ERROR_VALIDATE);
}
static void
test_modulemd_v3_context_duplicate (void)
{
const gchar *yaml_string = NULL;
g_autoptr (GError) error = NULL;
g_autoptr (GObject) object = NULL;
GType type = G_TYPE_INVALID;
yaml_string =
"---\n"
"document: modulemd-packager\n"
"version: 3\n"
"data:\n"
" name: foo\n"
" stream: bar\n"
" license: [DUMMY]\n"
" configurations:\n"
" - context: A\n"
" platform: 1\n"
" - context: A\n"
" platform: 2\n"
"...\n";
type = modulemd_read_packager_string (yaml_string, &object, &error);
g_assert_true (type == G_TYPE_INVALID);
g_assert_error (error, MODULEMD_ERROR, MMD_ERROR_VALIDATE);
}
static void
test_modulemd_v2_context_valid (void)
{
const gchar *yaml_string = NULL;
g_autoptr (GError) error = NULL;
g_autoptr (GObject) object = NULL;
GType type = G_TYPE_INVALID;
yaml_string =
"---\n"
"document: modulemd\n"
"version: 2\n"
"data:\n"
" name: trivialname\n"
" stream: trivialstream\n"
" summary: Trivial Summary\n"
" description: >-\n"
" Trivial Description\n"
" license:\n"
" module: [DUMMY]\n"
" static_context: true\n"
" context: a234567890_23\n"
"...\n";
type = modulemd_read_packager_string (yaml_string, &object, &error);
g_assert_true (type == MODULEMD_TYPE_MODULE_STREAM_V2);
g_assert_no_error (error);
/* Reading v2 document does not validate it; validating explictly */
g_assert_true (
modulemd_module_stream_validate (MODULEMD_MODULE_STREAM (object), &error));
}
static void
test_modulemd_v2_context_overlong (void)
{
const gchar *yaml_string = NULL;
g_autoptr (GError) error = NULL;
g_autoptr (GObject) object = NULL;
GType type = G_TYPE_INVALID;
yaml_string =
"---\n"
"document: modulemd\n"
"version: 2\n"
"data:\n"
" name: trivialname\n"
" stream: trivialstream\n"
" summary: Trivial Summary\n"
" description: >-\n"
" Trivial Description\n"
" license:\n"
" module: [DUMMY]\n"
" static_context: true\n"
" context: a234567890_234\n"
"...\n";
type = modulemd_read_packager_string (yaml_string, &object, &error);
g_assert_true (type == MODULEMD_TYPE_MODULE_STREAM_V2);
g_assert_no_error (error);
/* Reading v2 document does not validate it; validating explictly */
g_assert_false (
modulemd_module_stream_validate (MODULEMD_MODULE_STREAM (object), &error));
}
static void
test_modulemd_v2_context_bad_character (void)
{
const gchar *yaml_string = NULL;
g_autoptr (GError) error = NULL;
g_autoptr (GObject) object = NULL;
GType type = G_TYPE_INVALID;
yaml_string =
"---\n"
"document: modulemd\n"
"version: 2\n"
"data:\n"
" name: trivialname\n"
" stream: trivialstream\n"
" summary: Trivial Summary\n"
" description: >-\n"
" Trivial Description\n"
" license:\n"
" module: [DUMMY]\n"
" static_context: true\n"
" context: '-'\n"
"...\n";
type = modulemd_read_packager_string (yaml_string, &object, &error);
g_assert_true (type == MODULEMD_TYPE_MODULE_STREAM_V2);
g_assert_no_error (error);
/* Reading v2 document does not validate it; validating explictly */
g_assert_false (
modulemd_module_stream_validate (MODULEMD_MODULE_STREAM (object), &error));
}
int
main (int argc, char *argv[])
{
setlocale (LC_ALL, "");
g_test_init (&argc, &argv, NULL);
g_test_set_nonfatal_assertions ();
g_test_bug_base ("https://github.com/fedora-modularity/libmodulemd/issues/");
g_test_bug ("549");
g_test_add_func ("/modulemd/v3/context/valid",
test_modulemd_v3_context_valid);
g_test_add_func ("/modulemd/v3/context/overlong",
test_modulemd_v3_context_overlong);
g_test_add_func ("/modulemd/v3/context/bad_underscore",
test_modulemd_v3_context_bad_underscore);
g_test_add_func ("/modulemd/v3/context/duplicate",
test_modulemd_v3_context_duplicate);
g_test_add_func ("/modulemd/v2/context/valid",
test_modulemd_v2_context_valid);
g_test_add_func ("/modulemd/v2/context/overlong",
test_modulemd_v2_context_overlong);
g_test_add_func ("/modulemd/v2/context/bad_character",
test_modulemd_v2_context_bad_character);
return g_test_run ();
}
|