Skip to content

Commit

Permalink
drivers: fixup linux version dependent test cases
Browse files Browse the repository at this point in the history
The error output being checked depends on the linux caps supported
by the particular operating system. Fix these test cases to just
check that an error did occur.
  • Loading branch information
shoenig committed May 15, 2021
1 parent a71081c commit dca4acd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
30 changes: 0 additions & 30 deletions drivers/docker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,6 @@ const (
dockerAuthHelperPrefix = "docker-credential-"
)

// nomadDefaultCaps is the subset of dockerDefaultCaps that Nomad enables by
// default and is used to compute the set of capabilities to add/drop given
// docker driver configuration.
func nomadDefaultCaps() []string {
return []string{
"AUDIT_WRITE",
"CHOWN",
"DAC_OVERRIDE",
"FOWNER",
"FSETID",
"KILL",
"MKNOD",
"NET_BIND_SERVICE",
"SETFCAP",
"SETGID",
"SETPCAP",
"SETUID",
"SYS_CHROOT",
}
}

// dockerDefaultCaps is a list of Linux capabilities enabled by docker by default
// and is used to compute the set of capabilities to add/drop given docker driver
// configuration, as well as Nomad built-in limitations.
//
// https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities
func dockerDefaultCaps() []string {
return append(nomadDefaultCaps(), "NET_RAW")
}

func PluginLoader(opts map[string]string) (map[string]interface{}, error) {
conf := map[string]interface{}{}
if v, ok := opts["docker.endpoint"]; ok {
Expand Down
28 changes: 21 additions & 7 deletions drivers/shared/capabilities/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ func TestCaps_Calculate(t *testing.T) {
capDrop []string // task config

// output
exp []string
err error
exp []string
err error
skip bool // error message is linux version dependent
}{
{
name: "the default setting",
Expand Down Expand Up @@ -77,6 +78,7 @@ func TestCaps_Calculate(t *testing.T) {
err: nil,
},
{
skip: true,
name: "allow defaults and add all",
allowCaps: NomadDefaults().Slice(false),
capAdd: []string{"all"},
Expand Down Expand Up @@ -135,8 +137,13 @@ func TestCaps_Calculate(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
caps, err := Calculate(NomadDefaults(), tc.allowCaps, tc.capAdd, tc.capDrop)
require.Equal(t, tc.err, err)
require.Equal(t, tc.exp, caps)
if !tc.skip {
require.Equal(t, tc.err, err)
require.Equal(t, tc.exp, caps)
} else {
require.Error(t, err)
require.Equal(t, tc.exp, caps)
}
})
}
}
Expand All @@ -154,6 +161,7 @@ func TestCaps_Delta(t *testing.T) {
expAdd []string
expDrop []string
err error
skip bool // error message is linux version dependent
}{
{
name: "the default setting",
Expand Down Expand Up @@ -249,6 +257,7 @@ func TestCaps_Delta(t *testing.T) {
err: nil,
},
{
skip: true,
name: "add all atop defaults",
allowCaps: NomadDefaults().Slice(false),
capAdd: []string{"all"},
Expand All @@ -260,9 +269,14 @@ func TestCaps_Delta(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
add, drop, err := Delta(DockerDefaults(), tc.allowCaps, tc.capAdd, tc.capDrop)
require.Equal(t, tc.err, err)
require.Equal(t, tc.expAdd, add)
require.Equal(t, tc.expDrop, drop)
if !tc.skip {
require.Equal(t, tc.err, err)
require.Equal(t, tc.expAdd, add)
require.Equal(t, tc.expDrop, drop)
} else {
require.Error(t, err)
require.Equal(t, tc.expDrop, drop)
}
})
}
}

0 comments on commit dca4acd

Please sign in to comment.