Web dashboard, task release, logs api

This commit is contained in:
simon987
2019-01-21 20:16:30 -05:00
parent 0346dd8b6b
commit cbd32daf02
65 changed files with 13430 additions and 114 deletions

View File

@@ -3,6 +3,7 @@ package test
import (
"encoding/json"
"fmt"
"github.com/google/uuid"
"io/ioutil"
"net/http"
"src/task_tracker/api"
@@ -17,6 +18,7 @@ func TestCreateGetProject(t *testing.T) {
GitRepo: "drone/webhooktest",
Version: "Test Version",
Priority: 123,
Motd: "motd",
})
id := resp.Id
@@ -51,6 +53,9 @@ func TestCreateGetProject(t *testing.T) {
if getResp.Project.Priority != 123 {
t.Error()
}
if getResp.Project.Motd != "motd" {
t.Error()
}
}
func TestCreateProjectInvalid(t *testing.T) {
@@ -114,6 +119,82 @@ func TestGetProjectNotFound(t *testing.T) {
}
}
func TestGetProjectStats(t *testing.T) {
r := createProject(api.CreateProjectRequest{
Motd: "motd",
Name: "Name",
Version: "version",
CloneUrl: "http://github.com/drone/test",
GitRepo: "drone/test",
Priority: 3,
})
pid := r.Id
createTask(api.CreateTaskRequest{
Priority: 1,
Project: pid,
MaxRetries: 0,
Recipe: "{}",
})
createTask(api.CreateTaskRequest{
Priority: 2,
Project: pid,
MaxRetries: 0,
Recipe: "{}",
})
createTask(api.CreateTaskRequest{
Priority: 3,
Project: pid,
MaxRetries: 0,
Recipe: "{}",
})
stats := getProjectStats(pid)
if stats.Ok != true {
t.Error()
}
if stats.Stats.Project.Id != pid {
t.Error()
}
if stats.Stats.NewTaskCount != 3 {
t.Error()
}
if stats.Stats.Assignees[0].Assignee != uuid.Nil {
t.Error()
}
if stats.Stats.Assignees[0].TaskCount != 3 {
t.Error()
}
}
func TestGetProjectStatsNotFound(t *testing.T) {
r := createProject(api.CreateProjectRequest{
Motd: "eeeeeeeeej",
Name: "Namaaaaaaaaaaaa",
Version: "versionsssssssss",
CloneUrl: "http://github.com/drone/test1",
GitRepo: "drone/test1",
Priority: 1,
})
s := getProjectStats(r.Id)
if s.Ok != false {
t.Error()
}
if len(s.Message) <= 0 {
t.Error()
}
}
func createProject(req api.CreateProjectRequest) *api.CreateProjectResponse {
r := Post("/project/create", req)
@@ -137,3 +218,15 @@ func getProject(id int64) (*api.GetProjectResponse, *http.Response) {
return &getResp, r
}
func getProjectStats(id int64) *api.GetProjectStatsResponse {
r := Get(fmt.Sprintf("/project/stats/%d", id))
var getResp api.GetProjectStatsResponse
data, _ := ioutil.ReadAll(r.Body)
err := json.Unmarshal(data, &getResp)
handleErr(err)
return &getResp
}