-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathmain_e2e_test.go
More file actions
72 lines (53 loc) · 1.44 KB
/
main_e2e_test.go
File metadata and controls
72 lines (53 loc) · 1.44 KB
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
//go:build e2e
package main
import (
"bytes"
"fmt"
"io"
"os"
"testing"
"github.com/fatih/color"
"github.com/stretchr/testify/assert"
)
func TestE2E_DeletingBranchesWhenDryRunOptionIsFalse(t *testing.T) {
onlyCI(t)
results := captureOutput(func() { runMain(Merged, Quick, false, false) })
expected := fmt.Sprintf("%s %s", green("✔"), "Deleting branches...")
assert.Contains(t, results, expected)
}
func TestE2E_DoNotDeleteBranchesWhenDryRunOptionIsTrue(t *testing.T) {
onlyCI(t)
results := captureOutput(func() { runMain(Merged, Quick, true, false) })
expected := fmt.Sprintf("%s %s", hiBlack("-"), "Deleting branches...")
assert.Contains(t, results, expected)
}
func TestE2E_LockAndUnlock(t *testing.T) {
onlyCI(t)
runLock([]string{"main"}, false)
lockResults := captureOutput(func() { runMain(Merged, Quick, true, false) })
expected := fmt.Sprintf("main %s", hiBlack("[locked]"))
assert.Contains(t, lockResults, expected)
runUnlock([]string{"main"}, false)
unlockResults := captureOutput(func() { runMain(Merged, Quick, true, false) })
assert.NotContains(t, unlockResults, 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 {
org := os.Stdout
defer func() {
os.Stdout = org
}()
r, w, _ := os.Pipe()
os.Stdout = w
color.Output = w
f()
w.Close()
var buf bytes.Buffer
io.Copy(&buf, r)
return buf.String()
}