Initial project snapshot
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package supervisor
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/client"
|
||||
)
|
||||
|
||||
type Supervisor interface {
|
||||
Apply(ctx context.Context, desired []client.DesiredWorkload) ([]client.WorkloadStatusRequest, error)
|
||||
}
|
||||
|
||||
type StubSupervisor struct {
|
||||
Version string
|
||||
}
|
||||
|
||||
func (s StubSupervisor) Apply(_ context.Context, desired []client.DesiredWorkload) ([]client.WorkloadStatusRequest, error) {
|
||||
statuses := make([]client.WorkloadStatusRequest, 0, len(desired))
|
||||
for _, workload := range desired {
|
||||
state := "degraded"
|
||||
if workload.DesiredState == "disabled" {
|
||||
state = "stopped"
|
||||
}
|
||||
version := workload.Version
|
||||
if version == "" {
|
||||
version = s.Version
|
||||
}
|
||||
statuses = append(statuses, client.WorkloadStatusRequest{
|
||||
ReportedState: state,
|
||||
RuntimeMode: workload.RuntimeMode,
|
||||
Version: version,
|
||||
StatusPayload: map[string]any{
|
||||
"supervisor": "stub",
|
||||
"desired_state": workload.DesiredState,
|
||||
"service_type": workload.ServiceType,
|
||||
},
|
||||
})
|
||||
}
|
||||
return statuses, nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package supervisor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/example/remote-access-platform/agents/rap-node-agent/internal/client"
|
||||
)
|
||||
|
||||
func TestStubSupervisorReportsDegradedForEnabledWorkload(t *testing.T) {
|
||||
statuses, err := (StubSupervisor{Version: "test"}).Apply(context.Background(), []client.DesiredWorkload{
|
||||
{ServiceType: "rdp-worker", DesiredState: "enabled", RuntimeMode: "container"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("apply desired workload: %v", err)
|
||||
}
|
||||
if len(statuses) != 1 {
|
||||
t.Fatalf("statuses length = %d", len(statuses))
|
||||
}
|
||||
if statuses[0].ReportedState != "degraded" {
|
||||
t.Fatalf("ReportedState = %q", statuses[0].ReportedState)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStubSupervisorReportsStoppedForDisabledWorkload(t *testing.T) {
|
||||
statuses, err := (StubSupervisor{Version: "test"}).Apply(context.Background(), []client.DesiredWorkload{
|
||||
{ServiceType: "relay-node", DesiredState: "disabled", RuntimeMode: "container"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("apply desired workload: %v", err)
|
||||
}
|
||||
if statuses[0].ReportedState != "stopped" {
|
||||
t.Fatalf("ReportedState = %q", statuses[0].ReportedState)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user