fix(http): change /query to use org/orgID

Fixes: #2106
pull/10616/head
Chris Goller 2018-12-20 22:18:09 -06:00
parent 532a3b7294
commit e3a86bbd64
3 changed files with 97 additions and 2 deletions

View File

@ -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.

90
http/requests_test.go Normal file
View File

@ -0,0 +1,90 @@
package http
import (
"context"
"fmt"
"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, fmt.Errorf("unknown ID")
},
},
},
},
{
name: "bad id returns errorn",
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, fmt.Errorf("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)
}
})
}
}

View File

@ -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: