-
Notifications
You must be signed in to change notification settings - Fork 2
/
jobs_test.go
84 lines (67 loc) · 1.84 KB
/
jobs_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
package chronos_test
import (
"net/http"
"net/http/httptest"
chronos "github.com/axelspringer/go-chronos"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Jobs", func() {
var client *chronos.Client
var httpClient *http.Client
var mux *http.ServeMux
var server *httptest.Server
var testJobs []*chronos.Job
var testJob *chronos.Job
BeforeEach(func() {
httpClient, mux, server = fakeTestServer()
testJob = &chronos.Job{
Schedule: "R10/2012-10-01T05:52:00Z/PT2S",
Name: "demo",
Epsilon: "PT15M",
Command: "echo 'Test'",
Mem: 64,
CPUs: 0.1,
Container: &chronos.Container{
Image: "alpine:3.6",
Network: "USER",
NetworkName: "mesos",
},
}
testJobs = make([]*chronos.Job, 0)
testJobs = append(testJobs, testJob)
client = chronos.New("https://localhost/", httpClient)
})
AfterEach(func() {
defer server.Close()
})
Describe("List Jobs", func() {
var jobs *[]chronos.Job
BeforeEach(func() {
mux.HandleFunc("/v1/scheduler/jobs", func(w http.ResponseWriter, r *http.Request) {
Ω(r.Method).Should(Equal("GET"))
w.Header().Set("Content-Type", "application/json")
handleJSONEncode(w, testJobs)
})
jobs, _, _ = client.Jobs.List()
})
It("should contain 1 job", func() {
Ω(*jobs).Should(HaveLen(1))
})
})
Describe("Search Jobs", func() {
var jobs *[]chronos.Job
BeforeEach(func() {
mux.HandleFunc("/v1/scheduler/jobs/search", func(w http.ResponseWriter, r *http.Request) {
Ω(r.Method).Should(Equal("GET"))
Ω(r.URL.Query()["name"][0]).Should(Equal("demo"))
w.Header().Set("Content-Type", "application/json")
handleJSONEncode(w, testJobs)
})
jobs, _, _ = client.Jobs.Search(&chronos.JobsSearchParams{Name: "demo"})
})
It("should contain 1 job", func() {
Ω(*jobs).Should(HaveLen(1))
})
})
})