From bdf65f5dfec311495ba2cc445bdd8c300a230c3c Mon Sep 17 00:00:00 2001 From: Lyon Hill Date: Thu, 24 Jan 2019 16:05:24 -0700 Subject: [PATCH] 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. --- http/task_service_test.go | 18 +++--------------- task.go | 2 +- task/servicetest/servicetest.go | 30 ++++++++++++++++-------------- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/http/task_service_test.go b/http/task_service_test.go index 9d9f24a447..0ba937b01a 100644 --- a/http/task_service_test.go +++ b/http/task_service_test.go @@ -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": "" } `, }, diff --git a/task.go b/task.go index 4c2bf99b20..478946c6ee 100644 --- a/task.go +++ b/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"` diff --git a/task/servicetest/servicetest.go b/task/servicetest/servicetest.go index 82112645cc..0e985cb5f4 100644 --- a/task/servicetest/servicetest.go +++ b/task/servicetest/servicetest.go @@ -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) }