summaryrefslogtreecommitdiff
path: root/src/test/test-env-util.c
diff options
context:
space:
mode:
authorRay Strode <rstrode@redhat.com>2016-08-03 14:35:50 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-20 18:49:14 -0500
commit6162512cde54244127da547917d0e6d5d0a378c3 (patch)
tree4a819239ab2c2050a8d0dcbe4e668fdad322dc41 /src/test/test-env-util.c
parent1bd2d4e31b739586cf91ddfe65349f79298af013 (diff)
downloadsystemd-6162512cde54244127da547917d0e6d5d0a378c3.tar.gz
basic: fix strv_env_get_n for unclean arrays
If an environment array has duplicates, strv_env_get_n returns the results for the first match. This is wrong, because later entries in the environment are supposed to replace earlier entries.
Diffstat (limited to 'src/test/test-env-util.c')
-rw-r--r--src/test/test-env-util.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c
index 35bb62906e..e004c518fb 100644
--- a/src/test/test-env-util.c
+++ b/src/test/test-env-util.c
@@ -45,6 +45,16 @@ static void test_strv_env_delete(void) {
assert_se(strv_length(d) == 2);
}
+static void test_strv_env_get(void) {
+ char **l;
+
+ l = STRV_MAKE("ONE_OR_TWO=1", "THREE=3", "ONE_OR_TWO=2", "FOUR=4");
+
+ assert_se(streq(strv_env_get(l, "ONE_OR_TWO"), "2"));
+ assert_se(streq(strv_env_get(l, "THREE"), "3"));
+ assert_se(streq(strv_env_get(l, "FOUR"), "4"));
+}
+
static void test_strv_env_unset(void) {
_cleanup_strv_free_ char **l = NULL;
@@ -211,6 +221,7 @@ static void test_env_assignment_is_valid(void) {
int main(int argc, char *argv[]) {
test_strv_env_delete();
+ test_strv_env_get();
test_strv_env_unset();
test_strv_env_set();
test_strv_env_merge();