-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci_test.go
73 lines (59 loc) · 1.11 KB
/
ci_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
package ci
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func delCache() {
cache.m.Lock()
delete(cache.val, cacheKey)
cache.m.Unlock()
}
func TestIsCI(t *testing.T) {
t.Run("true", func(t *testing.T) {
t.Setenv("CI", "true")
assert.True(t, IsCI())
t.Cleanup(delCache)
})
t.Run("false", func(t *testing.T) {
t.Setenv("CI", "false")
assert.False(t, IsCI())
t.Cleanup(delCache)
})
}
func TestIsNotCI(t *testing.T) {
t.Run("true", func(t *testing.T) {
t.Setenv("CI", "false")
assert.True(t, IsNotCI())
t.Cleanup(delCache)
})
t.Run("false", func(t *testing.T) {
t.Setenv("CI", "true")
assert.False(t, IsNotCI())
t.Cleanup(delCache)
})
}
func BenchmarkIsCI(b *testing.B) {
b.Run("true", func(b *testing.B) {
b.ReportAllocs()
b.Setenv("CI", "true")
for i := 0; i < b.N; i++ {
_ = IsCI()
}
b.Cleanup(delCache)
})
b.Run("false", func(b *testing.B) {
b.ReportAllocs()
b.Setenv("CI", "false")
for i := 0; i < b.N; i++ {
_ = IsCI()
}
b.Cleanup(delCache)
})
}
func ExampleIsCI() {
os.Setenv("CI", "false")
fmt.Println(IsCI())
// Output: false
}