forked from getantibody/antibody
/
antibody_test.go
67 lines (60 loc) · 1.69 KB
/
antibody_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package antibody_test
import (
"bytes"
"io/ioutil"
"os"
"strings"
"testing"
"github.com/akatrevorjay/antibody"
"github.com/stretchr/testify/assert"
)
func TestAntibody(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
bundles := []string{
"# comments also are allowed",
"caarlos0/ports kind:path # comment at the end of the line",
"caarlos0/jvm kind:path branch:gh-pages",
"caarlos0/zsh-open-pr kind:zsh",
"",
" ",
" # trick play",
"/tmp kind:path",
}
sh, err := antibody.New(
home,
bytes.NewBufferString(strings.Join(bundles, "\n")),
).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/git-open-pr.plugin.zsh`)
}
func TestAntibodyError(t *testing.T) {
assert := assert.New(t)
home := home()
defer os.RemoveAll(home)
bundles := bytes.NewBufferString("invalid-repo")
sh, err := antibody.New(home, bundles).Bundle()
assert.Error(err)
assert.Empty(sh)
}
func TestHome(t *testing.T) {
assert.Contains(t, antibody.Home(), "antibody")
}
func TestHomeFromEnvironmentVariable(t *testing.T) {
os.Setenv("ANTIBODY_HOME", "/tmp")
assert.Equal(t, "/tmp", antibody.Home())
}
func home() string {
home, err := ioutil.TempDir(os.TempDir(), "antibody")
if err != nil {
panic(err.Error())
}
return home
}