Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
more fixes and features ported
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Aug 17, 2016
1 parent 3a1e466 commit 80cb5c9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
1 change: 1 addition & 0 deletions antibody.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (a *Antibody) Bundle() (string, error) {

for _, line := range a.Lines {
go func(l string) {
l = strings.TrimSpace(l)
if l != "" && l[0] != '#' {
bundle.New(a.Home, l).Get(a.Events)
}
Expand Down
15 changes: 10 additions & 5 deletions antibody_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ func TestAntibody(t *testing.T) {
"# comments also are allowed",
"caarlos0/ports kind:path",
"caarlos0/jvm kind:path branch:gh-pages",
"caarlos0/zsh-open-pr kind:zsh",
"caarlos0/zsh-open-pr kind:zsh",
"",
" ",
" # trick play",
"/tmp kind:path",
}
sh, err := antibody.New(home, bundles).Bundle()
assert.NoError(err)
files, err := ioutil.ReadDir(home)
assert.NoError(err)
assert.Len(files, 3)
assert.Contains(sh, `export PATH="/tmp:$PATH"`)
assert.Contains(sh, `export PATH="`+home+`https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-ports:$PATH"`)
assert.Contains(sh, `export PATH="`+home+`https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-jvm:$PATH"`)
assert.Contains(sh, `source `+home+`https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-zsh-open-pr/open-pr.plugin.zsh`)
assert.Contains(sh, `export PATH="`+home+`/https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-ports:$PATH"`)
assert.Contains(sh, `export PATH="`+home+`/https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-jvm:$PATH"`)
assert.Contains(sh, `source `+home+`/https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-zsh-open-pr/open-pr.plugin.zsh`)
}

func TestAntibodyError(t *testing.T) {
Expand All @@ -40,7 +45,7 @@ func TestAntibodyError(t *testing.T) {
}

func TestHome(t *testing.T) {
assert.Contains(t, "antibody", antibody.Home())
assert.Contains(t, antibody.Home(), "antibody")
}

func TestHomeFromEnvironmentVariable(t *testing.T) {
Expand Down
27 changes: 9 additions & 18 deletions bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bundle_test
import (
"io/ioutil"
"os"
"strings"
"testing"

"github.com/getantibody/antibody/bundle"
Expand All @@ -17,8 +16,7 @@ func TestZshGitBundle(t *testing.T) {
defer os.RemoveAll(home)
events := make(chan event.Event)
go bundle.New(home, "caarlos0/jvm").Get(events)
evt := <-events
assert.True(strings.HasSuffix(evt.Shell, "jvm.plugin.zsh"))
assert.Contains((<-events).Shell, "jvm.plugin.zsh")
}

func TestZshInvalidGitBundle(t *testing.T) {
Expand All @@ -27,19 +25,17 @@ func TestZshInvalidGitBundle(t *testing.T) {
defer os.RemoveAll(home)
events := make(chan event.Event)
go bundle.New(home, "doesnt exists").Get(events)
evt := <-events
assert.Error(evt.Error)
assert.Error((<-events).Error)
}

func TestZshLocalBundle(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
assert.NoError(ioutil.WriteFile(home+"whatever.sh", []byte(""), 0644))
assert.NoError(ioutil.WriteFile(home+"/a.sh", []byte("echo 9"), 0644))
events := make(chan event.Event)
go bundle.New(home, home).Get(events)
evt := <-events
assert.True(strings.HasSuffix(evt.Shell, "whatever.sh"))
assert.Contains((<-events).Shell, "a.sh")
}

func TestZshInvalidLocalBundle(t *testing.T) {
Expand All @@ -48,8 +44,7 @@ func TestZshInvalidLocalBundle(t *testing.T) {
defer os.RemoveAll(home)
events := make(chan event.Event)
go bundle.New(home, "/asduhasd/asdasda").Get(events)
evt := <-events
assert.Error(evt.Error)
assert.Error((<-events).Error)
}

func TestPathInvalidLocalBundle(t *testing.T) {
Expand All @@ -58,8 +53,7 @@ func TestPathInvalidLocalBundle(t *testing.T) {
defer os.RemoveAll(home)
events := make(chan event.Event)
go bundle.New(home, "/asduhasd/asdasda kind:path").Get(events)
evt := <-events
assert.Error(evt.Error)
assert.Error((<-events).Error)
}

func TestPathGitBundle(t *testing.T) {
Expand All @@ -68,8 +62,7 @@ func TestPathGitBundle(t *testing.T) {
defer os.RemoveAll(home)
events := make(chan event.Event)
go bundle.New(home, "caarlos0/jvm kind:path").Get(events)
evt := <-events
assert.True(strings.HasPrefix(evt.Shell, "export PATH=\""))
assert.Contains((<-events).Shell, "export PATH=\"")
}

func TestPathLocalBundle(t *testing.T) {
Expand All @@ -79,8 +72,7 @@ func TestPathLocalBundle(t *testing.T) {
assert.NoError(ioutil.WriteFile(home+"whatever.sh", []byte(""), 0644))
events := make(chan event.Event)
go bundle.New(home, home+" kind:path").Get(events)
evt := <-events
assert.Equal("export PATH=\""+home+":$PATH\"", evt.Shell)
assert.Equal("export PATH=\""+home+":$PATH\"", (<-events).Shell)
}

func TestPathGitBundleWithBranch(t *testing.T) {
Expand All @@ -89,8 +81,7 @@ func TestPathGitBundleWithBranch(t *testing.T) {
defer os.RemoveAll(home)
events := make(chan event.Event)
go bundle.New(home, "caarlos0/jvm kind:path branch:gh-pages").Get(events)
evt := <-events
assert.True(strings.HasPrefix(evt.Shell, "export PATH=\""))
assert.Contains((<-events).Shell, "export PATH=\"")
}

func home() string {
Expand Down
2 changes: 1 addition & 1 deletion cmd/shell/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package shell_test
import (
"testing"

"github.com/getantibody/antibody/shell"
"github.com/getantibody/antibody/cmd/shell"
"github.com/stretchr/testify/assert"
)

Expand Down

0 comments on commit 80cb5c9

Please sign in to comment.