refactor(ax): remove workspace message compatibility map
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
38066a6fae
commit
3054217038
2 changed files with 4 additions and 51 deletions
|
|
@ -192,28 +192,12 @@ func (service *Service) HandleWorkspaceCommand(command WorkspaceCommand) core.Re
|
|||
}
|
||||
|
||||
// Example: result := service.HandleWorkspaceMessage(core.New(), WorkspaceCommand{Action: WorkspaceSwitchAction, WorkspaceID: "f3f0d7"})
|
||||
// Example: legacy := service.HandleWorkspaceMessage(core.New(), map[string]any{"action": WorkspaceCreateAction, "identifier": "alice", "password": "pass123"})
|
||||
func (service *Service) HandleWorkspaceMessage(_ *core.Core, message core.Message) core.Result {
|
||||
command, ok := workspaceCommandFromMessage(message)
|
||||
if !ok {
|
||||
return core.Result{OK: true}
|
||||
}
|
||||
return service.HandleWorkspaceCommand(command)
|
||||
}
|
||||
|
||||
func workspaceCommandFromMessage(message core.Message) (WorkspaceCommand, bool) {
|
||||
switch payload := message.(type) {
|
||||
switch command := message.(type) {
|
||||
case WorkspaceCommand:
|
||||
return payload, true
|
||||
case map[string]any:
|
||||
command := WorkspaceCommand{}
|
||||
command.Action, _ = payload["action"].(string)
|
||||
command.Identifier, _ = payload["identifier"].(string)
|
||||
command.Password, _ = payload["password"].(string)
|
||||
command.WorkspaceID, _ = payload["workspaceID"].(string)
|
||||
return command, true
|
||||
return service.HandleWorkspaceCommand(command)
|
||||
}
|
||||
return WorkspaceCommand{}, false
|
||||
return core.Result{OK: true}
|
||||
}
|
||||
|
||||
func resolveWorkspaceHomeDirectory() string {
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ func TestService_WriteWorkspaceFile_TraversalBlocked_Bad(t *testing.T) {
|
|||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestService_HandleWorkspaceMessage_Good(t *testing.T) {
|
||||
func TestService_HandleWorkspaceMessage_Command_Good(t *testing.T) {
|
||||
service, _ := newTestService(t)
|
||||
|
||||
create := service.HandleWorkspaceMessage(core.New(), WorkspaceCommand{
|
||||
|
|
@ -114,37 +114,6 @@ func TestService_HandleWorkspaceMessage_Good(t *testing.T) {
|
|||
assert.True(t, switchResult.OK)
|
||||
assert.Equal(t, workspaceID, service.activeWorkspaceID)
|
||||
|
||||
legacyCreate := service.HandleWorkspaceMessage(core.New(), map[string]any{
|
||||
"action": WorkspaceCreateAction,
|
||||
"identifier": "legacy-user",
|
||||
"password": "pass123",
|
||||
})
|
||||
assert.True(t, legacyCreate.OK)
|
||||
|
||||
legacyWorkspaceID, ok := legacyCreate.Value.(string)
|
||||
require.True(t, ok)
|
||||
require.NotEmpty(t, legacyWorkspaceID)
|
||||
|
||||
legacySwitch := service.HandleWorkspaceMessage(core.New(), WorkspaceCommand{
|
||||
Action: WorkspaceSwitchAction,
|
||||
WorkspaceID: legacyWorkspaceID,
|
||||
})
|
||||
assert.True(t, legacySwitch.OK)
|
||||
assert.Equal(t, legacyWorkspaceID, service.activeWorkspaceID)
|
||||
|
||||
rejectedLegacySwitch := service.HandleWorkspaceMessage(core.New(), map[string]any{
|
||||
"action": WorkspaceSwitchAction,
|
||||
"name": workspaceID,
|
||||
})
|
||||
assert.False(t, rejectedLegacySwitch.OK)
|
||||
assert.Equal(t, legacyWorkspaceID, service.activeWorkspaceID)
|
||||
|
||||
failedSwitch := service.HandleWorkspaceMessage(core.New(), map[string]any{
|
||||
"action": WorkspaceSwitchAction,
|
||||
"workspaceID": "missing",
|
||||
})
|
||||
assert.False(t, failedSwitch.OK)
|
||||
|
||||
unknown := service.HandleWorkspaceMessage(core.New(), "noop")
|
||||
assert.True(t, unknown.OK)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue