diff options
-rw-r--r-- | client/menu.go | 5 | ||||
-rw-r--r-- | client/menu_test.go | 49 |
2 files changed, 52 insertions, 2 deletions
diff --git a/client/menu.go b/client/menu.go index 19c8992..f6de082 100644 --- a/client/menu.go +++ b/client/menu.go @@ -6,6 +6,11 @@ func (s *State) displayMenu() { menu := s.config.Menus[s.currentMenu] fmt.Print("\033[2J") // clear the screen fmt.Printf("%s\n\n", menu.Banner) + if s.login == "" { + fmt.Print("Not logged in.\n\n") + } else { + fmt.Printf("Logged in as: %s\n\n", s.login) + } for i := 0; i < len(menu.MenuEntries); i++ { fmt.Printf("%s) %s\n", menu.MenuEntries[i].Key, menu.MenuEntries[i].Label) } diff --git a/client/menu_test.go b/client/menu_test.go index aaf3d81..9d7a8bc 100644 --- a/client/menu_test.go +++ b/client/menu_test.go @@ -14,7 +14,7 @@ func TestDisplayMenu(t *testing.T) { r, w, _ := os.Pipe() os.Stdout = w - // Complete menu + // Complete menu, while not logged in state := State{ config: &config.Config{ Menus: map[string]config.Menu{ @@ -31,11 +31,13 @@ func TestDisplayMenu(t *testing.T) { }, }, currentMenu: "test", - login: "nil", + login: "", } want := []byte("\033[2J" + "TEST TEST TEST\n" + "\n" + + "Not logged in.\n" + + "\n" + "q) quit\n") state.displayMenu() // back to normal state @@ -44,4 +46,47 @@ func TestDisplayMenu(t *testing.T) { if !reflect.DeepEqual(out, want) { t.Fatalf("menu displayed incorrectly:\nwant:%+v\ngot: %+v", want, out) } + + // Complete menu, while logged in + r, w, _ = os.Pipe() + os.Stdout = w + + // Complete menu, while not logged in + state = State{ + config: &config.Config{ + Menus: map[string]config.Menu{ + "test": config.Menu{ + Banner: "TEST TEST TEST", + MenuEntries: []config.MenuEntry{ + config.MenuEntry{ + Key: "w", + Label: "wait", + Action: "wait", + }, + config.MenuEntry{ + Key: "q", + Label: "quit", + Action: "quit", + }, + }, + }, + }, + }, + currentMenu: "test", + login: "test", + } + want = []byte("\033[2J" + + "TEST TEST TEST\n" + + "\n" + + "Logged in as: test\n" + + "\n" + + "w) wait\n" + + "q) quit\n") + state.displayMenu() + // back to normal state + w.Close() + out, _ = ioutil.ReadAll(r) + if !reflect.DeepEqual(out, want) { + t.Fatalf("menu displayed incorrectly:\nwant:%+v\ngot: %+v", want, out) + } } |