forked from zaquestion/lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnippet_test.go
97 lines (84 loc) · 2.08 KB
/
snippet_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package cmd
import (
"fmt"
"os/exec"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func Test_snippetCmd_personal(t *testing.T) {
t.Parallel()
repo := copyTestRepo(t)
var snipID string
t.Run("create_personal", func(t *testing.T) {
cmd := exec.Command(labBinaryPath, "snippet", "-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)
}
out := string(b)
require.Contains(t, out, "https://gitlab.com/-/snippets/")
i := strings.Index(out, "\n")
snipID = strings.TrimPrefix(out[:i], "https://gitlab.com/-/snippets/")
t.Log(snipID)
})
t.Run("list_personal", func(t *testing.T) {
// Issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/43361
t.Skip("borked")
if snipID == "" {
t.Skip("snipID is empty, create likely failed")
}
cmd := exec.Command(labBinaryPath, "snippet", "-l", "-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.Contains(t, snips, fmt.Sprintf("#%s personal snippet title", snipID))
})
t.Run("delete_personal", func(t *testing.T) {
if snipID == "" {
t.Skip("snipID is empty, create likely failed")
}
cmd := exec.Command(labBinaryPath, "snippet", "-g", "-d", snipID)
cmd.Dir = repo
b, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Fatal(err)
}
require.Contains(t, string(b), fmt.Sprintf("Snippet #%s deleted", snipID))
})
}
func Test_snippetCmd_noArgs(t *testing.T) {
repo := copyTestRepo(t)
cmd := exec.Command(labBinaryPath, "snippet")
cmd.Dir = repo
b, err := cmd.CombinedOutput()
if err != nil {
t.Log(string(b))
t.Fatal(err)
}
require.Contains(t, string(b), `Usage:
lab snippet [flags]
lab snippet [command]`)
}