Skip to content

Commit

Permalink
(snippets) integration test for create and list
Browse files Browse the repository at this point in the history
  • Loading branch information
zaquestion committed Dec 4, 2017
1 parent ae033bc commit d991611
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cmd/snippetCreate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"os/exec"
"testing"

"github.com/stretchr/testify/require"
)

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

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

_, err = rc.Write([]byte("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/lab-testing/test/snippets/")
}
25 changes: 25 additions & 0 deletions cmd/snippetList_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func Test_snippetList(t *testing.T) {
repo := copyTestRepo(t)
cmd := exec.Command("../lab_bin", "snippet", "list", "lab-testing")
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+ snippet title`, snips[0])
}
3 changes: 3 additions & 0 deletions testdata/test.git/config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
[remote "origin"]
url = git@gitlab.com:zaquestion/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "lab-testing"]
url = git@gitlab.com:lab-testing/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
[gitlab]
token = uDz6czYV412zK-xC5mUu
user = lab-testing
Expand Down

0 comments on commit d991611

Please sign in to comment.