1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
// Copyright (c) 2019, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package delete
import (
"bytes"
"testing"
"github.com/sylabs/singularity/v4/e2e/internal/e2e"
"github.com/sylabs/singularity/v4/e2e/internal/testhelper"
)
type ctx struct {
env e2e.TestEnv
}
func (c ctx) testDeleteCmd(t *testing.T) {
tests := []struct {
name string
args []string
agree string
expectExit int
expect e2e.SingularityCmdResultOp
}{
{
name: "delete unauthorized arch",
args: []string{"--arch=amd64", "library://test/default/test:v0.0.3"},
agree: "y",
expectExit: 255,
},
{
name: "delete unauthorized no arch",
args: []string{"library://test/default/test:v0.0.3"},
agree: "y",
expectExit: 255,
},
{
name: "delete disagree arch",
args: []string{"--arch=amd64", "library://test/default/test:v0.0.3"},
agree: "n",
expectExit: 0,
},
{
name: "delete disagree noarch",
args: []string{"library://test/default/test:v0.0.3"},
agree: "n",
expectExit: 0,
},
{
name: "delete unauthorized force arch",
args: []string{"--force", "--arch=amd64", "library://test/default/test:v0.0.3"},
agree: "",
expectExit: 255,
},
{
name: "delete unauthorized force noarch",
args: []string{"--force", "library://test/default/test:v0.0.3"},
agree: "",
expectExit: 255,
},
{
name: "delete unauthorized custom library",
args: []string{"--library=https://cloud.staging.sylabs.io", "library://test/default/test:v0.0.3"},
agree: "y",
expectExit: 255,
},
{
name: "delete host in uri",
args: []string{"library://library.example.com/test/default/test:v0.0.3"},
agree: "y",
expectExit: 255,
expect: e2e.ExpectError(e2e.ContainMatch, "no such host"),
},
}
for _, tt := range tests {
c.env.RunSingularity(
t,
e2e.AsSubtest(tt.name),
e2e.WithProfile(e2e.UserProfile),
e2e.WithCommand("delete"),
e2e.WithArgs(tt.args...),
e2e.WithStdin(bytes.NewBufferString(tt.agree)),
e2e.ExpectExit(tt.expectExit, tt.expect),
)
}
}
// E2ETests is the main func to trigger the test suite.
func E2ETests(env e2e.TestEnv) testhelper.Tests {
c := ctx{
env: env,
}
return testhelper.Tests{
"delete": c.testDeleteCmd,
}
}
|