mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-13 14:59:03 +00:00
Task GET
This commit is contained in:
@@ -2,6 +2,8 @@ package test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"io/ioutil"
|
||||
"src/task_tracker/api"
|
||||
"testing"
|
||||
@@ -11,16 +13,15 @@ func TestCreateTaskValid(t *testing.T) {
|
||||
|
||||
//Make sure there is always a project for id:1
|
||||
createProject(api.CreateProjectRequest{
|
||||
Name: "Some Test name",
|
||||
Name: "Some Test name",
|
||||
Version: "Test Version",
|
||||
GitUrl: "http://github.com/test/test",
|
||||
|
||||
GitUrl: "http://github.com/test/test",
|
||||
})
|
||||
|
||||
resp := createTask(api.CreateTaskRequest{
|
||||
Project:1,
|
||||
Recipe: "{}",
|
||||
MaxRetries:3,
|
||||
Project: 1,
|
||||
Recipe: "{}",
|
||||
MaxRetries: 3,
|
||||
})
|
||||
|
||||
if resp.Ok != true {
|
||||
@@ -31,9 +32,9 @@ func TestCreateTaskValid(t *testing.T) {
|
||||
func TestCreateTaskInvalidProject(t *testing.T) {
|
||||
|
||||
resp := createTask(api.CreateTaskRequest{
|
||||
Project:123456,
|
||||
Recipe: "{}",
|
||||
MaxRetries:3,
|
||||
Project: 123456,
|
||||
Recipe: "{}",
|
||||
MaxRetries: 3,
|
||||
})
|
||||
|
||||
if resp.Ok != false {
|
||||
@@ -48,8 +49,8 @@ func TestCreateTaskInvalidProject(t *testing.T) {
|
||||
func TestCreateTaskInvalidRetries(t *testing.T) {
|
||||
|
||||
resp := createTask(api.CreateTaskRequest{
|
||||
Project:1,
|
||||
MaxRetries:-1,
|
||||
Project: 1,
|
||||
MaxRetries: -1,
|
||||
})
|
||||
|
||||
if resp.Ok != false {
|
||||
@@ -61,6 +62,158 @@ func TestCreateTaskInvalidRetries(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateGetTask(t *testing.T) {
|
||||
|
||||
//Make sure there is always a project for id:1
|
||||
resp := createProject(api.CreateProjectRequest{
|
||||
Name: "My project",
|
||||
Version: "1.0",
|
||||
GitUrl: "http://github.com/test/test",
|
||||
Priority: 999,
|
||||
})
|
||||
|
||||
createTask(api.CreateTaskRequest{
|
||||
Project: resp.Id,
|
||||
Recipe: "{\"url\":\"test\"}",
|
||||
MaxRetries: 3,
|
||||
Priority: 9999,
|
||||
})
|
||||
|
||||
taskResp := getTaskFromProject(resp.Id, genWid())
|
||||
|
||||
if taskResp.Ok != true {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.Priority != 9999 {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.Id == 0 {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.Recipe != "{\"url\":\"test\"}" {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.Status != "new" {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.MaxRetries != 3 {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.Project.Id != resp.Id {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.Project.Priority != 999 {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.Project.Version != "1.0" {
|
||||
t.Error()
|
||||
}
|
||||
if taskResp.Task.Project.GitUrl != "http://github.com/test/test" {
|
||||
t.Error()
|
||||
}
|
||||
}
|
||||
|
||||
func createTasks(prefix string) (int64, int64) {
|
||||
|
||||
lowP := createProject(api.CreateProjectRequest{
|
||||
Name: prefix + "low",
|
||||
Version: "1.0",
|
||||
GitUrl: "http://github.com/test/test",
|
||||
Priority: 1,
|
||||
})
|
||||
highP := createProject(api.CreateProjectRequest{
|
||||
Name: prefix + "high",
|
||||
Version: "1.0",
|
||||
GitUrl: "http://github.com/test/test",
|
||||
Priority: 999,
|
||||
})
|
||||
createTask(api.CreateTaskRequest{
|
||||
Project: lowP.Id,
|
||||
Recipe: "low1",
|
||||
Priority: 0,
|
||||
})
|
||||
createTask(api.CreateTaskRequest{
|
||||
Project: lowP.Id,
|
||||
Recipe: "low2",
|
||||
Priority: 1,
|
||||
})
|
||||
createTask(api.CreateTaskRequest{
|
||||
Project: highP.Id,
|
||||
Recipe: "high1",
|
||||
Priority: 100,
|
||||
})
|
||||
createTask(api.CreateTaskRequest{
|
||||
Project: highP.Id,
|
||||
Recipe: "high2",
|
||||
Priority: 101,
|
||||
})
|
||||
|
||||
return lowP.Id, highP.Id
|
||||
}
|
||||
|
||||
func TestTaskProjectPriority(t *testing.T) {
|
||||
|
||||
wid := genWid()
|
||||
l, h := createTasks("withProject")
|
||||
|
||||
t1 := getTaskFromProject(l, wid)
|
||||
t2 := getTaskFromProject(l, wid)
|
||||
t3 := getTaskFromProject(h, wid)
|
||||
t4 := getTaskFromProject(h, wid)
|
||||
|
||||
if t1.Task.Recipe != "low2" {
|
||||
t.Error()
|
||||
}
|
||||
if t2.Task.Recipe != "low1" {
|
||||
t.Error()
|
||||
}
|
||||
if t3.Task.Recipe != "high2" {
|
||||
t.Error()
|
||||
}
|
||||
if t4.Task.Recipe != "high1" {
|
||||
t.Error()
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskPriority(t *testing.T) {
|
||||
|
||||
wid := genWid()
|
||||
|
||||
// Clean other tasks
|
||||
for i := 0; i < 20; i++ {
|
||||
getTask(wid)
|
||||
}
|
||||
|
||||
createTasks("")
|
||||
|
||||
t1 := getTask(wid)
|
||||
t2 := getTask(wid)
|
||||
t3 := getTask(wid)
|
||||
t4 := getTask(wid)
|
||||
|
||||
if t1.Task.Recipe != "high2" {
|
||||
t.Error()
|
||||
}
|
||||
if t2.Task.Recipe != "high1" {
|
||||
t.Error()
|
||||
}
|
||||
if t3.Task.Recipe != "low2" {
|
||||
t.Error()
|
||||
}
|
||||
if t4.Task.Recipe != "low1" {
|
||||
t.Error()
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoMoreTasks(t *testing.T) {
|
||||
|
||||
wid := genWid()
|
||||
|
||||
for i := 0; i < 30; i++ {
|
||||
getTask(wid)
|
||||
}
|
||||
}
|
||||
|
||||
func createTask(request api.CreateTaskRequest) *api.CreateTaskResponse {
|
||||
|
||||
r := Post("/task/create", request)
|
||||
@@ -72,3 +225,27 @@ func createTask(request api.CreateTaskRequest) *api.CreateTaskResponse {
|
||||
|
||||
return &resp
|
||||
}
|
||||
|
||||
func getTask(wid *uuid.UUID) *api.GetTaskResponse {
|
||||
|
||||
r := Get(fmt.Sprintf("/task/get?wid=%s", wid))
|
||||
|
||||
var resp api.GetTaskResponse
|
||||
data, _ := ioutil.ReadAll(r.Body)
|
||||
err := json.Unmarshal(data, &resp)
|
||||
handleErr(err)
|
||||
|
||||
return &resp
|
||||
}
|
||||
|
||||
func getTaskFromProject(project int64, wid *uuid.UUID) *api.GetTaskResponse {
|
||||
|
||||
r := Get(fmt.Sprintf("/task/get/%d?wid=%s", project, wid))
|
||||
|
||||
var resp api.GetTaskResponse
|
||||
data, _ := ioutil.ReadAll(r.Body)
|
||||
err := json.Unmarshal(data, &resp)
|
||||
handleErr(err)
|
||||
|
||||
return &resp
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user