Skip to content

Commit

Permalink
add proper cleanup callback
Browse files Browse the repository at this point in the history
  • Loading branch information
fearful-symmetry committed Mar 4, 2024
1 parent b784e52 commit ea6fba2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions metric/system/process/process_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ func TestRunningProcessFromOtherUser(t *testing.T) {
require.NoError(t, err)
t.Logf("uid: %v", uid)

t.Cleanup(func() {
// not sure how ephemeral the CI environment is, but delete the user anyway
cmd := exec.Command("userdel", "-f", testUsername)
output, err := cmd.CombinedOutput()
require.NoError(t, err, "got error deleting user: %s", string(output))
})

cmdHandler := exec.Command("sleep", "60")
cmdHandler.SysProcAttr = &syscall.SysProcAttr{Credential: &syscall.Credential{Uid: uint32(uid), Gid: 0}}

Expand Down Expand Up @@ -122,10 +129,6 @@ func TestRunningProcessFromOtherUser(t *testing.T) {
require.NotZero(t, result["memory"].(map[string]interface{})["size"])
t.Logf("got result: %s", result["username"])

// not sure how ephemeral the Ci environment is, but delete the user anyway
cmd := exec.Command("userdel", "-f", testUsername)
output, err := cmd.CombinedOutput()
require.NoError(t, err, "got error deleting user: %s", string(output))
}

func TestFetchProcessFromOtherUser(t *testing.T) {
Expand Down

0 comments on commit ea6fba2

Please sign in to comment.