Skip to content

Commit

Permalink
e2e: add SINGULARITYENV_ tests for --oci mode
Browse files Browse the repository at this point in the history
Signed-off-by: Edita Kizinevic <edita.kizinevic@cern.ch>
  • Loading branch information
dtrudg authored and edytuk committed Mar 31, 2023
1 parent 35e9df0 commit 4ebfbf7
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
3 changes: 2 additions & 1 deletion e2e/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ func E2ETests(env e2e.TestEnv) testhelper.Tests {
//
// --oci mode
//
"oci environment option": c.ociEnvOption,
"oci environment apptainerenv": c.ociApptainerEnv,
"oci environment option": c.ociEnvOption,
}
}
67 changes: 67 additions & 0 deletions e2e/env/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,73 @@ import (
"github.com/apptainer/apptainer/e2e/internal/e2e"
)

func (c ctx) ociApptainerEnv(t *testing.T) {
e2e.EnsureOCIImage(t, c.env)
defaultImage := "oci-archive:" + c.env.OCIImagePath

// Append or prepend this path.
partialPath := "/foo"

// Overwrite the path with this one.
overwrittenPath := "/usr/bin:/bin"

// A path with a trailing comma
trailingCommaPath := "/usr/bin:/bin,"

tests := []struct {
name string
image string
path string
env []string
}{
{
name: "DefaultPath",
image: defaultImage,
path: defaultPath,
env: []string{},
},
{
name: "AppendToDefaultPath",
image: defaultImage,
path: defaultPath + ":" + partialPath,
env: []string{"APPTAINERENV_APPEND_PATH=/foo"},
},
{
name: "PrependToDefaultPath",
image: defaultImage,
path: partialPath + ":" + defaultPath,
env: []string{"APPTAINERENV_PREPEND_PATH=/foo"},
},
{
name: "OverwriteDefaultPath",
image: defaultImage,
path: overwrittenPath,
env: []string{"APPTAINERENV_PATH=" + overwrittenPath},
},
{
name: "OverwriteTrailingCommaPath",
image: defaultImage,
path: trailingCommaPath,
env: []string{"APPTAINERENV_PATH=" + trailingCommaPath},
},
}

for _, tt := range tests {
c.env.RunApptainer(
t,
e2e.AsSubtest(tt.name),
e2e.WithProfile(e2e.OCIUserProfile),
e2e.WithCommand("exec"),
e2e.WithEnv(tt.env),
e2e.WithArgs(tt.image, "/bin/sh", "-c", "echo $PATH"),
e2e.ExpectExit(
0,
e2e.ExpectOutput(e2e.ExactMatch, tt.path),
),
)
}
}

func (c ctx) ociEnvOption(t *testing.T) {
e2e.EnsureOCIImage(t, c.env)
defaultImage := "oci-archive:" + c.env.OCIImagePath
Expand Down

0 comments on commit 4ebfbf7

Please sign in to comment.