Remove owner from task json responses (#11504)
* Remove owner from task json responses * allow for crud to run in parallel with other tests To be parallel we just cant assume we only have 1 task.pull/11460/head
parent
c91f2be31d
commit
bdf65f5dfe
|
@ -123,11 +123,7 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
|
|||
"orgID": "0000000000000001",
|
||||
"org": "test",
|
||||
"status": "",
|
||||
"flux": "",
|
||||
"owner": {
|
||||
"id":"0000000000000001",
|
||||
"name":"user1"
|
||||
}
|
||||
"flux": ""
|
||||
},
|
||||
{
|
||||
"links": {
|
||||
|
@ -152,11 +148,7 @@ func TestTaskHandler_handleGetTasks(t *testing.T) {
|
|||
"orgID": "0000000000000002",
|
||||
"org": "test",
|
||||
"status": "",
|
||||
"flux": "",
|
||||
"owner": {
|
||||
"id":"0000000000000002",
|
||||
"name":"user2"
|
||||
}
|
||||
"flux": ""
|
||||
}
|
||||
]
|
||||
}`,
|
||||
|
@ -250,11 +242,7 @@ func TestTaskHandler_handlePostTasks(t *testing.T) {
|
|||
"orgID": "0000000000000001",
|
||||
"org": "test",
|
||||
"status": "",
|
||||
"flux": "",
|
||||
"owner": {
|
||||
"id": "0000000000000001",
|
||||
"name": "user1"
|
||||
}
|
||||
"flux": ""
|
||||
}
|
||||
`,
|
||||
},
|
||||
|
|
2
task.go
2
task.go
|
@ -26,7 +26,7 @@ type Task struct {
|
|||
Organization string `json:"org"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
Owner User `json:"owner"`
|
||||
Owner User `json:"-"`
|
||||
Flux string `json:"flux"`
|
||||
Every string `json:"every,omitempty"`
|
||||
Cron string `json:"cron,omitempty"`
|
||||
|
|
|
@ -108,8 +108,7 @@ type System struct {
|
|||
}
|
||||
|
||||
func testTaskCRUD(t *testing.T, sys *System) {
|
||||
orgID := idGen.ID()
|
||||
userID := idGen.ID()
|
||||
orgID, userID, _ := creds(t, sys)
|
||||
|
||||
// Create a task.
|
||||
task := &platform.Task{OrganizationID: orgID, Owner: platform.User{ID: userID}, Flux: fmt.Sprintf(scriptFmt, 0)}
|
||||
|
@ -120,6 +119,16 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
t.Fatal("no task ID set")
|
||||
}
|
||||
|
||||
findTask := func(tasks []*platform.Task, id platform.ID) *platform.Task {
|
||||
for _, t := range tasks {
|
||||
if t.ID == id {
|
||||
return t
|
||||
}
|
||||
}
|
||||
t.Fatalf("failed to find task by id %s", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Look up a task the different ways we can.
|
||||
// Map of method name to found task.
|
||||
found := map[string]*platform.Task{
|
||||
|
@ -137,28 +146,21 @@ func testTaskCRUD(t *testing.T, sys *System) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(fs) != 1 {
|
||||
t.Fatalf("expected 1 task returned, got %d: %#v", len(fs), fs)
|
||||
}
|
||||
found["FindTasks with Organization filter"] = fs[0]
|
||||
f = findTask(fs, task.ID)
|
||||
found["FindTasks with Organization filter"] = f
|
||||
|
||||
fs, _, err = sys.ts.FindTasks(sys.Ctx, platform.TaskFilter{User: &userID})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(fs) != 1 {
|
||||
t.Fatalf("expected 1 task returned, got %d: %#v", len(fs), fs)
|
||||
}
|
||||
found["FindTasks with User filter"] = fs[0]
|
||||
|
||||
f = findTask(fs, task.ID)
|
||||
found["FindTasks with User filter"] = f
|
||||
|
||||
for fn, f := range found {
|
||||
if f.OrganizationID != orgID {
|
||||
t.Fatalf("%s: wrong organization returned; want %s, got %s", fn, orgID.String(), f.OrganizationID.String())
|
||||
}
|
||||
if f.Owner.ID != userID {
|
||||
t.Fatalf("%s: wrong user returned; want %s, got %s", fn, userID.String(), f.Owner.ID.String())
|
||||
}
|
||||
|
||||
if f.Name != "task #0" {
|
||||
t.Fatalf(`%s: wrong name returned; want "task #0", got %q`, fn, f.Name)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue