-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevop_test.go
70 lines (55 loc) · 1.21 KB
/
devop_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
package main_test
import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"testing"
"time"
)
func TestDevOP(t *testing.T) {
os.Remove("./testData/testData")
exec.Command("go", "build").Run()
os.Chdir("./testData")
DEVOP := exec.Command("../devop")
DEVOP.Stderr = os.Stderr
DEVOP.Stdout = os.Stdout
DEVOP.Start()
t_bytes := []byte("test ok")
if err := ioutil.WriteFile("test.txt", t_bytes, os.ModePerm); err != nil {
t.Error(err)
}
var found bool
for i := 0; i < 1000; i++ {
time.Sleep(time.Millisecond)
if n_bytes, err := ioutil.ReadFile("test.out.txt"); err == nil {
found = true
if !bytes.Equal(n_bytes, t_bytes) {
t.Fail()
}
break
}
}
if !found {
t.Error("Can't read test.out.txt")
}
DEVOP.Process.Kill()
DEVOP.Wait()
//if _, err := os.Stat("test.out.txt"); err == nil {
// t.Error("test.out.txt file was not deleted")
//}
//
//if _, err := os.Stat("test.txt"); err == nil {
// t.Error("test.txt file was not deleted")
//}
//
//if _, err := os.Stat("testcmd"); err == nil {
// t.Error("testcmd file was not deleted")
//}
os.Remove("../devop")
os.Remove("test.txt")
os.Remove("test.out.txt")
os.Remove("testData")
os.Remove("../devop.exe")
os.Remove("testData.exe")
}