From ff2998dcf858f01bcd891d631fc6e32324d7600b Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Thu, 1 Nov 2018 12:03:51 -0700 Subject: [PATCH] chore(chronograf): fix megacheck errors --- chronograf/bolt/client.go | 4 - chronograf/bolt/mapping_test.go | 3 - chronograf/bolt/organizations_test.go | 3 + chronograf/bolt/servers_test.go | 2 +- chronograf/bolt/sources_test.go | 2 +- chronograf/bolt/users_test.go | 6 +- chronograf/enterprise/enterprise_test.go | 4 +- chronograf/enterprise/meta_test.go | 74 ++++++------------- chronograf/filestore/organizations.go | 7 +- chronograf/influx/databases.go | 2 +- chronograf/influx/influx.go | 1 - chronograf/influx/influx_test.go | 12 +-- chronograf/influx/query.go | 6 +- chronograf/oauth2/cookies_test.go | 9 ++- chronograf/oauth2/heroku.go | 4 + chronograf/organizations/dashboards_test.go | 19 +++-- .../organizations/organizations_test.go | 19 +++-- chronograf/organizations/servers_test.go | 19 +++-- chronograf/organizations/sources_test.go | 19 +++-- chronograf/organizations/users.go | 2 +- chronograf/organizations/users_test.go | 10 +-- chronograf/server/auth.go | 2 - chronograf/server/cells_test.go | 5 +- chronograf/server/dashboards_test.go | 4 +- chronograf/server/databases.go | 4 - chronograf/server/mapping_test.go | 3 - chronograf/server/me.go | 12 +-- chronograf/server/me_test.go | 2 - chronograf/server/mux.go | 10 --- chronograf/server/org_config_test.go | 2 +- chronograf/server/organizations_test.go | 8 +- chronograf/server/queryconfig.go | 2 +- chronograf/server/redoc.go | 1 - chronograf/server/routes.go | 4 +- chronograf/server/users.go | 2 +- 35 files changed, 112 insertions(+), 176 deletions(-) diff --git a/chronograf/bolt/client.go b/chronograf/bolt/client.go index e66ed9eb8b..47807c4770 100644 --- a/chronograf/bolt/client.go +++ b/chronograf/bolt/client.go @@ -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)) -} diff --git a/chronograf/bolt/mapping_test.go b/chronograf/bolt/mapping_test.go index efbbaf6c20..0f81999518 100644 --- a/chronograf/bolt/mapping_test.go +++ b/chronograf/bolt/mapping_test.go @@ -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 }{ { diff --git a/chronograf/bolt/organizations_test.go b/chronograf/bolt/organizations_test.go index 4ab3ad10e1..4a534da12e 100644 --- a/chronograf/bolt/organizations_test.go +++ b/chronograf/bolt/organizations_test.go @@ -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 != "" { diff --git a/chronograf/bolt/servers_test.go b/chronograf/bolt/servers_test.go index d9b0082fea..e235ab62ee 100644 --- a/chronograf/bolt/servers_test.go +++ b/chronograf/bolt/servers_test.go @@ -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") } diff --git a/chronograf/bolt/sources_test.go b/chronograf/bolt/sources_test.go index 17abe6a561..6cb29e2212 100644 --- a/chronograf/bolt/sources_test.go +++ b/chronograf/bolt/sources_test.go @@ -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") } diff --git a/chronograf/bolt/users_test.go b/chronograf/bolt/users_test.go index 1cf1df4543..0df5b1b6ef 100644 --- a/chronograf/bolt/users_test.go +++ b/chronograf/bolt/users_test.go @@ -83,10 +83,8 @@ 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 + ctx context.Context + usr *chronograf.User } tests := []struct { name string diff --git a/chronograf/enterprise/enterprise_test.go b/chronograf/enterprise/enterprise_test.go index 7a128bbce0..47b6cb00cd 100644 --- a/chronograf/enterprise/enterprise_test.go +++ b/chronograf/enterprise/enterprise_test.go @@ -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") } } diff --git a/chronograf/enterprise/meta_test.go b/chronograf/enterprise/meta_test.go index 0b2d413cfd..1d0f7be146 100644 --- a/chronograf/enterprise/meta_test.go +++ b/chronograf/enterprise/meta_test.go @@ -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 diff --git a/chronograf/filestore/organizations.go b/chronograf/filestore/organizations.go index 444185dbf3..6c6f1d43ff 100644 --- a/chronograf/filestore/organizations.go +++ b/chronograf/filestore/organizations.go @@ -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) diff --git a/chronograf/influx/databases.go b/chronograf/influx/databases.go index 44d34e8717..13ce69d457 100644 --- a/chronograf/influx/databases.go +++ b/chronograf/influx/databases.go @@ -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{ diff --git a/chronograf/influx/influx.go b/chronograf/influx/influx.go index 0fcc71303d..02c8e69fb4 100644 --- a/chronograf/influx/influx.go +++ b/chronograf/influx/influx.go @@ -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 { diff --git a/chronograf/influx/influx_test.go b/chronograf/influx/influx_test.go index 35aeba24ff..8c5bc9ae4a 100644 --- a/chronograf/influx/influx_test.go +++ b/chronograf/influx/influx_test.go @@ -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") } diff --git a/chronograf/influx/query.go b/chronograf/influx/query.go index 072d55f31d..51cf15445f 100644 --- a/chronograf/influx/query.go +++ b/chronograf/influx/query.go @@ -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) } } diff --git a/chronograf/oauth2/cookies_test.go b/chronograf/oauth2/cookies_test.go index 18ef96191e..004d0836d4 100644 --- a/chronograf/oauth2/cookies_test.go +++ b/chronograf/oauth2/cookies_test.go @@ -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") } diff --git a/chronograf/oauth2/heroku.go b/chronograf/oauth2/heroku.go index 697182231f..a44d75fa12 100644 --- a/chronograf/oauth2/heroku.go +++ b/chronograf/oauth2/heroku.go @@ -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) diff --git a/chronograf/organizations/dashboards_test.go b/chronograf/organizations/dashboards_test.go index 46ef23f77c..8ff6827082 100644 --- a/chronograf/organizations/dashboards_test.go +++ b/chronograf/organizations/dashboards_test.go @@ -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 }{ @@ -219,12 +220,11 @@ func TestDashboards_Get(t *testing.T) { dashboard chronograf.Dashboard } tests := []struct { - name string - fields fields - args args - want chronograf.Dashboard - addFirst bool - wantErr bool + name string + fields fields + args args + want chronograf.Dashboard + wantErr bool }{ { name: "Get Dashboard", @@ -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) } diff --git a/chronograf/organizations/organizations_test.go b/chronograf/organizations/organizations_test.go index 9df04c955c..e95398f1ce 100644 --- a/chronograf/organizations/organizations_test.go +++ b/chronograf/organizations/organizations_test.go @@ -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 }{ @@ -231,12 +232,11 @@ func TestOrganizations_Get(t *testing.T) { organization *chronograf.Organization } tests := []struct { - name string - fields fields - args args - want *chronograf.Organization - addFirst bool - wantErr bool + name string + fields fields + args args + want *chronograf.Organization + wantErr bool }{ { name: "Get Organization", @@ -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) } diff --git a/chronograf/organizations/servers_test.go b/chronograf/organizations/servers_test.go index b67153961d..64eafea694 100644 --- a/chronograf/organizations/servers_test.go +++ b/chronograf/organizations/servers_test.go @@ -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 }{ @@ -220,12 +221,11 @@ func TestServers_Get(t *testing.T) { server chronograf.Server } tests := []struct { - name string - fields fields - args args - want chronograf.Server - addFirst bool - wantErr bool + name string + fields fields + args args + want chronograf.Server + wantErr bool }{ { name: "Get Server", @@ -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) } diff --git a/chronograf/organizations/sources_test.go b/chronograf/organizations/sources_test.go index b35401466a..e97030f4f1 100644 --- a/chronograf/organizations/sources_test.go +++ b/chronograf/organizations/sources_test.go @@ -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 }{ @@ -220,12 +221,11 @@ func TestSources_Get(t *testing.T) { source chronograf.Source } tests := []struct { - name string - fields fields - args args - want chronograf.Source - addFirst bool - wantErr bool + name string + fields fields + args args + want chronograf.Source + wantErr bool }{ { name: "Get Source", @@ -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) } diff --git a/chronograf/organizations/users.go b/chronograf/organizations/users.go index bdada80b06..b2706c4dc7 100644 --- a/chronograf/organizations/users.go +++ b/chronograf/organizations/users.go @@ -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 } diff --git a/chronograf/organizations/users_test.go b/chronograf/organizations/users_test.go index 3eb3f0b45d..25359fe761 100644 --- a/chronograf/organizations/users_test.go +++ b/chronograf/organizations/users_test.go @@ -24,7 +24,6 @@ func TestUsersStore_Get(t *testing.T) { } type args struct { ctx context.Context - usr *chronograf.User userID uint64 orgID string } @@ -149,10 +148,9 @@ func TestUsersStore_Add(t *testing.T) { UsersStore chronograf.UsersStore } type args struct { - ctx context.Context - u *chronograf.User - orgID string - uInitial *chronograf.User + ctx context.Context + u *chronograf.User + orgID string } 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 }{ { diff --git a/chronograf/server/auth.go b/chronograf/server/auth.go index a254c82946..3a4996824e 100644 --- a/chronograf/server/auth.go +++ b/chronograf/server/auth.go @@ -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 }) } diff --git a/chronograf/server/cells_test.go b/chronograf/server/cells_test.go index 32a3eaee70..42917b417b 100644 --- a/chronograf/server/cells_test.go +++ b/chronograf/server/cells_test.go @@ -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, ) diff --git a/chronograf/server/dashboards_test.go b/chronograf/server/dashboards_test.go index 97cb843a36..d2d489d3f1 100644 --- a/chronograf/server/dashboards_test.go +++ b/chronograf/server/dashboards_test.go @@ -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", diff --git a/chronograf/server/databases.go b/chronograf/server/databases.go index 73b726b022..49f1a090aa 100644 --- a/chronograf/server/databases.go +++ b/chronograf/server/databases.go @@ -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"` diff --git a/chronograf/server/mapping_test.go b/chronograf/server/mapping_test.go index a564705397..0a0cdf2c68 100644 --- a/chronograf/server/mapping_test.go +++ b/chronograf/server/mapping_test.go @@ -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 }{ { diff --git a/chronograf/server/me.go b/chronograf/server/me.go index b908016199..235550420b 100644 --- a/chronograf/server/me.go +++ b/chronograf/server/me.go @@ -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 -} diff --git a/chronograf/server/me_test.go b/chronograf/server/me_test.go index 7f99045f47..70db5bd746 100644 --- a/chronograf/server/me_test.go +++ b/chronograf/server/me_test.go @@ -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 diff --git a/chronograf/server/mux.go b/chronograf/server/mux.go index d41d5e3cca..aa9bd8a46b 100644 --- a/chronograf/server/mux.go +++ b/chronograf/server/mux.go @@ -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) diff --git a/chronograf/server/org_config_test.go b/chronograf/server/org_config_test.go index 9c3b1e1495..3b5d117940 100644 --- a/chronograf/server/org_config_test.go +++ b/chronograf/server/org_config_test.go @@ -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) } }) diff --git a/chronograf/server/organizations_test.go b/chronograf/server/organizations_test.go index c655f9cf1e..f760076ccb 100644 --- a/chronograf/server/organizations_test.go +++ b/chronograf/server/organizations_test.go @@ -220,10 +220,9 @@ func TestService_UpdateOrganization(t *testing.T) { Logger chronograf.Logger } type args struct { - w *httptest.ResponseRecorder - r *http.Request - org *organizationRequest - setPtr bool + w *httptest.ResponseRecorder + r *http.Request + org *organizationRequest } 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 diff --git a/chronograf/server/queryconfig.go b/chronograf/server/queryconfig.go index d2e20d207c..15b33c70d6 100644 --- a/chronograf/server/queryconfig.go +++ b/chronograf/server/queryconfig.go @@ -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), } } diff --git a/chronograf/server/redoc.go b/chronograf/server/redoc.go index 77f4e83c0a..4cc39bf27d 100644 --- a/chronograf/server/redoc.go +++ b/chronograf/server/redoc.go @@ -35,6 +35,5 @@ func Redoc(swagger string) http.HandlerFunc { rw.WriteHeader(http.StatusOK) _, _ = rw.Write([]byte(fmt.Sprintf(index, swagger))) - return }) } diff --git a/chronograf/server/routes.go b/chronograf/server/routes.go index 43036b8e9f..659b3e2292 100644 --- a/chronograf/server/routes.go +++ b/chronograf/server/routes.go @@ -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) } diff --git a/chronograf/server/users.go b/chronograf/server/users.go index ea2c5ece9c..c286610ecf 100644 --- a/chronograf/server/users.go +++ b/chronograf/server/users.go @@ -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 }