Beispiel #1
0
func (a *ApiTestSuite) TestHandleStartJobRequestNotFound() {
	t := a.T()
	cache := job.NewMockCache()
	handler := HandleStartJobRequest(cache)
	w, req := setupTestReq(t, "POST", ApiJobPath+"start/asdasd", nil)
	handler(w, req)
	a.Equal(w.Code, http.StatusNotFound)
}
Beispiel #2
0
func (a *ApiTestSuite) TestHandleAddJobFailureBadJson() {
	t := a.T()
	cache := job.NewMockCache()
	handler := HandleAddJob(cache)

	w, req := setupTestReq(t, "POST", ApiJobPath, []byte("asd"))
	handler(w, req)
	a.Equal(w.Code, http.StatusBadRequest)
}
Beispiel #3
0
func (a *ApiTestSuite) TestSetupApiRoutes() {
	db := &job.MockDB{}
	cache := job.NewMockCache()
	r := mux.NewRouter()

	SetupApiRoutes(r, cache, db)

	a.NotNil(r)
	a.IsType(r, mux.NewRouter())
}
Beispiel #4
0
func (a *ApiTestSuite) TestHandleListJobStatsRequestNotFound() {
	cache := job.NewMockCache()
	r := mux.NewRouter()
	r.HandleFunc(ApiJobPath+"stats/{id}", HandleListJobStatsRequest(cache)).Methods("GET")
	ts := httptest.NewServer(r)

	_, req := setupTestReq(a.T(), "GET", ts.URL+ApiJobPath+"stats/not-a-real-id", nil)

	client := &http.Client{}
	resp, err := client.Do(req)
	a.NoError(err)

	a.Equal(resp.StatusCode, http.StatusNotFound)
}
Beispiel #5
0
func (a *ApiTestSuite) TestHandleAddJobFailureBadSchedule() {
	t := a.T()
	cache := job.NewMockCache()
	jobMap := generateNewJobMap()
	handler := HandleAddJob(cache)

	// Mess up schedule
	jobMap["schedule"] = "asdf"

	jsonJobMap, err := json.Marshal(jobMap)
	a.NoError(err)
	w, req := setupTestReq(t, "POST", ApiJobPath, jsonJobMap)
	handler(w, req)
	a.Equal(w.Code, http.StatusBadRequest)
	a.True(strings.Contains(bytes.NewBuffer(w.Body.Bytes()).String(), "when initializing"))
}
Beispiel #6
0
func (a *ApiTestSuite) TestHandleJobRequestJobDoesNotExist() {
	t := a.T()
	db := &job.MockDB{}
	cache := job.NewMockCache()

	r := mux.NewRouter()
	r.HandleFunc(ApiJobPath+"{id}", HandleJobRequest(cache, db)).Methods("DELETE", "GET")
	ts := httptest.NewServer(r)

	_, req := setupTestReq(t, "DELETE", ts.URL+ApiJobPath+"not-a-real-id", nil)

	client := &http.Client{}
	resp, err := client.Do(req)
	a.NoError(err)

	a.Equal(resp.StatusCode, http.StatusNotFound)
}
Beispiel #7
0
func (a *ApiTestSuite) TestHandleAddJob() {
	t := a.T()
	cache := job.NewMockCache()
	jobMap := generateNewJobMap()
	handler := HandleAddJob(cache)

	jsonJobMap, err := json.Marshal(jobMap)
	a.NoError(err)
	w, req := setupTestReq(t, "POST", ApiJobPath, jsonJobMap)
	handler(w, req)

	var addJobResp AddJobResponse
	err = json.Unmarshal(w.Body.Bytes(), &addJobResp)
	a.NoError(err)
	retrievedJob, err := cache.Get(addJobResp.Id)
	a.NoError(err)
	a.Equal(jobMap["name"], retrievedJob.Name)
	a.Equal(jobMap["owner"], retrievedJob.Owner)
	a.Equal(w.Code, http.StatusCreated)
}
Beispiel #8
0
func generateJobAndCache() (*job.MemoryJobCache, *job.Job) {
	cache := job.NewMockCache()
	job := job.GetMockJobWithGenericSchedule()
	job.Init(cache)
	return cache, job
}