summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-01-17 16:36:41 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-01-17 16:58:14 +0800
commitd14bf38b9881c385478a460e3058d7cadee107fb (patch)
tree57eb1befbbbdc732b4c0715652081d59b5a55b21 /test
parentb1d15f894473d4b1e90ad273487a432bcd637195 (diff)
downloadtalos-petitboot-d14bf38b9881c385478a460e3058d7cadee107fb.zip
talos-petitboot-d14bf38b9881c385478a460e3058d7cadee107fb.tar.gz
test/parser: Check for full URLs in parser tests
At present, we only match the 'file' portion of a URL in the parser tests, so we "serve" a file if just the filename (but not the scheme, hostname or path) matches the file we set with test_read_conf_embedded. This change introduces test_read_conf_embedded_url, which we can use to specify a full URL. In this case, the fake parser_request_file matches the entire URL before returning the file data. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'test')
-rw-r--r--test/parser/parser-test.h12
-rw-r--r--test/parser/test-grub2-save-env.c3
-rw-r--r--test/parser/test-pxe-initrd-in-append.c2
-rw-r--r--test/parser/test-pxe-ip-without-conf.c2
-rw-r--r--test/parser/test-pxe-mac-without-conf.c3
-rw-r--r--test/parser/test-pxe-non-url-conf.c2
-rw-r--r--test/parser/test-pxe-single.c2
-rw-r--r--test/parser/utils.c10
8 files changed, 24 insertions, 12 deletions
diff --git a/test/parser/parser-test.h b/test/parser/parser-test.h
index c23a7b0..7c40650 100644
--- a/test/parser/parser-test.h
+++ b/test/parser/parser-test.h
@@ -21,9 +21,10 @@ struct discover_device *test_create_device(struct parser_test *test,
const char *name);
#define test_read_conf_data(t, f, d) \
- __test_read_conf_data(t, f, d, sizeof(d))
+ __test_read_conf_data(t, t->ctx->device, f, d, sizeof(d))
-void __test_read_conf_data(struct parser_test *test, const char *conf_file,
+void __test_read_conf_data(struct parser_test *test,
+ struct discover_device *dev, const char *conf_file,
const char *buf, size_t len);
void test_read_conf_file(struct parser_test *test, const char *filename,
const char *conf_file);
@@ -49,7 +50,12 @@ struct discover_boot_option *get_boot_option(struct discover_context *ctx,
extern const char __embedded_config[];
extern const size_t __embedded_config_size;
#define test_read_conf_embedded(t, f) \
- __test_read_conf_data(t, f, __embedded_config, __embedded_config_size)
+ __test_read_conf_data(t, t->ctx->device, f, \
+ __embedded_config, __embedded_config_size)
+
+#define test_read_conf_embedded_url(t, u) \
+ __test_read_conf_data(t, NULL, u, \
+ __embedded_config, __embedded_config_size)
/**
* Checks for parser results.
diff --git a/test/parser/test-grub2-save-env.c b/test/parser/test-grub2-save-env.c
index ce9a76a..68e91bd 100644
--- a/test/parser/test-grub2-save-env.c
+++ b/test/parser/test-grub2-save-env.c
@@ -86,7 +86,8 @@ static void run_env_test(struct parser_test *test, struct env_test *envtest)
test_add_file_data(test, test->ctx->device, "/boot/grub/grubenv",
env_before, strlen(env_before));
- __test_read_conf_data(test, "/boot/grub/grub.cfg", envtest->script,
+ __test_read_conf_data(test, test->ctx->device,
+ "/boot/grub/grub.cfg", envtest->script,
strlen(envtest->script));
test_run_parser(test, "grub2");
diff --git a/test/parser/test-pxe-initrd-in-append.c b/test/parser/test-pxe-initrd-in-append.c
index 2939e98..6ea6bef 100644
--- a/test/parser/test-pxe-initrd-in-append.c
+++ b/test/parser/test-pxe-initrd-in-append.c
@@ -14,7 +14,7 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test, "conf.txt");
+ test_read_conf_embedded_url(test, "tftp://host/dir/conf.txt");
test_set_event_source(test);
test_set_event_param(test->ctx->event, "pxeconffile",
diff --git a/test/parser/test-pxe-ip-without-conf.c b/test/parser/test-pxe-ip-without-conf.c
index dd4cedd..ff3bf9e 100644
--- a/test/parser/test-pxe-ip-without-conf.c
+++ b/test/parser/test-pxe-ip-without-conf.c
@@ -15,7 +15,7 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test, "C0A8");
+ test_read_conf_embedded_url(test, "tftp://host/dir/C0A8");
test_set_event_source(test);
test_set_event_param(test->ctx->event, "bootfile", "dir/pxe");
diff --git a/test/parser/test-pxe-mac-without-conf.c b/test/parser/test-pxe-mac-without-conf.c
index 72ef94b..8c0b561 100644
--- a/test/parser/test-pxe-mac-without-conf.c
+++ b/test/parser/test-pxe-mac-without-conf.c
@@ -15,7 +15,8 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test, "01-12-34-56-78-9A-BC");
+ test_read_conf_embedded_url(test,
+ "tftp://host/dir/01-12-34-56-78-9A-BC");
test_set_event_source(test);
test_set_event_param(test->ctx->event, "bootfile", "dir/pxe");
diff --git a/test/parser/test-pxe-non-url-conf.c b/test/parser/test-pxe-non-url-conf.c
index 08f246a..491a40b 100644
--- a/test/parser/test-pxe-non-url-conf.c
+++ b/test/parser/test-pxe-non-url-conf.c
@@ -15,7 +15,7 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test, "conf.txt");
+ test_read_conf_embedded_url(test, "tftp://host/conf.txt");
test_set_event_source(test);
test_set_event_param(test->ctx->event, "siaddr", "host");
diff --git a/test/parser/test-pxe-single.c b/test/parser/test-pxe-single.c
index 0bc6a59..56c404c 100644
--- a/test/parser/test-pxe-single.c
+++ b/test/parser/test-pxe-single.c
@@ -15,7 +15,7 @@ void run_test(struct parser_test *test)
struct discover_boot_option *opt;
struct discover_context *ctx;
- test_read_conf_embedded(test, "conf.txt");
+ test_read_conf_embedded_url(test, "tftp://host/dir/conf.txt");
test_set_event_source(test);
test_set_event_param(test->ctx->event, "pxeconffile",
diff --git a/test/parser/utils.c b/test/parser/utils.c
index 8011793..67401ab 100644
--- a/test/parser/utils.c
+++ b/test/parser/utils.c
@@ -112,10 +112,11 @@ void test_fini(struct parser_test *test)
talloc_free(test);
}
-void __test_read_conf_data(struct parser_test *test, const char *conf_file,
+void __test_read_conf_data(struct parser_test *test,
+ struct discover_device *dev, const char *conf_file,
const char *buf, size_t len)
{
- test_add_file_data(test, test->ctx->device, conf_file, buf, len);
+ test_add_file_data(test, dev, conf_file, buf, len);
}
void test_read_conf_file(struct parser_test *test, const char *filename,
@@ -239,7 +240,10 @@ int parser_request_url(struct discover_context *ctx, struct pb_url *url,
char *tmp;
list_for_each_entry(&test->files, file, list) {
- if (strcmp(file->name, url->file))
+ if (file->dev)
+ continue;
+
+ if (strcmp(file->name, url->full))
continue;
/* the read_file() interface always adds a trailing null
OpenPOWER on IntegriCloud