chore(chronograf): fix megacheck errors
parent
dae3dc8a7e
commit
ff2998dcf8
|
@ -287,7 +287,3 @@ func (c *Client) backup(ctx context.Context, build chronograf.BuildInfo) error {
|
|||
|
||||
return c.copy(ctx, lastBuild.Version)
|
||||
}
|
||||
|
||||
func bucket(b []byte, org string) []byte {
|
||||
return []byte(path.Join(string(b), org))
|
||||
}
|
||||
|
|
|
@ -111,8 +111,6 @@ func TestMappingStore_All(t *testing.T) {
|
|||
type fields struct {
|
||||
mappings []*chronograf.Mapping
|
||||
}
|
||||
type args struct {
|
||||
}
|
||||
type wants struct {
|
||||
mappings []chronograf.Mapping
|
||||
err error
|
||||
|
@ -120,7 +118,6 @@ func TestMappingStore_All(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wants wants
|
||||
}{
|
||||
{
|
||||
|
|
|
@ -406,6 +406,9 @@ func TestOrganizationsStore_Update(t *testing.T) {
|
|||
|
||||
if tt.addFirst {
|
||||
tt.args.initial, err = s.Add(tt.args.ctx, tt.args.initial)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if tt.args.updates.Name != "" {
|
||||
|
|
|
@ -90,7 +90,7 @@ func TestServerStore(t *testing.T) {
|
|||
|
||||
if actual, err := s.Get(ctx, srcs[0].ID); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if actual.Active == true {
|
||||
} else if actual.Active {
|
||||
t.Fatal("Able to set two active servers when only one should be permitted")
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ func TestSourceStore(t *testing.T) {
|
|||
|
||||
if actual, err := s.Get(ctx, srcs[0].ID); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if actual.Default == true {
|
||||
} else if actual.Default {
|
||||
t.Fatal("Able to set two default sources when only one should be permitted")
|
||||
}
|
||||
|
||||
|
|
|
@ -84,8 +84,6 @@ func TestUsersStore_GetWithID(t *testing.T) {
|
|||
func TestUsersStore_GetWithNameProviderScheme(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
name string
|
||||
provider string
|
||||
usr *chronograf.User
|
||||
}
|
||||
tests := []struct {
|
||||
|
|
|
@ -34,7 +34,7 @@ func Test_Enterprise_FetchesDataNodes(t *testing.T) {
|
|||
t.Fatal("Unexpected error while creating enterprise client. err:", err)
|
||||
}
|
||||
|
||||
if showClustersCalled != true {
|
||||
if !showClustersCalled {
|
||||
t.Fatal("Expected request to meta node but none was issued")
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func Test_Enterprise_IssuesQueries(t *testing.T) {
|
|||
t.Fatal("Unexpected error while querying data node: err:", err)
|
||||
}
|
||||
|
||||
if called == false {
|
||||
if !called {
|
||||
t.Fatal("Expected request to data node but none was received")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,9 +19,7 @@ import (
|
|||
func TestMetaClient_ShowCluster(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -112,7 +110,7 @@ func TestMetaClient_ShowCluster(t *testing.T) {
|
|||
if tt.wantErr {
|
||||
continue
|
||||
}
|
||||
reqs := tt.fields.client.(*MockClient).Requests
|
||||
reqs := tt.fields.client.Requests
|
||||
if len(reqs) != 1 {
|
||||
t.Errorf("%q. MetaClient.ShowCluster() expected 1 but got %d", tt.name, len(reqs))
|
||||
continue
|
||||
|
@ -130,9 +128,7 @@ func TestMetaClient_ShowCluster(t *testing.T) {
|
|||
func TestMetaClient_Users(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -267,9 +263,7 @@ func TestMetaClient_Users(t *testing.T) {
|
|||
func TestMetaClient_User(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -368,9 +362,7 @@ func TestMetaClient_User(t *testing.T) {
|
|||
func TestMetaClient_CreateUser(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -417,7 +409,7 @@ func TestMetaClient_CreateUser(t *testing.T) {
|
|||
if tt.wantErr {
|
||||
continue
|
||||
}
|
||||
reqs := tt.fields.client.(*MockClient).Requests
|
||||
reqs := tt.fields.client.Requests
|
||||
if len(reqs) != 1 {
|
||||
t.Errorf("%q. MetaClient.CreateUser() expected 1 but got %d", tt.name, len(reqs))
|
||||
continue
|
||||
|
@ -439,9 +431,7 @@ func TestMetaClient_CreateUser(t *testing.T) {
|
|||
func TestMetaClient_ChangePassword(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -489,7 +479,7 @@ func TestMetaClient_ChangePassword(t *testing.T) {
|
|||
if tt.wantErr {
|
||||
continue
|
||||
}
|
||||
reqs := tt.fields.client.(*MockClient).Requests
|
||||
reqs := tt.fields.client.Requests
|
||||
if len(reqs) != 1 {
|
||||
t.Errorf("%q. MetaClient.ChangePassword() expected 1 but got %d", tt.name, len(reqs))
|
||||
continue
|
||||
|
@ -511,9 +501,7 @@ func TestMetaClient_ChangePassword(t *testing.T) {
|
|||
func TestMetaClient_DeleteUser(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -558,7 +546,7 @@ func TestMetaClient_DeleteUser(t *testing.T) {
|
|||
if tt.wantErr {
|
||||
continue
|
||||
}
|
||||
reqs := tt.fields.client.(*MockClient).Requests
|
||||
reqs := tt.fields.client.Requests
|
||||
if len(reqs) != 1 {
|
||||
t.Errorf("%q. MetaClient.DeleteUser() expected 1 but got %d", tt.name, len(reqs))
|
||||
continue
|
||||
|
@ -580,9 +568,7 @@ func TestMetaClient_DeleteUser(t *testing.T) {
|
|||
func TestMetaClient_SetUserPerms(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -655,7 +641,7 @@ func TestMetaClient_SetUserPerms(t *testing.T) {
|
|||
if tt.wantErr {
|
||||
continue
|
||||
}
|
||||
reqs := tt.fields.client.(*MockClient).Requests
|
||||
reqs := tt.fields.client.Requests
|
||||
if len(reqs) < 2 {
|
||||
t.Errorf("%q. MetaClient.SetUserPerms() expected 2 but got %d", tt.name, len(reqs))
|
||||
continue
|
||||
|
@ -701,9 +687,7 @@ func TestMetaClient_SetUserPerms(t *testing.T) {
|
|||
func TestMetaClient_Roles(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -800,9 +784,7 @@ func TestMetaClient_Roles(t *testing.T) {
|
|||
func TestMetaClient_Role(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -883,9 +865,7 @@ func TestMetaClient_Role(t *testing.T) {
|
|||
func TestMetaClient_UserRoles(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -987,9 +967,7 @@ func TestMetaClient_UserRoles(t *testing.T) {
|
|||
func TestMetaClient_CreateRole(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -1031,7 +1009,7 @@ func TestMetaClient_CreateRole(t *testing.T) {
|
|||
if err := m.CreateRole(tt.args.ctx, tt.args.name); (err != nil) != tt.wantErr {
|
||||
t.Errorf("%q. MetaClient.CreateRole() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
||||
}
|
||||
reqs := tt.fields.client.(*MockClient).Requests
|
||||
reqs := tt.fields.client.Requests
|
||||
if len(reqs) != 1 {
|
||||
t.Errorf("%q. MetaClient.CreateRole() expected 1 but got %d", tt.name, len(reqs))
|
||||
continue
|
||||
|
@ -1053,9 +1031,7 @@ func TestMetaClient_CreateRole(t *testing.T) {
|
|||
func TestMetaClient_DeleteRole(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -1100,7 +1076,7 @@ func TestMetaClient_DeleteRole(t *testing.T) {
|
|||
if tt.wantErr {
|
||||
continue
|
||||
}
|
||||
reqs := tt.fields.client.(*MockClient).Requests
|
||||
reqs := tt.fields.client.Requests
|
||||
if len(reqs) != 1 {
|
||||
t.Errorf("%q. MetaClient.DeleteRole() expected 1 but got %d", tt.name, len(reqs))
|
||||
continue
|
||||
|
@ -1122,9 +1098,7 @@ func TestMetaClient_DeleteRole(t *testing.T) {
|
|||
func TestMetaClient_SetRolePerms(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -1197,7 +1171,7 @@ func TestMetaClient_SetRolePerms(t *testing.T) {
|
|||
if tt.wantErr {
|
||||
continue
|
||||
}
|
||||
reqs := tt.fields.client.(*MockClient).Requests
|
||||
reqs := tt.fields.client.Requests
|
||||
if len(reqs) < 2 {
|
||||
t.Errorf("%q. MetaClient.SetRolePerms() expected 2 but got %d", tt.name, len(reqs))
|
||||
continue
|
||||
|
@ -1243,9 +1217,7 @@ func TestMetaClient_SetRolePerms(t *testing.T) {
|
|||
func TestMetaClient_SetRoleUsers(t *testing.T) {
|
||||
type fields struct {
|
||||
URL *url.URL
|
||||
client interface {
|
||||
Do(URL *url.URL, path, method string, authorizer influx.Authorizer, params map[string]string, body io.Reader) (*http.Response, error)
|
||||
}
|
||||
client *MockClient
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
@ -1315,7 +1287,7 @@ func TestMetaClient_SetRoleUsers(t *testing.T) {
|
|||
if tt.wantErr {
|
||||
continue
|
||||
}
|
||||
reqs := tt.fields.client.(*MockClient).Requests
|
||||
reqs := tt.fields.client.Requests
|
||||
if len(reqs) != len(tt.wants)+1 {
|
||||
t.Errorf("%q. MetaClient.SetRoleUsers() expected %d but got %d", tt.name, len(tt.wants)+1, len(reqs))
|
||||
continue
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
// OrgExt is the the file extension searched for in the directory for org files
|
||||
const OrgExt = ".org"
|
||||
|
||||
var _ chronograf.OrganizationsStore = &Organizations{}
|
||||
var _ chronograf.OrganizationsStore = (*Organizations)(nil)
|
||||
|
||||
// Organizations are JSON orgs stored in the filesystem
|
||||
type Organizations struct {
|
||||
|
@ -33,11 +33,6 @@ func NewOrganizations(dir string, logger chronograf.Logger) chronograf.Organizat
|
|||
}
|
||||
}
|
||||
|
||||
func orgFile(dir string, org chronograf.Organization) string {
|
||||
base := fmt.Sprintf("%s%s", org.Name, OrgExt)
|
||||
return path.Join(dir, base)
|
||||
}
|
||||
|
||||
// All returns all orgs from the directory
|
||||
func (o *Organizations) All(ctx context.Context) ([]chronograf.Organization, error) {
|
||||
files, err := o.ReadDir(o.Dir)
|
||||
|
|
|
@ -99,7 +99,7 @@ func (c *Client) UpdateRP(ctx context.Context, db string, rp string, upd *chrono
|
|||
if len(upd.ShardDuration) > 0 {
|
||||
buffer.WriteString(" SHARD DURATION " + upd.ShardDuration)
|
||||
}
|
||||
if upd.Default == true {
|
||||
if upd.Default {
|
||||
buffer.WriteString(" DEFAULT")
|
||||
}
|
||||
queryRes, err := c.Query(ctx, chronograf.Query{
|
||||
|
|
|
@ -349,7 +349,6 @@ func (c *Client) write(ctx context.Context, u *url.URL, db, rp, lp string) error
|
|||
}
|
||||
|
||||
errChan <- errors.New(response.Err)
|
||||
return
|
||||
}()
|
||||
|
||||
select {
|
||||
|
|
|
@ -58,7 +58,7 @@ func Test_Influx_MakesRequestsToQueryEndpoint(t *testing.T) {
|
|||
t.Fatal("Expected no error but was", err)
|
||||
}
|
||||
|
||||
if called == false {
|
||||
if !called {
|
||||
t.Error("Expected http request to Influx but there was none")
|
||||
}
|
||||
}
|
||||
|
@ -164,6 +164,9 @@ func Test_Influx_AuthorizationBearerCtx(t *testing.T) {
|
|||
URL: ts.URL,
|
||||
InsecureSkipVerify: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
query := chronograf.Query{
|
||||
Command: "show databases",
|
||||
|
@ -226,10 +229,9 @@ func Test_Influx_HTTPS_Failure(t *testing.T) {
|
|||
t.Error("Expected error but was successful")
|
||||
}
|
||||
|
||||
if called == true {
|
||||
if called {
|
||||
t.Error("Expected http request to fail, but, succeeded")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func Test_Influx_HTTPS_InsecureSkipVerify(t *testing.T) {
|
||||
|
@ -271,7 +273,7 @@ func Test_Influx_HTTPS_InsecureSkipVerify(t *testing.T) {
|
|||
t.Fatal("Expected no error but was", err)
|
||||
}
|
||||
|
||||
if called == false {
|
||||
if !called {
|
||||
t.Error("Expected http request to Influx but there was none")
|
||||
}
|
||||
called = false
|
||||
|
@ -284,7 +286,7 @@ func Test_Influx_HTTPS_InsecureSkipVerify(t *testing.T) {
|
|||
t.Fatal("Expected no error but was", err)
|
||||
}
|
||||
|
||||
if called == false {
|
||||
if !called {
|
||||
t.Error("Expected http request to Influx but there was none")
|
||||
}
|
||||
|
||||
|
|
|
@ -95,13 +95,13 @@ func Convert(influxQL string) (chronograf.QueryConfig, error) {
|
|||
GroupBy: chronograf.GroupBy{
|
||||
Tags: []string{},
|
||||
},
|
||||
Tags: make(map[string][]string, 0),
|
||||
Tags: make(map[string][]string),
|
||||
}
|
||||
qc := chronograf.QueryConfig{
|
||||
GroupBy: chronograf.GroupBy{
|
||||
Tags: []string{},
|
||||
},
|
||||
Tags: make(map[string][]string, 0),
|
||||
Tags: make(map[string][]string),
|
||||
}
|
||||
|
||||
if len(query.Statements) != 1 {
|
||||
|
@ -286,8 +286,6 @@ func Convert(influxQL string) (chronograf.QueryConfig, error) {
|
|||
qc.Range = &chronograf.DurationRange{
|
||||
Lower: "now() - " + shortDur(dur),
|
||||
}
|
||||
} else {
|
||||
strings.Replace(influxQL, "now() - 15m", ":dashboardTime:", 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package oauth2
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
gojwt "github.com/dgrijalva/jwt-go"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -11,6 +10,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
gojwt "github.com/dgrijalva/jwt-go"
|
||||
)
|
||||
|
||||
type MockTokenizer struct {
|
||||
|
@ -78,7 +79,7 @@ func TestCookieAuthorize(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
|
||||
cookies := w.HeaderMap["Set-Cookie"]
|
||||
cookies := w.Header()["Set-Cookie"]
|
||||
|
||||
if len(cookies) == 0 {
|
||||
t.Fatal("Expected some cookies but got zero")
|
||||
|
@ -275,12 +276,12 @@ func TestCookieExtend(t *testing.T) {
|
|||
t.Errorf("cookie.Extend() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if tt.wantErr == false {
|
||||
if !tt.wantErr {
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("cookie.Extend() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
||||
cookies := tt.args.w.HeaderMap["Set-Cookie"]
|
||||
cookies := tt.args.w.Header()["Set-Cookie"]
|
||||
if len(cookies) == 0 {
|
||||
t.Fatal("Expected some cookies but got zero")
|
||||
}
|
||||
|
|
|
@ -63,6 +63,10 @@ func (h *Heroku) PrincipalID(provider *http.Client) (string, error) {
|
|||
}
|
||||
|
||||
req, err := http.NewRequest("GET", HerokuAccountRoute, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Requests fail to Heroku unless this Accept header is set.
|
||||
req.Header.Set("Accept", "application/vnd.heroku+json; version=3")
|
||||
resp, err := provider.Do(req)
|
||||
|
|
|
@ -32,7 +32,6 @@ func TestDashboards_All(t *testing.T) {
|
|||
args args
|
||||
fields fields
|
||||
want []chronograf.Dashboard
|
||||
wantRaw []chronograf.Dashboard
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -147,6 +146,9 @@ func TestDashboards_Add(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
got, err := s.Get(tt.args.ctx, d.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(got, tt.want, dashboardCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. DashboardsStore.Add():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
|
@ -166,7 +168,6 @@ func TestDashboards_Delete(t *testing.T) {
|
|||
name string
|
||||
fields fields
|
||||
args args
|
||||
want []chronograf.Dashboard
|
||||
addFirst bool
|
||||
wantErr bool
|
||||
}{
|
||||
|
@ -223,7 +224,6 @@ func TestDashboards_Get(t *testing.T) {
|
|||
fields fields
|
||||
args args
|
||||
want chronograf.Dashboard
|
||||
addFirst bool
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -332,6 +332,9 @@ func TestDashboards_Update(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
got, err := s.Get(tt.args.ctx, tt.args.dashboard.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(got, tt.want, dashboardCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. DashboardsStore.Update():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ func TestOrganizations_All(t *testing.T) {
|
|||
args args
|
||||
fields fields
|
||||
want []chronograf.Organization
|
||||
wantRaw []chronograf.Organization
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -161,6 +160,9 @@ func TestOrganizations_Add(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
got, err := s.Get(tt.args.ctx, chronograf.OrganizationQuery{ID: &d.ID})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(got, tt.want, organizationCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. OrganizationsStore.Add():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
|
@ -180,7 +182,6 @@ func TestOrganizations_Delete(t *testing.T) {
|
|||
name string
|
||||
fields fields
|
||||
args args
|
||||
want []chronograf.Organization
|
||||
addFirst bool
|
||||
wantErr bool
|
||||
}{
|
||||
|
@ -235,7 +236,6 @@ func TestOrganizations_Get(t *testing.T) {
|
|||
fields fields
|
||||
args args
|
||||
want *chronograf.Organization
|
||||
addFirst bool
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -338,6 +338,9 @@ func TestOrganizations_Update(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
got, err := s.Get(tt.args.ctx, chronograf.OrganizationQuery{ID: &tt.args.organization.ID})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(got, tt.want, organizationCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. OrganizationsStore.Update():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ func TestServers_All(t *testing.T) {
|
|||
args args
|
||||
fields fields
|
||||
want []chronograf.Server
|
||||
wantRaw []chronograf.Server
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -148,6 +147,9 @@ func TestServers_Add(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
got, err := s.Get(tt.args.ctx, d.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(got, tt.want, serverCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. ServersStore.Add():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
|
@ -167,7 +169,6 @@ func TestServers_Delete(t *testing.T) {
|
|||
name string
|
||||
fields fields
|
||||
args args
|
||||
want []chronograf.Server
|
||||
addFirst bool
|
||||
wantErr bool
|
||||
}{
|
||||
|
@ -224,7 +225,6 @@ func TestServers_Get(t *testing.T) {
|
|||
fields fields
|
||||
args args
|
||||
want chronograf.Server
|
||||
addFirst bool
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -333,6 +333,9 @@ func TestServers_Update(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
got, err := s.Get(tt.args.ctx, tt.args.server.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(got, tt.want, serverCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. ServersStore.Update():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ func TestSources_All(t *testing.T) {
|
|||
args args
|
||||
fields fields
|
||||
want []chronograf.Source
|
||||
wantRaw []chronograf.Source
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -148,6 +147,9 @@ func TestSources_Add(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
got, err := s.Get(tt.args.ctx, d.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(got, tt.want, sourceCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. SourcesStore.Add():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
|
@ -167,7 +169,6 @@ func TestSources_Delete(t *testing.T) {
|
|||
name string
|
||||
fields fields
|
||||
args args
|
||||
want []chronograf.Source
|
||||
addFirst bool
|
||||
wantErr bool
|
||||
}{
|
||||
|
@ -224,7 +225,6 @@ func TestSources_Get(t *testing.T) {
|
|||
fields fields
|
||||
args args
|
||||
want chronograf.Source
|
||||
addFirst bool
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -333,6 +333,9 @@ func TestSources_Update(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
got, err := s.Get(tt.args.ctx, tt.args.source.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff := cmp.Diff(got, tt.want, sourceCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. SourcesStore.Update():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ func (s *UsersStore) Add(ctx context.Context, u *chronograf.User) (*chronograf.U
|
|||
// If the user being added already existed in a previous organization, and was already a SuperAdmin,
|
||||
// then this ensures that they retain their SuperAdmin status. And if they weren't a SuperAdmin, and
|
||||
// the user being added has been granted SuperAdmin status, they will be promoted
|
||||
if u.SuperAdmin == true {
|
||||
if u.SuperAdmin {
|
||||
usr.SuperAdmin = true
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ func TestUsersStore_Get(t *testing.T) {
|
|||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
usr *chronograf.User
|
||||
userID uint64
|
||||
orgID string
|
||||
}
|
||||
|
@ -152,7 +151,6 @@ func TestUsersStore_Add(t *testing.T) {
|
|||
ctx context.Context
|
||||
u *chronograf.User
|
||||
orgID string
|
||||
uInitial *chronograf.User
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -576,7 +574,6 @@ func TestUsersStore_Delete(t *testing.T) {
|
|||
fields fields
|
||||
args args
|
||||
wantErr bool
|
||||
wantRaw *chronograf.User
|
||||
}{
|
||||
{
|
||||
name: "No such user",
|
||||
|
@ -672,7 +669,6 @@ func TestUsersStore_Update(t *testing.T) {
|
|||
fields fields
|
||||
args args
|
||||
want *chronograf.User
|
||||
wantRaw *chronograf.User
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
|
|
@ -52,7 +52,6 @@ func AuthorizedToken(auth oauth2.Authenticator, logger chronograf.Logger, next h
|
|||
// Send the principal to the next handler
|
||||
ctx = context.WithValue(ctx, oauth2.PrincipalKey, principal)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -210,7 +209,6 @@ func AuthorizedUser(
|
|||
}
|
||||
|
||||
Error(w, http.StatusForbidden, "User is not authorized", logger)
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -212,7 +212,6 @@ func Test_Service_DashboardCells(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
// setup context with params
|
||||
ctx := context.Background()
|
||||
params := httprouter.Params{}
|
||||
for k, v := range test.ctxParams {
|
||||
params = append(params, httprouter.Param{
|
||||
|
@ -220,8 +219,8 @@ func Test_Service_DashboardCells(t *testing.T) {
|
|||
Value: v,
|
||||
})
|
||||
}
|
||||
ctx = context.WithValue(
|
||||
context.TODO(),
|
||||
ctx := context.WithValue(
|
||||
context.Background(),
|
||||
httprouter.ParamsKey,
|
||||
params,
|
||||
)
|
||||
|
|
|
@ -277,7 +277,7 @@ func Test_newDashboardResponse(t *testing.T) {
|
|||
GroupBy: chronograf.GroupBy{
|
||||
Tags: []string{},
|
||||
},
|
||||
Tags: make(map[string][]string, 0),
|
||||
Tags: make(map[string][]string),
|
||||
AreTagsAccepted: false,
|
||||
Shifts: []chronograf.TimeShift{
|
||||
{
|
||||
|
@ -339,7 +339,7 @@ func Test_newDashboardResponse(t *testing.T) {
|
|||
GroupBy: chronograf.GroupBy{
|
||||
Tags: []string{},
|
||||
},
|
||||
Tags: make(map[string][]string, 0),
|
||||
Tags: make(map[string][]string),
|
||||
AreTagsAccepted: false,
|
||||
Range: &chronograf.DurationRange{
|
||||
Lower: "now() - 15m",
|
||||
|
|
|
@ -71,10 +71,6 @@ func (r *rpResponse) WithLinks(srcID int, db string) {
|
|||
}
|
||||
}
|
||||
|
||||
type rpsResponse struct {
|
||||
RetentionPolicies []rpResponse `json:"retentionPolicies"`
|
||||
}
|
||||
|
||||
type measurementLinks struct {
|
||||
Self string `json:"self"`
|
||||
First string `json:"first"`
|
||||
|
|
|
@ -19,8 +19,6 @@ func TestMappings_All(t *testing.T) {
|
|||
type fields struct {
|
||||
MappingsStore chronograf.MappingsStore
|
||||
}
|
||||
type args struct {
|
||||
}
|
||||
type wants struct {
|
||||
statusCode int
|
||||
contentType string
|
||||
|
@ -30,7 +28,6 @@ func TestMappings_All(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
wants wants
|
||||
}{
|
||||
{
|
||||
|
|
|
@ -153,7 +153,7 @@ func (s *Service) UpdateMe(auth oauth2.Authenticator) func(http.ResponseWriter,
|
|||
return
|
||||
}
|
||||
|
||||
if u.SuperAdmin == false {
|
||||
if !u.SuperAdmin {
|
||||
// Since a user is not a part of this organization and not a super admin,
|
||||
// we should tell them that they are Forbidden (403) from accessing this resource
|
||||
Error(w, http.StatusForbidden, chronograf.ErrUserNotFound.Error(), s.Logger)
|
||||
|
@ -399,13 +399,3 @@ func (s *Service) usersOrganizations(ctx context.Context, u *chronograf.User) ([
|
|||
|
||||
return orgs, nil
|
||||
}
|
||||
|
||||
func hasRoleInDefaultOrganization(u *chronograf.User, orgID string) bool {
|
||||
for _, role := range u.Roles {
|
||||
if role.Organization == orgID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ import (
|
|||
"github.com/influxdata/platform/chronograf/roles"
|
||||
)
|
||||
|
||||
type MockUsers struct{}
|
||||
|
||||
func TestService_Me(t *testing.T) {
|
||||
type fields struct {
|
||||
UsersStore chronograf.UsersStore
|
||||
|
|
|
@ -448,16 +448,6 @@ func paramID(key string, r *http.Request) (int, error) {
|
|||
return id, nil
|
||||
}
|
||||
|
||||
func paramInt64(key string, r *http.Request) (int64, error) {
|
||||
ctx := r.Context()
|
||||
param := jhttprouter.ParamsFromContext(ctx).ByName(key)
|
||||
v, err := strconv.ParseInt(param, 10, 64)
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("Error converting parameter %s", param)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func paramStr(key string, r *http.Request) (string, error) {
|
||||
ctx := r.Context()
|
||||
param := jhttprouter.ParamsFromContext(ctx).ByName(key)
|
||||
|
|
|
@ -1069,7 +1069,7 @@ func Test_validLogViewerConfig(t *testing.T) {
|
|||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := validLogViewerConfig(tt.args.LogViewer)
|
||||
|
||||
if (tt.wantErr == true && got == nil) || (tt.wantErr == false && got != nil) {
|
||||
if (tt.wantErr && got == nil) || (!tt.wantErr && got != nil) {
|
||||
t.Errorf("%q. validLogViewerConfig().\ngot: %v\nwantErr: %v", tt.name, got, tt.wantErr)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -223,7 +223,6 @@ func TestService_UpdateOrganization(t *testing.T) {
|
|||
w *httptest.ResponseRecorder
|
||||
r *http.Request
|
||||
org *organizationRequest
|
||||
setPtr bool
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -520,7 +519,6 @@ func TestService_NewOrganization(t *testing.T) {
|
|||
name string
|
||||
fields fields
|
||||
args args
|
||||
id string
|
||||
wantStatus int
|
||||
wantContentType string
|
||||
wantBody string
|
||||
|
|
|
@ -21,7 +21,7 @@ func ToQueryConfig(query string) chronograf.QueryConfig {
|
|||
GroupBy: chronograf.GroupBy{
|
||||
Tags: []string{},
|
||||
},
|
||||
Tags: make(map[string][]string, 0),
|
||||
Tags: make(map[string][]string),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,5 @@ func Redoc(swagger string) http.HandlerFunc {
|
|||
rw.WriteHeader(http.StatusOK)
|
||||
|
||||
_, _ = rw.Write([]byte(fmt.Sprintf(index, swagger)))
|
||||
return
|
||||
})
|
||||
}
|
||||
|
|
|
@ -116,9 +116,7 @@ func (a *AllRoutes) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
routes.Logout = &a.LogoutLink
|
||||
}
|
||||
|
||||
for i, route := range a.AuthRoutes {
|
||||
routes.Auth[i] = route
|
||||
}
|
||||
copy(routes.Auth, a.AuthRoutes)
|
||||
|
||||
encodeJSON(w, http.StatusOK, routes, a.Logger)
|
||||
}
|
||||
|
|
|
@ -301,7 +301,7 @@ func (s *Service) UpdateUser(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
// If the user being updated is the user making the request and they are
|
||||
// changing their SuperAdmin status, return an unauthorized error
|
||||
if ctxUser.ID == u.ID && u.SuperAdmin == true && req.SuperAdmin == false {
|
||||
if ctxUser.ID == u.ID && u.SuperAdmin && !req.SuperAdmin {
|
||||
Error(w, http.StatusUnauthorized, "user cannot modify their own SuperAdmin status", s.Logger)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue