Skip to content

Commit

Permalink
Adding more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebodin committed Jul 9, 2018
1 parent 1ca3ca6 commit b663c64
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
5 changes: 1 addition & 4 deletions tmux/tmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ func ListSessions() (map[string]SessionInfo, error) {

res, err := Exec("ls")
if err != nil {
if strings.Contains(err.Error(), "no server running on") {
return sessionMap, nil
}
return sessionMap, fmt.Errorf("error listing sessions %v", err)
return sessionMap, nil
}

splits := strings.Split(res.Stdout, "\n")
Expand Down
50 changes: 50 additions & 0 deletions tmux/tmux_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tmux

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -52,3 +53,52 @@ func TestSendRawKeys(t *testing.T) {
assert.Equal(t, "tmux", fnName)
assert.Equal(t, []string{"send-keys", "-R", "-t", "target", "ls"}, fnArgs)
}

func TestGetOptions(t *testing.T) {
t.Run("get options", func(t *testing.T) {
ExecFunc = func(name string, args ...string) (Result, error) {
return Result{Stdout: "base-index 2\npane-base-index 1"}, nil
}

options, err := GetOptions()
assert.Nil(t, err)
assert.Equal(t, 2, options.BaseIndex)
assert.Equal(t, 1, options.PaneBaseIndex)
})

t.Run("get options error", func(t *testing.T) {
ExecFunc = func(name string, args ...string) (Result, error) {
return Result{}, errors.New("some random error")
}

_, err := GetOptions()
assert.Error(t, err)
})
}

func TestListSessions(t *testing.T) {
t.Run("list options ok", func(t *testing.T) {
ExecFunc = func(name string, args ...string) (Result, error) {
return Result{Stdout: "azd: infos\nother-session: infos"}, nil
}

sessions, err := ListSessions()
assert.Nil(t, err)
assert.Equal(t, map[string]SessionInfo{
"azd": SessionInfo{},
"other-session": SessionInfo{},
},
sessions,
)
})

t.Run("list options error", func(t *testing.T) {
ExecFunc = func(name string, args ...string) (Result, error) {
return Result{}, errors.New("some error")
}

sessions, err := ListSessions()
assert.Nil(t, err)
assert.Equal(t, map[string]SessionInfo{}, sessions)
})
}

0 comments on commit b663c64

Please sign in to comment.