Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make root tests easier to run #501

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,7 @@ jobs:

- name: Test
run: |
go test -c ./internals/daemon
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H ./daemon.test -check.v -check.f ^execSuite\.TestUserGroup$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H ./daemon.test -check.v -check.f ^execSuite\.TestUserIDGroupID$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H ./daemon.test -check.v -check.f ^filesSuite\.TestWriteUserGroupReal$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H ./daemon.test -check.v -check.f ^filesSuite\.TestMakeDirsUserGroupReal$
go test -c ./internals/osutil
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H ./osutil.test -check.v -check.f ^mkdirSuite\.TestMakeParentsChmodAndChown$

go test -c ./internals/overlord/servstate/
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H ./servstate.test -check.v -check.f ^S.TestUserGroup$
PEBBLE_TEST_USER=runner PEBBLE_TEST_GROUP=runner sudo -E -H go test ./...

format:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions internals/cli/cmd_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ services:
} else if path == triggerLayerPath {
c.Assert(err, check.ErrorMatches, "triggered")
} else if path == unreadableLayerPath {
if os.Getuid() == 0 {
c.Skip("requires running as non-root users")
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
}
c.Assert(os.IsPermission(err), check.Equals, true)
}
}
Expand Down
2 changes: 0 additions & 2 deletions internals/daemon/api_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ func (s *execSuite) TestCurrentUserGroup(c *C) {
c.Check(stderr, Equals, "")
}

// See .github/workflows/tests.yml for how to run this test as root.
func (s *execSuite) TestUserGroup(c *C) {
if os.Getuid() != 0 {
c.Skip("requires running as root")
Expand Down Expand Up @@ -286,7 +285,6 @@ func (s *execSuite) TestUserGroup(c *C) {
c.Assert(err, ErrorMatches, `.*home directory.*does not exist`)
}

// See .github/workflows/tests.yml for how to run this test as root.
func (s *execSuite) TestUserIDGroupID(c *C) {
if os.Getuid() != 0 {
c.Skip("requires running as root")
Expand Down
2 changes: 0 additions & 2 deletions internals/daemon/api_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ func (s *filesSuite) testMakeDirsUserGroup(c *C, uid, gid int, user, group strin
return tmpDir
}

// See .github/workflows/tests.yml for how to run this test as root.
func (s *filesSuite) TestMakeDirsUserGroupReal(c *C) {
if os.Getuid() != 0 {
c.Skip("requires running as root")
Expand Down Expand Up @@ -988,7 +987,6 @@ func (s *filesSuite) TestWriteUserGroupMocked(c *C) {
c.Check(mkdirCalls[1], Equals, mkdirArgs{tmpDir + "/nested2", 0o755, osutil.MkdirOptions{MakeParents: true, ExistOK: true, Chmod: true, Chown: true, UserID: 56, GroupID: 78}})
}

// See .github/workflows/tests.yml for how to run this test as root.
func (s *filesSuite) TestWriteUserGroupReal(c *C) {
if os.Getuid() != 0 {
c.Skip("requires running as root")
Expand Down
3 changes: 3 additions & 0 deletions internals/osutil/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func (ts *AtomicWriteTestSuite) TestAtomicWriteFileSymlinkNoFollow(c *C) {
c.Assert(os.Chmod(rodir, 0500), IsNil)
defer os.Chmod(rodir, 0700)

if os.Getuid() == 0 {
c.Skip("requires running as non-root users")
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
}
err := osutil.AtomicWriteFile(p, []byte("hi"), 0600, 0)
c.Assert(err, NotNil)
}
Expand Down
1 change: 0 additions & 1 deletion internals/osutil/mkdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ func (mkdirSuite) TestMakeParentsAndNoChmod(c *check.C) {
c.Assert(info.Mode().Perm(), check.Equals, os.FileMode(0o755))
}

// See .github/workflows/tests.yml for how to run this test as root.
func (mkdirSuite) TestMakeParentsChmodAndChown(c *check.C) {
if os.Getuid() != 0 {
c.Skip("requires running as root")
Expand Down
7 changes: 7 additions & 0 deletions internals/osutil/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ func makeTestPathInDir(c *C, dir string, path string, mode os.FileMode) string {
}

func (s *StatTestSuite) TestIsWritableDir(c *C) {
if os.Getuid() == 0 {
c.Skip("requires running as non-root users")
}

for _, t := range []struct {
path string
mode os.FileMode
Expand Down Expand Up @@ -180,6 +184,9 @@ func (s *StatTestSuite) TestExistsIsDir(c *C) {
c.Check(err, IsNil, comm)
}

if os.Getuid() == 0 {
c.Skip("requires running as non-root users")
}
p := makeTestPath(c, "foo/bar", 0)
c.Assert(os.Chmod(filepath.Dir(p), 0), IsNil)
defer os.Chmod(filepath.Dir(p), 0755)
Expand Down
1 change: 0 additions & 1 deletion internals/overlord/servstate/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ func (s *S) TestUserGroupFails(c *C) {
c.Check(gotGid, Equals, uint32(gid))
}

// See .github/workflows/tests.yml for how to run this test as root.
func (s *S) TestUserGroup(c *C) {
s.newServiceManager(c)
s.planAddLayer(c, testPlanLayer)
Expand Down
Loading