From 17d71eaa18bfeb07fab78ac13b1c4fca8379a6d0 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Fri, 10 Jul 2015 20:18:20 +0000 Subject: Rename cmd modules. --- cmd_help.go | 32 -------------------------------- cmd_help_test.go | 29 ----------------------------- cmd_pid.go | 27 --------------------------- cmd_pid_test.go | 25 ------------------------- cmd_ping.go | 19 ------------------- cmd_ping_test.go | 23 ----------------------- help.go | 32 ++++++++++++++++++++++++++++++++ help_test.go | 29 +++++++++++++++++++++++++++++ pid.go | 27 +++++++++++++++++++++++++++ pid_test.go | 25 +++++++++++++++++++++++++ ping.go | 19 +++++++++++++++++++ ping_test.go | 23 +++++++++++++++++++++++ 12 files changed, 155 insertions(+), 155 deletions(-) delete mode 100644 cmd_help.go delete mode 100644 cmd_help_test.go delete mode 100644 cmd_pid.go delete mode 100644 cmd_pid_test.go delete mode 100644 cmd_ping.go delete mode 100644 cmd_ping_test.go create mode 100644 help.go create mode 100644 help_test.go create mode 100644 pid.go create mode 100644 pid_test.go create mode 100644 ping.go create mode 100644 ping_test.go diff --git a/cmd_help.go b/cmd_help.go deleted file mode 100644 index b14471c..0000000 --- a/cmd_help.go +++ /dev/null @@ -1,32 +0,0 @@ -package goctl - -import ( - "fmt" - "sort" - "strings" -) - -type cmdHelp struct{} - -func (cmd cmdHelp) Name() string { - return "help" -} - -func (cmd cmdHelp) Help() string { - return "show this message" -} - -func (cmd cmdHelp) Run(gc *Goctl, args []string) string { - rc := []string{"Available commands:", ""} - cmds := []string{} - for _, h := range gc.handlers { - cmds = append(cmds, fmt.Sprintf("\t%s\t%s", h.Name(), h.Help())) - } - sort.Strings(cmds) - rc = append(rc, cmds...) - return strings.Join(rc, "\n") -} - -func init() { - builtinHandlers = append(builtinHandlers, cmdHelp{}) -} diff --git a/cmd_help_test.go b/cmd_help_test.go deleted file mode 100644 index 9c9a930..0000000 --- a/cmd_help_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package goctl - -import "testing" - -func TestHelp(t *testing.T) { - gc := start(t) - defer gc.Stop() - - c := dial(t) - defer c.Close() - - buf := []byte("help") - Write(c, buf) - - buf, err := Read(c) - if err != nil { - t.Fatalf("Couldn't read from socket: %s.", err) - } - - got := string(buf) - want := `Available commands: - - help show this message - pid return the Unix process ID of this program - ping checks whether the connection is working` - if got != want { - t.Errorf("Didn't get proper help response.\nGot:\n'%s',\nWant:\n'%s'", got, want) - } -} diff --git a/cmd_pid.go b/cmd_pid.go deleted file mode 100644 index 3bdb1f3..0000000 --- a/cmd_pid.go +++ /dev/null @@ -1,27 +0,0 @@ -package goctl - -import ( - "os" - "strconv" -) - -var pid string - -type cmdPID struct{} - -func (cmd cmdPID) Name() string { - return "pid" -} - -func (cmd cmdPID) Help() string { - return "return the Unix process ID of this program" -} - -func (cmd cmdPID) Run(_ *Goctl, _ []string) string { - return pid -} - -func init() { - pid = strconv.Itoa(os.Getpid()) - builtinHandlers = append(builtinHandlers, cmdPID{}) -} diff --git a/cmd_pid_test.go b/cmd_pid_test.go deleted file mode 100644 index 681b116..0000000 --- a/cmd_pid_test.go +++ /dev/null @@ -1,25 +0,0 @@ -package goctl - -import ( - "strconv" - "testing" -) - -func TestPID(t *testing.T) { - gc := start(t) - defer gc.Stop() - - c := dial(t) - defer c.Close() - - buf := []byte("pid") - Write(c, buf) - - buf, err := Read(c) - if err != nil { - t.Fatalf("Couldn't read from socket: %s.", err) - } - if _, err = strconv.Atoi(string(buf)); err != nil { - t.Errorf("Requesting PID: got non-integer: '%s'.", string(buf)) - } -} diff --git a/cmd_ping.go b/cmd_ping.go deleted file mode 100644 index 48294ea..0000000 --- a/cmd_ping.go +++ /dev/null @@ -1,19 +0,0 @@ -package goctl - -type cmdPing struct{} - -func (cmd *cmdPing) Name() string { - return "ping" -} - -func (cmd cmdPing) Help() string { - return "checks whether the connection is working" -} - -func (cmd *cmdPing) Run(_ *Goctl, _ []string) string { - return "pong" -} - -func init() { - builtinHandlers = append(builtinHandlers, &cmdPing{}) -} diff --git a/cmd_ping_test.go b/cmd_ping_test.go deleted file mode 100644 index 89a08c7..0000000 --- a/cmd_ping_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package goctl - -import "testing" - -func TestPing(t *testing.T) { - gc := start(t) - defer gc.Stop() - - c := dial(t) - defer c.Close() - - buf := []byte("ping") - Write(c, buf) - - buf, err := Read(c) - if err != nil { - t.Fatalf("Couldn't read from socket: %s.", err) - } - s := string(buf) - if s != "pong" { - t.Errorf("Sending ping: got '%s', expected 'pong'.", s) - } -} diff --git a/help.go b/help.go new file mode 100644 index 0000000..b14471c --- /dev/null +++ b/help.go @@ -0,0 +1,32 @@ +package goctl + +import ( + "fmt" + "sort" + "strings" +) + +type cmdHelp struct{} + +func (cmd cmdHelp) Name() string { + return "help" +} + +func (cmd cmdHelp) Help() string { + return "show this message" +} + +func (cmd cmdHelp) Run(gc *Goctl, args []string) string { + rc := []string{"Available commands:", ""} + cmds := []string{} + for _, h := range gc.handlers { + cmds = append(cmds, fmt.Sprintf("\t%s\t%s", h.Name(), h.Help())) + } + sort.Strings(cmds) + rc = append(rc, cmds...) + return strings.Join(rc, "\n") +} + +func init() { + builtinHandlers = append(builtinHandlers, cmdHelp{}) +} diff --git a/help_test.go b/help_test.go new file mode 100644 index 0000000..9c9a930 --- /dev/null +++ b/help_test.go @@ -0,0 +1,29 @@ +package goctl + +import "testing" + +func TestHelp(t *testing.T) { + gc := start(t) + defer gc.Stop() + + c := dial(t) + defer c.Close() + + buf := []byte("help") + Write(c, buf) + + buf, err := Read(c) + if err != nil { + t.Fatalf("Couldn't read from socket: %s.", err) + } + + got := string(buf) + want := `Available commands: + + help show this message + pid return the Unix process ID of this program + ping checks whether the connection is working` + if got != want { + t.Errorf("Didn't get proper help response.\nGot:\n'%s',\nWant:\n'%s'", got, want) + } +} diff --git a/pid.go b/pid.go new file mode 100644 index 0000000..3bdb1f3 --- /dev/null +++ b/pid.go @@ -0,0 +1,27 @@ +package goctl + +import ( + "os" + "strconv" +) + +var pid string + +type cmdPID struct{} + +func (cmd cmdPID) Name() string { + return "pid" +} + +func (cmd cmdPID) Help() string { + return "return the Unix process ID of this program" +} + +func (cmd cmdPID) Run(_ *Goctl, _ []string) string { + return pid +} + +func init() { + pid = strconv.Itoa(os.Getpid()) + builtinHandlers = append(builtinHandlers, cmdPID{}) +} diff --git a/pid_test.go b/pid_test.go new file mode 100644 index 0000000..681b116 --- /dev/null +++ b/pid_test.go @@ -0,0 +1,25 @@ +package goctl + +import ( + "strconv" + "testing" +) + +func TestPID(t *testing.T) { + gc := start(t) + defer gc.Stop() + + c := dial(t) + defer c.Close() + + buf := []byte("pid") + Write(c, buf) + + buf, err := Read(c) + if err != nil { + t.Fatalf("Couldn't read from socket: %s.", err) + } + if _, err = strconv.Atoi(string(buf)); err != nil { + t.Errorf("Requesting PID: got non-integer: '%s'.", string(buf)) + } +} diff --git a/ping.go b/ping.go new file mode 100644 index 0000000..48294ea --- /dev/null +++ b/ping.go @@ -0,0 +1,19 @@ +package goctl + +type cmdPing struct{} + +func (cmd *cmdPing) Name() string { + return "ping" +} + +func (cmd cmdPing) Help() string { + return "checks whether the connection is working" +} + +func (cmd *cmdPing) Run(_ *Goctl, _ []string) string { + return "pong" +} + +func init() { + builtinHandlers = append(builtinHandlers, &cmdPing{}) +} diff --git a/ping_test.go b/ping_test.go new file mode 100644 index 0000000..89a08c7 --- /dev/null +++ b/ping_test.go @@ -0,0 +1,23 @@ +package goctl + +import "testing" + +func TestPing(t *testing.T) { + gc := start(t) + defer gc.Stop() + + c := dial(t) + defer c.Close() + + buf := []byte("ping") + Write(c, buf) + + buf, err := Read(c) + if err != nil { + t.Fatalf("Couldn't read from socket: %s.", err) + } + s := string(buf) + if s != "pong" { + t.Errorf("Sending ping: got '%s', expected 'pong'.", s) + } +} -- cgit v1.2.3