mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-12 06:28:50 +00:00
Task GET
This commit is contained in:
@@ -12,9 +12,10 @@ import (
|
||||
func TestCreateGetProject(t *testing.T) {
|
||||
|
||||
resp := createProject(api.CreateProjectRequest{
|
||||
Name: "Test name",
|
||||
GitUrl: "http://github.com/test/test",
|
||||
Version: "Test Version",
|
||||
Name: "Test name",
|
||||
GitUrl: "http://github.com/test/test",
|
||||
Version: "Test Version",
|
||||
Priority: 123,
|
||||
})
|
||||
|
||||
id := resp.Id
|
||||
@@ -29,26 +30,27 @@ func TestCreateGetProject(t *testing.T) {
|
||||
getResp, _ := getProject(id)
|
||||
|
||||
if getResp.Project.Id != id {
|
||||
t.Fail()
|
||||
t.Error()
|
||||
}
|
||||
|
||||
if getResp.Project.Name != "Test name" {
|
||||
t.Fail()
|
||||
t.Error()
|
||||
}
|
||||
|
||||
if getResp.Project.Version != "Test Version" {
|
||||
t.Fail()
|
||||
t.Error()
|
||||
}
|
||||
|
||||
if getResp.Project.GitUrl != "http://github.com/test/test" {
|
||||
t.Fail()
|
||||
t.Error()
|
||||
}
|
||||
if getResp.Project.Priority != 123 {
|
||||
t.Error()
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateProjectInvalid(t *testing.T) {
|
||||
resp := createProject(api.CreateProjectRequest{
|
||||
|
||||
})
|
||||
resp := createProject(api.CreateProjectRequest{})
|
||||
|
||||
if resp.Ok != false {
|
||||
t.Fail()
|
||||
@@ -111,4 +113,4 @@ func getProject(id int64) (*api.GetProjectResponse, *http.Response) {
|
||||
handleErr(err)
|
||||
|
||||
return &getResp, r
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package test
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"src/task_tracker/api"
|
||||
@@ -21,13 +22,13 @@ func TestCreateGetWorker(t *testing.T) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
getResp, r := getWorker(resp.WorkerId)
|
||||
getResp, r := getWorker(resp.WorkerId.String())
|
||||
|
||||
if r.StatusCode != 200 {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
if resp.WorkerId != getResp.Worker.Id.String() {
|
||||
if resp.WorkerId != getResp.Worker.Id {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
@@ -81,3 +82,9 @@ func getWorker(id string) (*api.GetWorkerResponse, *http.Response) {
|
||||
|
||||
return resp, r
|
||||
}
|
||||
|
||||
func genWid() *uuid.UUID {
|
||||
|
||||
resp, _ := createWorker(api.CreateWorkerRequest{})
|
||||
return &resp.WorkerId
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user