Skip to content

Commit

Permalink
(snippet) integration test creating and listing personal snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
zaquestion committed Dec 5, 2017
1 parent 846ff0a commit c7b260f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
18 changes: 8 additions & 10 deletions cmd/snippetCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ Source snippets from stdin, file, or in editor from scratch
Write title & description in editor, or using -m`,
Run: func(cmd *cobra.Command, args []string) {
remote := forkedFromRemote
ok, err := git.IsRemote(args[0])
if err != nil {
log.Fatal(err)
}
if ok {
remote = args[0]
}
if len(args) > 0 {
if !ok {
file = args[0]
ok, err := git.IsRemote(args[0])
if err != nil {
log.Fatal(err)
}
if ok && len(args) > 1 {
if ok {
remote = args[0]
} else if ok && len(args) > 1 {
file = args[1]
} else {
file = args[0]
}
}
code, err := determineCode(file)
Expand Down
30 changes: 30 additions & 0 deletions cmd/snippetCreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,33 @@ func Test_snippetCreate(t *testing.T) {

require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/snippets/")
}

func Test_snippetCreate_Global(t *testing.T) {
repo := copyTestRepo(t)
cmd := exec.Command("../lab_bin", "snippet", "create", "-g",
"-m", "personal snippet title",
"-m", "personal snippet description")
cmd.Dir = repo

rc, err := cmd.StdinPipe()
if err != nil {
t.Fatal(err)
}

_, err = rc.Write([]byte("personal snippet contents"))
if err != nil {
t.Fatal(err)
}
err = rc.Close()
if err != nil {
t.Fatal(err)
}

b, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Fatal(err)
}

require.Contains(t, string(b), "https://gitlab.com/snippets/")
}
16 changes: 16 additions & 0 deletions cmd/snippetList_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ func Test_snippetList(t *testing.T) {
t.Log(snips)
require.Regexp(t, `#\d+ snippet title`, snips[0])
}

func Test_snippetList_Global(t *testing.T) {
repo := copyTestRepo(t)
cmd := exec.Command("../lab_bin", "snippet", "list", "-g")
cmd.Dir = repo

b, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Fatal(err)
}

snips := strings.Split(string(b), "\n")
t.Log(snips)
require.Regexp(t, `#\d+ personal snippet title`, snips[0])
}

0 comments on commit c7b260f

Please sign in to comment.