test(scum): cover supported companion adapters
This commit is contained in:
@@ -2,12 +2,15 @@ package companion
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
var errAdapterUnsupported = errors.New("versioned adapter is unsupported")
|
||||
|
||||
// AuthorizedConfigPort is supplied by a version-bound Companion integration.
|
||||
// It exposes logical configuration values only: never a host path, connection
|
||||
// string, credential, arbitrary command, or direct database handle.
|
||||
@@ -75,9 +78,11 @@ type VersionedAdapter struct {
|
||||
DiagnosticsState map[string]string
|
||||
}
|
||||
|
||||
func (adapter VersionedAdapter) ServerBinding() string { return adapter.BoundServerID }
|
||||
|
||||
func (adapter VersionedAdapter) ReadConfiguration(ctx context.Context) (map[string]any, error) {
|
||||
if !supportedAdapterVersion(adapter.ServerVersion) || adapter.Config == nil {
|
||||
return nil, fmt.Errorf("configuration adapter is unsupported")
|
||||
return nil, errAdapterUnsupported
|
||||
}
|
||||
fields, err := adapter.Config.ReadConfig(ctx)
|
||||
if err != nil {
|
||||
@@ -87,7 +92,7 @@ func (adapter VersionedAdapter) ReadConfiguration(ctx context.Context) (map[stri
|
||||
}
|
||||
func (adapter VersionedAdapter) PatchConfiguration(ctx context.Context, payload map[string]any) (map[string]any, error) {
|
||||
if !supportedAdapterVersion(adapter.ServerVersion) || adapter.Config == nil {
|
||||
return nil, fmt.Errorf("configuration adapter is unsupported")
|
||||
return nil, errAdapterUnsupported
|
||||
}
|
||||
revision, _ := payload["revision"].(string)
|
||||
raw, _ := payload["fields"].([]any)
|
||||
@@ -120,14 +125,14 @@ func (adapter VersionedAdapter) Diagnostics(context.Context) (map[string]any, er
|
||||
return state, nil
|
||||
}
|
||||
func (VersionedAdapter) PatchGameState(context.Context, map[string]any) (map[string]any, error) {
|
||||
return nil, fmt.Errorf("state adapter is unsupported")
|
||||
return nil, errAdapterUnsupported
|
||||
}
|
||||
func (VersionedAdapter) DeliverReward(context.Context, map[string]any) (map[string]any, error) {
|
||||
return nil, fmt.Errorf("reward adapter is unsupported")
|
||||
return nil, errAdapterUnsupported
|
||||
}
|
||||
func (adapter VersionedAdapter) NotifyPlayer(ctx context.Context, payload map[string]any) (map[string]any, error) {
|
||||
if !adapter.supportsPinnedUE4SS() || adapter.Notification == nil {
|
||||
return nil, fmt.Errorf("notification adapter is unsupported")
|
||||
return nil, errAdapterUnsupported
|
||||
}
|
||||
playerID, playerOK := payload["playerId"].(string)
|
||||
message, messageOK := payload["message"].(string)
|
||||
@@ -146,7 +151,7 @@ func (adapter VersionedAdapter) NotifyPlayer(ctx context.Context, payload map[st
|
||||
}
|
||||
func (adapter VersionedAdapter) SpawnVehicle(ctx context.Context, payload map[string]any) (map[string]any, error) {
|
||||
if !adapter.supportsPinnedUE4SS() || adapter.VehicleSpawn == nil {
|
||||
return nil, fmt.Errorf("vehicle spawn adapter is unsupported")
|
||||
return nil, errAdapterUnsupported
|
||||
}
|
||||
vehicleCode, ok := payload["vehicleCode"].(string)
|
||||
spawn, err := newUE4SSVehicleSpawn(adapter.BoundServerID, vehicleCode)
|
||||
|
||||
Reference in New Issue
Block a user