-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2108 from influxdata/feat/flux-http-query-parameters
fix(http): change /query to use org/orgID
- Loading branch information
Showing
3 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters