diff --git a/cmd/snippetCreate_test.go b/cmd/snippetCreate_test.go new file mode 100644 index 00000000..4be67cb5 --- /dev/null +++ b/cmd/snippetCreate_test.go @@ -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/") +} diff --git a/cmd/snippetList_test.go b/cmd/snippetList_test.go new file mode 100644 index 00000000..499a2b00 --- /dev/null +++ b/cmd/snippetList_test.go @@ -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]) +} diff --git a/testdata/test.git/config b/testdata/test.git/config index 24d95b37..d1c10d26 100644 --- a/testdata/test.git/config +++ b/testdata/test.git/config @@ -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