summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ionrock/procs/manager_test.go
blob: 69c999407617d02b8eff9fed610f382b75ff86a6 (plain)
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
package procs_test

import (
	"flag"
	"fmt"
	"log"
	"net/http"
	"os"
	"testing"

	"github.com/ionrock/procs"
)

func TestManagerStartHelper(t *testing.T) {
	if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
		return
	}

	port := flag.String("p", "12212", "port to serve on")
	directory := flag.String("d", ".", "the directory of static file to host")
	flag.Parse()

	http.Handle("/", http.FileServer(http.Dir(*directory)))

	log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
	log.Fatal(http.ListenAndServe(":"+*port, nil))
	os.Exit(0)
}

func TestManagerStart(t *testing.T) {
	m := procs.NewManager()

	err := m.Start("test", fmt.Sprintf("%s -test.run=TestManagerStartHelper", os.Args[0]))
	if err != nil {
		t.Errorf("failed to start test process: %s", err)
	}

	if len(m.Processes) != 1 {
		t.Error("failed to add process")
	}

	err = m.Stop("test")
	if err != nil {
		t.Errorf("error stopping process: %s", err)
	}

	err = m.Remove("test")
	if err != nil {
		t.Errorf("error removing process: %s", err)
	}

	if len(m.Processes) != 0 {
		t.Error("failed to remove processes")
	}
}