Skip to content

Commit

Permalink
Merge pull request #2108 from influxdata/feat/flux-http-query-parameters
Browse files Browse the repository at this point in the history
fix(http): change /query to use org/orgID
  • Loading branch information
goller authored Dec 21, 2018
2 parents c0c8a90 + a33f3ff commit 38a3e94
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
4 changes: 2 additions & 2 deletions http/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

const (
// OrgName is the http query parameter to specify an organization by name.
OrgName = "organization"
OrgName = "org"
// OrgID is the http query parameter to specify an organization by ID.
OrgID = "organizationID"
OrgID = "orgID"
)

// queryOrganization returns the organization for any http request.
Expand Down
95 changes: 95 additions & 0 deletions http/requests_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package http

import (
"context"
"net/http"
"net/http/httptest"
"reflect"
"testing"

"github.com/influxdata/platform"
"github.com/influxdata/platform/mock"
)

func Test_queryOrganization(t *testing.T) {
type args struct {
ctx context.Context
r *http.Request
svc platform.OrganizationService
}
tests := []struct {
name string
args args
want *platform.Organization
wantErr bool
}{
{
name: "org id finds organization",
want: &platform.Organization{
ID: platform.ID(1),
},
args: args{
ctx: context.Background(),
r: httptest.NewRequest(http.MethodPost, "/api/v2/query?orgID=0000000000000001", nil),
svc: &mock.OrganizationService{
FindOrganizationF: func(ctx context.Context, filter platform.OrganizationFilter) (*platform.Organization, error) {
if *filter.ID == platform.ID(1) {
return &platform.Organization{
ID: platform.ID(1),
}, nil
}
return nil, &platform.Error{
Code: platform.EInvalid,
Msg: "unknown org name",
}
},
},
},
},
{
name: "bad id returns error",
wantErr: true,
args: args{
ctx: context.Background(),
r: httptest.NewRequest(http.MethodPost, "/api/v2/query?orgID=howdy", nil),
},
},
{
name: "org name finds organization",
want: &platform.Organization{
ID: platform.ID(1),
Name: "org1",
},
args: args{
ctx: context.Background(),
r: httptest.NewRequest(http.MethodPost, "/api/v2/query?org=org1", nil),
svc: &mock.OrganizationService{
FindOrganizationF: func(ctx context.Context, filter platform.OrganizationFilter) (*platform.Organization, error) {
if *filter.Name == "org1" {
return &platform.Organization{
ID: platform.ID(1),
Name: "org1",
}, nil
}
return nil, &platform.Error{
Code: platform.EInvalid,
Msg: "unknown org name",
}
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := queryOrganization(tt.args.ctx, tt.args.r, tt.args.svc)
if (err != nil) != tt.wantErr {
t.Errorf("queryOrganization() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("queryOrganization() = %v, want %v", got, tt.want)
}
})
}
}
5 changes: 5 additions & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,11 @@ paths:
description: specifies the name of the organization executing the query.
schema:
type: string
- in: query
name: orgID
description: specifies the ID of the organization executing the query.
schema:
type: string
requestBody:
description: flux query or specification to execute
content:
Expand Down

0 comments on commit 38a3e94

Please sign in to comment.