Introduce client/server separation

Refactor to introduce client/server separation, including a typed
client API and a HTTP REST server implementation.

Refactor the terminal to be an API consumer.
This commit is contained in:
Dan Mace
2015-03-20 17:11:11 -04:00
committed by Derek Parker
parent 288248d048
commit 2954e03a20
13 changed files with 2418 additions and 240 deletions

53
terminal/command_test.go Normal file
View File

@ -0,0 +1,53 @@
package terminal
import (
"fmt"
"testing"
"github.com/derekparker/delve/service"
)
func TestCommandDefault(t *testing.T) {
var (
cmds = Commands{}
cmd = cmds.Find("non-existant-command")
)
err := cmd(nil)
if err == nil {
t.Fatal("cmd() did not default")
}
if err.Error() != "command not available" {
t.Fatal("wrong command output")
}
}
func TestCommandReplay(t *testing.T) {
cmds := DebugCommands(nil)
cmds.Register("foo", func(client service.Client, args ...string) error { return fmt.Errorf("registered command") }, "foo command")
cmd := cmds.Find("foo")
err := cmd(nil)
if err.Error() != "registered command" {
t.Fatal("wrong command output")
}
cmd = cmds.Find("")
err = cmd(nil)
if err.Error() != "registered command" {
t.Fatal("wrong command output")
}
}
func TestCommandReplayWithoutPreviousCommand(t *testing.T) {
var (
cmds = DebugCommands(nil)
cmd = cmds.Find("")
err = cmd(nil)
)
if err != nil {
t.Error("Null command not returned", err)
}
}