cmd/hakurei/print: serialise array for ps
Some checks failed
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m15s
Test / Hakurei (push) Failing after 2m39s
Test / Hpkg (push) Failing after 4m8s
Test / Sandbox (race detector) (push) Successful in 4m10s
Test / Hakurei (race detector) (push) Failing after 4m23s
Test / Flake checks (push) Has been skipped
Some checks failed
Test / Create distribution (push) Successful in 35s
Test / Sandbox (push) Successful in 2m15s
Test / Hakurei (push) Failing after 2m39s
Test / Hpkg (push) Failing after 4m8s
Test / Sandbox (race detector) (push) Successful in 4m10s
Test / Hakurei (race detector) (push) Failing after 4m23s
Test / Flake checks (push) Has been skipped
Wanted to do this for a long time, since the key is redundant. This also makes it easier to migrate to the new store interface. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
23ae7822bf
commit
638e79cd8e
@ -1,9 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"maps"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -177,10 +179,8 @@ func printPs(output io.Writer, now time.Time, s store.Compat, short, flagJSON bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !short && flagJSON {
|
if !short && flagJSON {
|
||||||
es := make(map[string]*hst.State, len(entries))
|
es := slices.Collect(maps.Values(entries))
|
||||||
for id, instance := range entries {
|
slices.SortFunc(es, func(a, b *hst.State) int { return bytes.Compare(a.ID[:], b.ID[:]) })
|
||||||
es[id.String()] = instance
|
|
||||||
}
|
|
||||||
encodeJSON(log.Fatal, output, short, es)
|
encodeJSON(log.Fatal, output, short, es)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"hakurei.app/container/check"
|
||||||
"hakurei.app/hst"
|
"hakurei.app/hst"
|
||||||
"hakurei.app/internal/store"
|
"hakurei.app/internal/store"
|
||||||
)
|
)
|
||||||
@ -530,8 +532,25 @@ func TestPrintPs(t *testing.T) {
|
|||||||
4cf073bd 3405691582 9 (org.chromium.Chromium) 1h2m32s
|
4cf073bd 3405691582 9 (org.chromium.Chromium) 1h2m32s
|
||||||
`},
|
`},
|
||||||
{"valid short", map[hst.ID]*hst.State{testID: testState}, true, false, "4cf073bd\n"},
|
{"valid short", map[hst.ID]*hst.State{testID: testState}, true, false, "4cf073bd\n"},
|
||||||
{"valid json", map[hst.ID]*hst.State{testID: testState}, false, true, `{
|
{"valid json", map[hst.ID]*hst.State{testID: testState, (hst.ID)(bytes.Repeat([]byte{0xaa}, len(hst.ID{}))): {
|
||||||
"8e2c76b066dabe574cf073bdb46eb5c1": {
|
ID: (hst.ID)(bytes.Repeat([]byte{0xaa}, len(hst.ID{}))),
|
||||||
|
PID: 0xbeef,
|
||||||
|
ShimPID: 0xcafe,
|
||||||
|
Config: &hst.Config{
|
||||||
|
ID: "uk.gensokyo.cat",
|
||||||
|
Enablements: hst.NewEnablements(hst.EWayland | hst.EPulse),
|
||||||
|
Identity: 1,
|
||||||
|
Container: &hst.ContainerConfig{
|
||||||
|
Shell: check.MustAbs("/bin/sh"),
|
||||||
|
Home: check.MustAbs("/data/data/uk.gensokyo.cat"),
|
||||||
|
Path: check.MustAbs("/usr/bin/cat"),
|
||||||
|
Args: []string{"cat"},
|
||||||
|
Flags: hst.FUserns,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Time: time.Unix(0, 0xdeadbeef).UTC(),
|
||||||
|
}}, false, true, `[
|
||||||
|
{
|
||||||
"instance": "8e2c76b066dabe574cf073bdb46eb5c1",
|
"instance": "8e2c76b066dabe574cf073bdb46eb5c1",
|
||||||
"pid": 3405691582,
|
"pid": 3405691582,
|
||||||
"shim_pid": 3735928559,
|
"shim_pid": 3735928559,
|
||||||
@ -683,8 +702,33 @@ func TestPrintPs(t *testing.T) {
|
|||||||
"share_tmpdir": true
|
"share_tmpdir": true
|
||||||
},
|
},
|
||||||
"time": "1970-01-01T00:00:00.000000009Z"
|
"time": "1970-01-01T00:00:00.000000009Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"instance": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||||
|
"pid": 48879,
|
||||||
|
"shim_pid": 51966,
|
||||||
|
"id": "uk.gensokyo.cat",
|
||||||
|
"enablements": {
|
||||||
|
"wayland": true,
|
||||||
|
"pulse": true
|
||||||
|
},
|
||||||
|
"identity": 1,
|
||||||
|
"groups": null,
|
||||||
|
"container": {
|
||||||
|
"env": null,
|
||||||
|
"filesystem": null,
|
||||||
|
"shell": "/bin/sh",
|
||||||
|
"home": "/data/data/uk.gensokyo.cat",
|
||||||
|
"path": "/usr/bin/cat",
|
||||||
|
"args": [
|
||||||
|
"cat"
|
||||||
|
],
|
||||||
|
"userns": true,
|
||||||
|
"map_real_uid": false
|
||||||
|
},
|
||||||
|
"time": "1970-01-01T00:00:03.735928559Z"
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
`},
|
`},
|
||||||
{"valid short json", map[hst.ID]*hst.State{testID: testState}, true, true, `["8e2c76b066dabe574cf073bdb46eb5c1"]
|
{"valid short json", map[hst.ID]*hst.State{testID: testState}, true, true, `["8e2c76b066dabe574cf073bdb46eb5c1"]
|
||||||
`},
|
`},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user