39 lines
926 B
Go
39 lines
926 B
Go
package Podman_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"gitea.narnian.us/lordwelch/Podman"
|
|
)
|
|
|
|
// passwdContent is specifically not in order
|
|
const passwdContent = `root:x:0:0:root:/perm/home:/perm/bin/bash
|
|
vw:x:2:2:vw:/perm/home/vw:/bin/nologin
|
|
jellyfin:x:1:1:jellyfin:/perm/home/jellyfin:/bin/nologin
|
|
nzbget:x:3:3:nzbget:/perm/home/nzbget:/bin/nologin
|
|
`
|
|
|
|
// expected is always in uid order
|
|
const expected = `root:200:65536
|
|
jellyfin:65736:65536
|
|
vw:131272:65536
|
|
nzbget:196808:65536
|
|
`
|
|
|
|
func TestGetSubids(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
passwd := tmpDir + "/passwd"
|
|
err := os.WriteFile(passwd, []byte(passwdContent), 0o644)
|
|
if err != nil {
|
|
t.Fatalf("Unable to write %s: %s", passwd, err)
|
|
}
|
|
ids, err := Podman.GetSubids(passwd)
|
|
if err != nil {
|
|
t.Fatal("Unable to generate subids", err)
|
|
}
|
|
if got, want := string(ids), expected; got != want {
|
|
t.Errorf("GetSubids: unexpected result: got %q, want %q", got, want)
|
|
}
|
|
}
|