forked from jubnzv/go-tmux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_util.go
56 lines (48 loc) · 1014 Bytes
/
test_util.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
// The MIT License (MIT)
// Copyright (C) 2019 Georgy Komarov <[email protected]>
package tmux
import (
"os"
"strings"
)
// Kills sessions that contains namePattern substring in the name.
func sessionsReaper(namePattern string) {
s := new(Server)
// Suppose that ListSession works.
sessions, _ := s.ListSessions()
for _, ss := range sessions {
if strings.Contains(ss.Name, namePattern) {
s.KillSession(ss.Name)
}
}
}
// Restore tmux session that was active before test.
func restoreSession() {
if !IsInsideTmux() {
return
}
// Session name when test is running
session_name := ""
restore_fun := func() {
if session_name == "" {
session_name, _ = GetAttachedSessionName()
} else {
server := new(Server)
sessions, _ := server.ListSessions()
for _, s := range sessions {
if s.Name == session_name {
s.AttachSession()
}
}
}
return
}
restore_fun()
}
func InTravis() bool {
if os.Getenv("IN_TRAVIS") == "1" {
return true
} else {
return false
}
}