Exemple #1
0
func ListCases(w http.ResponseWriter, r *http.Request) {
	//Need better explaination of 'status', currently, only hasReport/isUpdated
	db := liboct.GetDefaultDB()
	var query liboct.DBQuery
	page_string := r.URL.Query().Get("Page")
	page, err := strconv.Atoi(page_string)
	if err == nil {
		query.Page = page
	}
	pageSizeString := r.URL.Query().Get("PageSize")
	pageSize, err := strconv.Atoi(pageSizeString)
	if err != nil {
		query.PageSize = pageSize
	}

	status := r.URL.Query().Get("Status")
	if len(status) > 0 {
		query.Params = make(map[string]string)
		query.Params["Status"] = status
	}
	ids := db.Lookup(liboct.DBCase, query)

	var caseList []liboct.TestCase
	for index := 0; index < len(ids); index++ {
		if val, err := db.Get(liboct.DBCase, ids[index]); err == nil {
			tc, _ := liboct.CaseFromString(val.String())
			caseList = append(caseList, tc)
		}
	}

	liboct.RenderOK(w, fmt.Sprintf("%d cases founded", len(caseList)), caseList)
}
Exemple #2
0
func GetCaseReport(w http.ResponseWriter, r *http.Request) {
	db := liboct.GetDefaultDB()
	id := r.URL.Query().Get(":ID")
	if val, err := db.Get(liboct.DBCase, id); err != nil {
		liboct.RenderError(w, err)
	} else {
		tc, _ := liboct.CaseFromString(val.String())
		content := tc.GetReportContent()
		if len(content) > 0 {
			liboct.RenderOK(w, "", content)
		} else {
			liboct.RenderErrorf(w, "Case report is empty.")
		}
	}
}
Exemple #3
0
func GetCase(w http.ResponseWriter, r *http.Request) {
	//TODO: support another query method : repo/group/name
	db := liboct.GetDefaultDB()
	id := r.URL.Query().Get(":ID")
	if val, err := db.Get(liboct.DBCase, id); err != nil {
		liboct.RenderError(w, err)
	} else {
		tc, _ := liboct.CaseFromString(val.String())
		value := tc.GetBundleContent()

		if len(value) > 0 {
			w.Write([]byte(value))
		} else {
			liboct.RenderErrorf(w, "Case is empty.")
		}
	}
}
Exemple #4
0
func AddTask(w http.ResponseWriter, r *http.Request) {
	result, _ := ioutil.ReadAll(r.Body)
	r.Body.Close()

	db := liboct.GetDefaultDB()
	caseID := string(result)
	caseInterface, err := db.Get(liboct.DBCase, caseID)
	if err != nil {
		liboct.RenderError(w, err)
		return
	}
	tc, _ := liboct.CaseFromString(caseInterface.String())

	bundleURL := tc.GetBundleTarURL()
	postURL := pubConfig.SchedulerURL
	if task, err := liboct.TestTaskNew(postURL, bundleURL, liboct.SchedulerDefaultPrio); err != nil {
		liboct.RenderError(w, err)
	} else {
		id, _ := db.Add(liboct.DBTask, task)
		liboct.RenderOK(w, id, nil)
	}
}