-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
58 lines (52 loc) · 1.16 KB
/
main_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
// crewgen/main_test.go
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"os/exec"
//"path/filepath"
"runtime"
"testing"
)
var mux *http.ServeMux
var writer *httptest.ResponseRecorder
var binName = "crewgen"
func TestMain(m *testing.M) {
if runtime.GOOS == "windows" {
binName += ".exe"
}
fmt.Printf("Building %s...\n", binName)
build := exec.Command("go", "build", "-o", binName)
if err := build.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Cannot build %s: %s\n", binName, err)
os.Exit(1)
}
fmt.Println("Running crewgen tests...")
result := m.Run()
fmt.Println("Cleanng up")
os.Remove(binName)
os.Exit(result)
}
/*
func TestHandleDocroot(t *testing.T) {
dir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
tDir := t.TempDir()
//cmdPath := filepath.Join(dir, binName)
fmt.Printf("Running in %s, with %s as dir.\n", tDir, dir)
t.Run("BaseCrewgenRun", func(t *testing.T) {
mux = http.NewServeMux()
mux.HandleFunc("/", crewGen)
writer = httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/", nil)
mux.ServeHTTP(writer, request)
if writer.Code != 200 {
t.Errorf("Response code is %v", writer.Code)
}
})
}
*/