refactor(ax): remove redundant compatibility surfaces
This commit is contained in:
parent
bcf780c0ac
commit
a290cba908
3 changed files with 2 additions and 41 deletions
12
io.go
12
io.go
|
|
@ -188,8 +188,6 @@ type MemoryMedium struct {
|
|||
modTimes map[string]time.Time
|
||||
}
|
||||
|
||||
type MockMedium = MemoryMedium
|
||||
|
||||
var _ Medium = (*MemoryMedium)(nil)
|
||||
|
||||
// Example: medium := io.NewMemoryMedium()
|
||||
|
|
@ -202,12 +200,6 @@ func NewMemoryMedium() *MemoryMedium {
|
|||
}
|
||||
}
|
||||
|
||||
// Example: medium := io.NewMockMedium()
|
||||
// Example: _ = medium.Write("config/app.yaml", "port: 8080")
|
||||
func NewMockMedium() *MemoryMedium {
|
||||
return NewMemoryMedium()
|
||||
}
|
||||
|
||||
func (medium *MemoryMedium) Read(path string) (string, error) {
|
||||
content, ok := medium.files[path]
|
||||
if !ok {
|
||||
|
|
@ -399,8 +391,6 @@ type MemoryFile struct {
|
|||
offset int64
|
||||
}
|
||||
|
||||
type MockFile = MemoryFile
|
||||
|
||||
func (file *MemoryFile) Stat() (fs.FileInfo, error) {
|
||||
return NewFileInfo(file.name, int64(len(file.content)), 0, time.Time{}, false), nil
|
||||
}
|
||||
|
|
@ -424,8 +414,6 @@ type MemoryWriteCloser struct {
|
|||
data []byte
|
||||
}
|
||||
|
||||
type MockWriteCloser = MemoryWriteCloser
|
||||
|
||||
func (writeCloser *MemoryWriteCloser) Write(data []byte) (int, error) {
|
||||
writeCloser.data = append(writeCloser.data, data...)
|
||||
return len(data), nil
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ type KeyPairProvider interface {
|
|||
CreateKeyPair(name, passphrase string) (string, error)
|
||||
}
|
||||
|
||||
type CryptProvider = KeyPairProvider
|
||||
|
||||
const (
|
||||
WorkspaceCreateAction = "workspace.create"
|
||||
WorkspaceSwitchAction = "workspace.switch"
|
||||
|
|
@ -42,7 +40,6 @@ type WorkspaceCommand struct {
|
|||
// Example: service, _ := workspace.New(workspace.Options{KeyPairProvider: keyPairProvider})
|
||||
type Options struct {
|
||||
KeyPairProvider KeyPairProvider
|
||||
CryptProvider CryptProvider
|
||||
}
|
||||
|
||||
// Example: service, _ := workspace.New(workspace.Options{KeyPairProvider: keyPairProvider})
|
||||
|
|
@ -65,16 +62,12 @@ func New(options Options) (*Service, error) {
|
|||
}
|
||||
rootPath := core.Path(home, ".core", "workspaces")
|
||||
|
||||
keyPairProvider := options.KeyPairProvider
|
||||
if keyPairProvider == nil {
|
||||
keyPairProvider = options.CryptProvider
|
||||
}
|
||||
if keyPairProvider == nil {
|
||||
if options.KeyPairProvider == nil {
|
||||
return nil, core.E("workspace.New", "key pair provider is required", fs.ErrInvalid)
|
||||
}
|
||||
|
||||
service := &Service{
|
||||
keyPairProvider: keyPairProvider,
|
||||
keyPairProvider: options.KeyPairProvider,
|
||||
rootPath: rootPath,
|
||||
medium: io.Local,
|
||||
}
|
||||
|
|
@ -208,11 +201,6 @@ func (service *Service) HandleWorkspaceMessage(_ *core.Core, message core.Messag
|
|||
return service.HandleWorkspaceCommand(command)
|
||||
}
|
||||
|
||||
// Example: result := service.HandleIPCEvents(core.New(), WorkspaceCommand{Action: WorkspaceSwitchAction, WorkspaceID: "f3f0d7"})
|
||||
func (service *Service) HandleIPCEvents(coreRuntime *core.Core, message core.Message) core.Result {
|
||||
return service.HandleWorkspaceMessage(coreRuntime, message)
|
||||
}
|
||||
|
||||
func workspaceCommandFromMessage(message core.Message) (WorkspaceCommand, bool) {
|
||||
switch payload := message.(type) {
|
||||
case WorkspaceCommand:
|
||||
|
|
|
|||
|
|
@ -148,18 +148,3 @@ func TestService_HandleWorkspaceMessage_Good(t *testing.T) {
|
|||
unknown := service.HandleWorkspaceMessage(core.New(), "noop")
|
||||
assert.True(t, unknown.OK)
|
||||
}
|
||||
|
||||
func TestService_HandleIPCEvents_Compatibility_Good(t *testing.T) {
|
||||
service, _ := newTestService(t)
|
||||
|
||||
result := service.HandleIPCEvents(core.New(), WorkspaceCommand{
|
||||
Action: WorkspaceCreateAction,
|
||||
Identifier: "compat-user",
|
||||
Password: "pass123",
|
||||
})
|
||||
|
||||
assert.True(t, result.OK)
|
||||
workspaceID, ok := result.Value.(string)
|
||||
require.True(t, ok)
|
||||
require.NotEmpty(t, workspaceID)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue