-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ivanilves/shell-coverage
test(pkg/shell): add test coverage
- Loading branch information
Showing
10 changed files
with
149 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ main: dep build | |
all: dep build install | ||
|
||
dep: | ||
go mod tidy | ||
go mod vendor | ||
|
||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package shell | ||
|
||
import ( | ||
"os" | ||
|
||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDetectShell(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
cases := map[string]string{ | ||
"/bin/bash": "/bin/bash", | ||
"/bin/zsh": "/bin/zsh", | ||
"/bin/yolo": defaultShell, | ||
"": defaultShell, | ||
} | ||
|
||
for input, expected := range cases { | ||
os.Setenv("SHELL", input) | ||
|
||
assert.Equal(expected, detectShell()) | ||
} | ||
} | ||
|
||
func TestName(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
assert.Equal(os.Args[0], Name()) | ||
} | ||
|
||
func TestIsRunningInside(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
cases := map[string]bool{ | ||
"true": true, | ||
"false": false, | ||
"whatever": false, | ||
} | ||
|
||
for input, expected := range cases { | ||
os.Setenv("TTG", input) | ||
|
||
assert.Equal(expected, IsRunningInside()) | ||
} | ||
|
||
os.Setenv("TTG", "") | ||
|
||
assert.Equal(false, IsRunningInside()) | ||
} | ||
|
||
func TestGetppid(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
cases := map[string]int{ | ||
"42424242": 42424242, | ||
"xyz": 0, | ||
} | ||
|
||
for input, expected := range cases { | ||
os.Setenv("TTG_PID", input) | ||
|
||
assert.Equal(expected, Getppid()) | ||
} | ||
|
||
os.Setenv("TTG_PID", "") | ||
|
||
assert.Equal(0, Getppid()) | ||
} | ||
|
||
func TestSpawn(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
cases := map[string]bool{ | ||
"/bin/true": true, | ||
"/bin/false": false, | ||
} | ||
|
||
for input, expected := range cases { | ||
os.Setenv("SHELL", input) | ||
|
||
assert.Equal(expected, Spawn("/") == nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package terminal | ||
|
||
import ( | ||
"golang.org/x/term" | ||
) | ||
|
||
const defautHeight = 20 | ||
|
||
// Height reveals a number of lines we have in our terminal | ||
func Height() int { | ||
_, h, err := term.GetSize(0) | ||
|
||
if err != nil { | ||
return defautHeight | ||
} | ||
|
||
return h | ||
} |