fix(process): harden program helpers and health schema
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
8a6c253ea2
commit
0e4dde9307
4 changed files with 24 additions and 2 deletions
|
|
@ -10,10 +10,10 @@ import (
|
|||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"forge.lthn.ai/core/api"
|
||||
"forge.lthn.ai/core/api/pkg/provider"
|
||||
process "dappco.re/go/core/process"
|
||||
"dappco.re/go/core/ws"
|
||||
"forge.lthn.ai/core/api"
|
||||
"forge.lthn.ai/core/api/pkg/provider"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
|
@ -119,6 +119,8 @@ func (p *ProcessProvider) Describe() []api.RouteDescription {
|
|||
"daemon": map[string]any{"type": "string"},
|
||||
"pid": map[string]any{"type": "integer"},
|
||||
"health": map[string]any{"type": "string"},
|
||||
"project": map[string]any{"type": "string"},
|
||||
"binary": map[string]any{"type": "string"},
|
||||
"started": map[string]any{"type": "string", "format": "date-time"},
|
||||
},
|
||||
},
|
||||
|
|
@ -147,6 +149,7 @@ func (p *ProcessProvider) Describe() []api.RouteDescription {
|
|||
"properties": map[string]any{
|
||||
"healthy": map[string]any{"type": "boolean"},
|
||||
"address": map[string]any{"type": "string"},
|
||||
"reason": map[string]any{"type": "string"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -49,6 +49,14 @@ func TestProcessProvider_Describe_Good(t *testing.T) {
|
|||
assert.NotEmpty(t, d.Summary)
|
||||
assert.NotEmpty(t, d.Tags)
|
||||
}
|
||||
|
||||
for _, d := range descs {
|
||||
if d.Path == "/daemons/:code/:daemon/health" {
|
||||
props, ok := d.Response["properties"].(map[string]any)
|
||||
require.True(t, ok)
|
||||
assert.Contains(t, props, "reason")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessProvider_ListDaemons_Good(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ func (p *Program) RunDir(ctx context.Context, dir string, args ...string) (strin
|
|||
if binary == "" {
|
||||
binary = p.Name
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
cmd := execCommandContext(ctx, binary, args...)
|
||||
|
|
|
|||
|
|
@ -56,6 +56,14 @@ func TestProgram_RunFallback_Good(t *testing.T) {
|
|||
assert.Equal(t, "fallback", out)
|
||||
}
|
||||
|
||||
func TestProgram_RunNilContext_Good(t *testing.T) {
|
||||
p := &process.Program{Name: "echo"}
|
||||
|
||||
out, err := p.Run(nil, "nil-context")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "nil-context", out)
|
||||
}
|
||||
|
||||
func TestProgram_RunDir_Good(t *testing.T) {
|
||||
p := &process.Program{Name: "pwd"}
|
||||
require.NoError(t, p.Find())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue