Skip to content

Commit

Permalink
Change event handler type name
Browse files Browse the repository at this point in the history
  • Loading branch information
moncho committed Apr 23, 2017
1 parent 316c8d6 commit 1cdaccd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
6 changes: 4 additions & 2 deletions appui/event.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package appui

type EventHandler func(string) error
//EventCommand type alias for a func to be run by an Actionable
type EventCommand func(string) error

//Actionable interface describes how widgets run commands as a result of an event
type Actionable interface {
OnEvent(EventHandler) error
OnEvent(EventCommand) error
}
3 changes: 2 additions & 1 deletion appui/swarm_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ func (s *SwarmNodesWidget) highlightSelectedRow() {
s.nodes[s.selectedIndex].Highlighted()
}

func (s *SwarmNodesWidget) OnEvent(event EventHandler) error {
//OnEvent runs the given command
func (s *SwarmNodesWidget) OnEvent(event EventCommand) error {
return event(s.nodes[s.selectedIndex].node.ID)
}

Expand Down
51 changes: 51 additions & 0 deletions appui/task_row_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package appui

import (
"testing"

"github.com/docker/docker/api/types/swarm"
"github.com/moncho/dry/docker/formatter"
)

func TestTaskRow(t *testing.T) {
task := swarm.Task{
ID: "task1",
Annotations: swarm.Annotations{Name: "taskName"},
Spec: swarm.TaskSpec{},
}

ts := formatter.NewTaskStringer(task)
row := NewTaskRow(task)

if row == nil {
t.Error("TaskRow was not created")
}

if row.ID.Text != task.ID {
t.Errorf("TaskRow name is not 'test', got %s", row.ID.Text)
}

if row.Name.Text != task.Name {
t.Errorf("TaskRow name is not 'test', got %s", row.Name.Text)
}

if row.Image.Text != ts.Image() {
t.Errorf("Unexpected TaskRow image, got %s, expected %s", row.Image.Text, ts.Image())
}
if row.Node.Text != ts.NodeID() {
t.Errorf("Unexpected TaskRow node, got %s, expected %s", row.Node.Text, ts.NodeID())
}
if row.DesiredState.Text != ts.DesiredState() {
t.Errorf("Unexpected TaskRow DesiredState, got %s, expected %s", row.DesiredState.Text, ts.DesiredState())
}
if row.CurrentState.Text != ts.CurrentState() {
t.Errorf("Unexpected TaskRow CurrentState, got %s, expected %s", row.CurrentState.Text, ts.CurrentState())
}
if row.Error.Text != ts.Error() {
t.Errorf("Unexpected TaskRow error, got %s, expected %s", row.Error.Text, ts.Error())
}
if row.Ports.Text != ts.Ports() {
t.Errorf("Unexpected TaskRow ports, got %s, expected %s", row.Ports.Text, ts.Ports())

}
}
3 changes: 2 additions & 1 deletion appui/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ func (s *NodeTasksWidget) highlightSelectedRow() {
s.tasks[s.selectedIndex].Highlighted()
}

func (s *NodeTasksWidget) OnEvent(event EventHandler) error {
//OnEvent runs the given command
func (s *NodeTasksWidget) OnEvent(event EventCommand) error {
return nil
}

Expand Down

0 comments on commit 1cdaccd

Please sign in to comment.