-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: address reviews, add more edge cases to test
Signed-off-by: Lincoln Wallace <lincoln.wallace@canonical.com>
- Loading branch information
Showing
7 changed files
with
166 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
tests/spread/extensions/snaps/env-injector-hello/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(hello C) | ||
|
||
# Add executable for hello | ||
add_executable(hello hello.c) | ||
install(TARGETS hello RUNTIME DESTINATION bin) | ||
|
||
# Add executable for hello2 | ||
add_executable(hello2 hello2.c) | ||
install(TARGETS hello2 RUNTIME DESTINATION bin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
int main(int argc, char const *argv[]) { | ||
const char *envs[] = { | ||
"GLOBAL", // This is set globally | ||
"SPECIFIC", // This is set for the app only | ||
"HELLO_WORLD", // This is set from global env file | ||
}; | ||
|
||
const char *expected[] = { | ||
"World", | ||
"City", | ||
"Hello World", | ||
}; | ||
|
||
int num_envs = sizeof(envs) / sizeof(envs[0]); | ||
|
||
for (int i = 0; i < num_envs; ++i) { | ||
const char *env = getenv(envs[i]); | ||
|
||
if (env == NULL) { | ||
fprintf(stderr, "\n[ERROR] Env. variable %s is not set.\n", envs[i]); | ||
exit(1); | ||
} | ||
|
||
if (strcmp(env, expected[i]) != 0) { | ||
fprintf(stderr, "\n[ERROR] Env. variable %s isn't set to the expected value.\n", envs[i]); | ||
fprintf(stderr, "Expected: %s\n", expected[i]); | ||
fprintf(stderr, "Got: %s\n", env); | ||
exit(1); | ||
} | ||
} | ||
|
||
// Check that it's not possible to access other app ENVs | ||
const char *env_hello = getenv("HELLO"); | ||
if (env_hello != NULL) { | ||
fprintf(stderr, "\n[ERROR] Env. variable SPECIFIC is accessible from the app.\n"); | ||
fprintf(stderr, "Expected: NULL\n"); | ||
fprintf(stderr, "Got %s\n", env_hello); | ||
exit(1); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters