tests: internal: env: windows support.
Windows doesn't support setenv/unsetenv.
This patch is to modify to use putenv/_putenv .
@@ -33,6 +33,7 @@ void test_translate_long_env()
char *long_env = "ABC_APPLICATION_TEST_TEST_ABC_FLUENT_BIT_SECRET_FLUENTD_HTTP_HOST";
char long_env_ra[4096] = {0};
char *env_val = "aaaaa";
+ char putenv_arg[4096] = {0};
size_t ret_size;
int ret;
@@ -41,14 +42,22 @@ void test_translate_long_env()
TEST_MSG("long_env_ra size error");
exit(1);
}
+ ret_size = snprintf(&putenv_arg[0], sizeof(putenv_arg), "%s=%s", long_env, env_val);
+ if (!TEST_CHECK(ret_size < sizeof(long_env_ra))) {
+ TEST_MSG("putenv_arg size error");
+ exit(1);
+ }
env = flb_env_create();
if (!TEST_CHECK(env != NULL)) {
TEST_MSG("flb_env_create failed");
exit(1);
}
-
- ret = setenv(long_env, env_val, 0);
+#ifndef FLB_SYSTEM_WINDOWS
+ ret = putenv(&putenv_arg[0]);
+#else
+ ret = _putenv(&putenv_arg[0]);
+#endif
if (!TEST_CHECK(ret == 0)) {
TEST_MSG("setenv failed");
flb_env_destroy(env);
@@ -58,7 +67,9 @@ void test_translate_long_env()
buf = flb_env_var_translate(env, &long_env_ra[0]);
if (!TEST_CHECK(buf != NULL)) {
TEST_MSG("flb_env_var_translate failed");
+#ifndef FLB_SYSTEM_WINDOWS
unsetenv(long_env);
+#endif
flb_env_destroy(env);
exit(1);
}
@@ -67,7 +78,9 @@ void test_translate_long_env()
TEST_MSG("mismatch. Got=%s expect=%s", buf, env_val);
}
flb_sds_destroy(buf);
+#ifndef FLB_SYSTEM_WINDOWS
unsetenv(long_env);
+#endif
flb_env_destroy(env);
}
