-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmain_test.go
52 lines (38 loc) · 933 Bytes
/
main_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
package main
import (
"bytes"
"fmt"
"io"
"os"
"testing"
"github.com/fatih/color"
"github.com/stretchr/testify/assert"
)
func Test_DeletingBranchesWhenTheDryRunOptionIsFalse(t *testing.T) {
onlyCI(t)
actual := captureOutput(func() { runMain(false, false) })
expected := fmt.Sprintf("%s %s", green("✔"), "Deleting branches...")
assert.Contains(t, actual, expected)
}
func Test_DoNotDeleteBranchesWhenTheDryRunOptionIsTrue(t *testing.T) {
onlyCI(t)
actual := captureOutput(func() { runMain(true, false) })
expected := fmt.Sprintf("%s %s", hiBlack("-"), "Deleting branches...")
assert.Contains(t, actual, expected)
}
func onlyCI(t *testing.T) {
if os.Getenv("CI") == "" {
t.Skip("skipping test in local")
}
os.Chdir("ci-test")
}
func captureOutput(f func()) string {
r, w, _ := os.Pipe()
os.Stdout = w
color.Output = w
f()
w.Close()
var buf bytes.Buffer
io.Copy(&buf, r)
return buf.String()
}