Skip to content

Commit

Permalink
fix(tasks): improve logic for tags in kv and make the http test cleaner.
Browse files Browse the repository at this point in the history
  • Loading branch information
lyondhill committed Aug 6, 2019
1 parent 879a78e commit 2ef7d79
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
7 changes: 6 additions & 1 deletion http/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ func TestTaskService(t *testing.T) {
Token: auth.Token,
}

cFunc := func() (servicetest.TestCreds, error) {
cFunc := func(t *testing.T) (servicetest.TestCreds, error) {
org := &platform.Organization{Name: t.Name() + "_org"}
if err := service.CreateOrganization(ctx, org); err != nil {
t.Fatal(err)
}

return servicetest.TestCreds{
OrgID: org.ID,
Org: org.Name,
Expand Down
20 changes: 9 additions & 11 deletions kv/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,16 @@ func (s *Service) findTaskByOrg(ctx context.Context, tx Tx, filter influxdb.Task
return nil, 0, err
}

if filter.Type == nil {
ft := ""
filter.Type = &ft
}
if *filter.Type != influxdb.TaskTypeWildcard && *filter.Type != t.Type {
t = nil
}

// insert the new task into the list
if t != nil {
ts = append(ts, t)

typ := ""
if filter.Type != nil {
typ = *filter.Type
}

// if the filter type matches task type or filter type is a wildcard
if typ == t.Type || typ == influxdb.TaskTypeWildcard {
ts = append(ts, t)
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions task/servicetest/servicetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ type System struct {
// However, if the system needs to verify credentials,
// the caller should set this value and return valid IDs and a valid token.
// It is safe if this returns the same values every time it is called.
CredsFunc func() (TestCreds, error)
CredsFunc func(*testing.T) (TestCreds, error)
}

func testTaskCRUD(t *testing.T, sys *System) {
Expand Down Expand Up @@ -1411,7 +1411,7 @@ func creds(t *testing.T, s *System) TestCreds {
}
}

c, err := s.CredsFunc()
c, err := s.CredsFunc(t)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1522,8 +1522,7 @@ func testTaskType(t *testing.T, sys *System) {
t.Fatal(err)
}

// this is to account for the concurrency test creating tasks in the same organization
if len(tasks) < 3 {
if len(tasks) != 3 {
t.Fatalf("failed to return tasks with wildcard, expected 3, got %d", len(tasks))
}
}

0 comments on commit 2ef7d79

Please sign in to comment.