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) }
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) }
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()) }
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) }
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")) }
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) }
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) }
func generateJobAndCache() (*job.MemoryJobCache, *job.Job) { cache := job.NewMockCache() job := job.GetMockJobWithGenericSchedule() job.Init(cache) return cache, job }