util/osuser: add unit test for parseGroupIds

Updates #11682

Signed-off-by: Percy Wegmann <percy@tailscale.com>
This commit is contained in:
Percy Wegmann
2024-04-22 20:34:43 -05:00
committed by Percy Wegmann
parent e985c6e58f
commit b7e5122226
2 changed files with 31 additions and 1 deletions

View File

@@ -46,5 +46,9 @@ func getGroupIdsWithId(usernameOrUID string) ([]string, error) {
if err != nil {
return nil, fmt.Errorf("running 'id' command: %w", err)
}
return strings.Split(string(out), "\x00"), nil
return parseGroupIds(out), nil
}
func parseGroupIds(cmdOutput []byte) []string {
return strings.Split(strings.Trim(string(cmdOutput), "\n\x00"), "\x00")
}