This repository has been archived by the owner on Mar 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
94 lines (74 loc) · 1.9 KB
/
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"os"
"os/exec"
"time"
"errors"
)
type TestData struct {
Name string
Install bool
Timeout int
}
func InstallChocoPkg(data TestData) error {
fmt.Println("> choco install " + data.Name)
cmd := exec.Command("choco", "install", data.Name, "-Force", "-Source", `"%cd%;http://chocolatey.org/api/v2/"`)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
return err
}
done := make(chan error, 1)
go func(){
done <- cmd.Wait()
}()
select {
case <- time.After(time.Duration(data.Timeout) * time.Second):
if err := cmd.Process.Kill(); err != nil {
<- done
return err
}
<- done
return errors.New("Timeout Error")
case err := <- done:
if err != nil {
return err
}
}
return nil
}
func TestManual(data TestData) error {
fmt.Println("> cd " + data.Name)
if err := os.Chdir(data.Name); err != nil {
return err
}
fmt.Println("> cd")
wd, err := os.Getwd();
if err != nil {
return err
} else {
fmt.Println(wd)
}
fmt.Println("> choco pack")
cmd := exec.Command("choco", "pack")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return err
}
if data.Install {
if err := InstallChocoPkg(data); err != nil {
return err
}
}
fmt.Println("> cd ..")
if err := os.Chdir(".."); err != nil {
return err
}
fmt.Print("\n")
return nil
}
func TestAutomatic(data TestData) error {
return TestKetarinAutomatic(data)
}