-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add spread tests for env-injector extension
- add: spread test: * hello.c: application which consumes env variables * task.yaml: Tests to verify env-injector functionality Signed-off-by: Lincoln Wallace <[email protected]>
- Loading branch information
Showing
6 changed files
with
114 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
summary: Build and run a basic hello-world snap using extensions | ||
|
||
systems: | ||
- ubuntu-24.04 | ||
|
||
environment: | ||
|
||
SNAPCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS: "1" | ||
SNAP_DIR: ../snaps/env-injector-hello | ||
SNAP: env-injector-hello | ||
|
||
prepare: | | ||
#shellcheck source=tests/spread/tools/snapcraft-yaml.sh | ||
. "$TOOLS_DIR/snapcraft-yaml.sh" | ||
set_base "$SNAP_DIR/snap/snapcraft.yaml" | ||
restore: | | ||
cd "$SNAP_DIR" | ||
snapcraft clean | ||
rm -f ./*.snap | ||
rm -rf ./squashfs-root | ||
#shellcheck source=tests/spread/tools/snapcraft-yaml.sh | ||
. "$TOOLS_DIR/snapcraft-yaml.sh" | ||
restore_yaml "snap/snapcraft.yaml" | ||
execute: | | ||
cd "$SNAP_DIR" | ||
snapcraft | ||
unsquashfs "${SNAP}"_1.0_*.snap | ||
# Check that the env-exporter program is present | ||
[ -f squashfs-root/bin/command-chain/env-exporter ] | ||
# Check that the hello command is present | ||
[ -f squashfs-root/usr/local/bin/hello ] | ||
snap install "${SNAP}"_1.0_*.snap --dangerous | ||
# Create envfile | ||
echo 'HELLO_WORLD="Hello, World"' >> envfile.env | ||
# Set env vars: Global, App specific, and envfile | ||
snap set env-injector-hello env.hello="Hello" | ||
snap set env-injector-hello apps.hello.env.world="World" | ||
snap set env-injector-hello envfile="${SNAP_DIR}"/enfile.env | ||
# Run the hello command | ||
env-injector-hello.hello | ||
4 changes: 4 additions & 0 deletions
4
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(hello C) | ||
add_executable(hello hello.c) | ||
install(TARGETS hello 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
int main(int argc, char const *argv[]) { | ||
const char *envs[] = { | ||
"HELLO", // This is set globally | ||
"WORLD", // This is set for the app | ||
"HELLO_WORLD", // This is set from env file | ||
}; | ||
|
||
const char *expected[] = { | ||
"Hello", | ||
"World", | ||
"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]); | ||
return 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); | ||
return 1; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/spread/extensions/snaps/env-injector-hello/snap/snapcraft.yaml
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,18 @@ | ||
name: env-injector-hello | ||
version: "1.0" | ||
summary: test the env-injector extension | ||
description: This is a basic snap for testing env-injector extension | ||
|
||
grade: devel | ||
base: core24 | ||
confinement: strict | ||
|
||
apps: | ||
env-hello: | ||
command: usr/local/bin/hello | ||
extensions: [ env-injector ] | ||
|
||
parts: | ||
hello: | ||
plugin: cmake | ||
source: . |
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