Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable more linters on CI #225

Merged
merged 8 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ jobs:

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
args: --timeout=3m
args: >
--enable=goimports,gosimple,nilerr,prealloc,revive,staticcheck,unconvert,unused,whitespace,zerologlint
--timeout=3m

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
Expand Down
10 changes: 5 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2021, 2022 Red Hat, Inc.
Copyright © 2021, 2022, 2023 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -279,7 +279,6 @@ func updateConfigFromClowder(c *ConfigStruct) error {
c.Storage.PGUsername = clowder.LoadedConfig.Database.Username
c.Storage.PGPassword = clowder.LoadedConfig.Database.Password
}

} else {
fmt.Println("Clowder is disabled")
}
Expand All @@ -289,28 +288,29 @@ func updateConfigFromClowder(c *ConfigStruct) error {

// GetOrganizationsToExport retrieves org_id list from provided CSV file
func GetOrganizationsToExport(config *ConfigStruct) ([]string, error) {
const errorMessage = "GetOrganizationsToExport"
if !config.Storage.EnableOrgIDFiltering {
log.Info().Msg("Selective export based on org_ids disabled")
return nil, nil
}

if config.Storage.OrganizationIDsCSVFile == "" {
err := errors.New("Selective export based on org_ids enabled, but none supplied")
log.Error().Err(err)
log.Error().Err(err).Msg(errorMessage)
return nil, err
}

organizationIDsData, err := os.ReadFile(config.Storage.OrganizationIDsCSVFile)
if err != nil {
err := errors.New("Organization IDs file could not be opened")
log.Error().Err(err)
log.Error().Err(err).Msg(errorMessage)
return nil, err
}

organizationsToExport, err := LoadOrgIDsFromCSV(bytes.NewBuffer(organizationIDsData))
if err != nil {
err := errors.New("Organization IDs CSV file could not be processed")
log.Error().Err(err)
log.Error().Err(err).Msg(errorMessage)
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2021, 2022 Red Hat, Inc.
Copyright © 2021, 2022, 2023 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -60,7 +60,7 @@ func mustSetEnv(t *testing.T, key, val string) {

// TestLoadDefaultConfiguration test loads a configuration file for testing
// with check that load was correct
func TestLoadDefaultConfiguration(t *testing.T) {
func TestLoadDefaultConfiguration(_ *testing.T) {
os.Clearenv()
mustLoadConfiguration("nonExistingEnvVar")
}
Expand Down
9 changes: 3 additions & 6 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func constructIgnoredTablesMap(input string) IgnoredTables {
tables := strings.Split(input, ",")

// prepare empty map with given capacity
var m IgnoredTables = make(IgnoredTables, len(tables))
var m = make(IgnoredTables, len(tables))

// don't add empty string into a map
if input == "" {
Expand Down Expand Up @@ -201,7 +201,6 @@ func performDataExportToS3(configuration *ConfigStruct,
exportDisabledRules bool,
operationLogger *zerolog.Logger, limit int,
ignoredTables IgnoredTables) (int, error) {

operationLogger.Info().Msg("Exporting to S3")

operationLogger.Info().Msg(readingListOfTables)
Expand Down Expand Up @@ -313,12 +312,11 @@ func performDataExportToS3(configuration *ConfigStruct,
}

// performDataExportToFiles exports all tables and metadata info files
func performDataExportToFiles(configuration *ConfigStruct,
func performDataExportToFiles(_ *ConfigStruct,
storage *DBStorage, exportMetadata bool,
exportDisabledRules bool,
operationLogger *zerolog.Logger, limit int,
ignoredTables IgnoredTables) (int, error) {

operationLogger.Info().Msg("Exporting to file")

operationLogger.Info().Msg(readingListOfTables)
Expand Down Expand Up @@ -506,7 +504,7 @@ func parseFlags() (cliFlags CliFlags) {
type DummyWriter struct{}

// Write method satisfies noop io.Write
func (w DummyWriter) Write(p []byte) (n int, err error) {
func (w DummyWriter) Write(_ []byte) (n int, err error) {
return 0, nil
}

Expand Down Expand Up @@ -534,7 +532,6 @@ func createOperationLog(cliFlags CliFlags, buffer *bytes.Buffer) (zerolog.Logger
}

return dummyLogger, nil

}

func setObjectPrefix(prefix, object string) string {
Expand Down
5 changes: 1 addition & 4 deletions s3.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2021, 2022 Red Hat, Inc.
Copyright © 2021, 2022, 2023 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -94,7 +94,6 @@ func NewS3Connection(configuration *ConfigStruct) (*minio.Client, context.Contex
// accessed by current client
func s3BucketExists(ctx context.Context, minioClient *minio.Client,
bucketName string) (bool, error) {

// check if Minio client has been passed to this function
if minioClient == nil {
err := errors.New(minioClientIsNil)
Expand Down Expand Up @@ -124,7 +123,6 @@ func s3BucketExists(ctx context.Context, minioClient *minio.Client,
// parameter into given bucket under selected object name
func storeTableNames(ctx context.Context, minioClient *minio.Client,
bucketName string, objectName string, tableNames []TableName) error {

// check if Minio client has been passed to this function
if minioClient == nil {
err := errors.New(minioClientIsNil)
Expand Down Expand Up @@ -183,7 +181,6 @@ func storeTableNames(ctx context.Context, minioClient *minio.Client,
// into given bucket under selected object name
func storeDisabledRulesIntoS3(ctx context.Context, minioClient *minio.Client,
bucketName string, objectName string, disabledRulesInfo []DisabledRuleInfo) error {

// check if Minio client has been passed to this function
if minioClient == nil {
err := errors.New(minioClientIsNil)
Expand Down
7 changes: 1 addition & 6 deletions s3_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2022 Red Hat, Inc.
Copyright © 2022, 2023 Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -118,7 +118,6 @@ func TestNewS3Connection(t *testing.T) {
assert.NotNil(t, client)
}
})

}
}

Expand Down Expand Up @@ -173,9 +172,7 @@ func TestS3BucketExists(t *testing.T) {
assert.NoError(t, err)
}
})

}

}

// Test case specification structure for function main.storeTableNames
Expand Down Expand Up @@ -256,7 +253,5 @@ func TestStoreTable(t *testing.T) {
assert.NoError(t, err)
}
})

}

}
14 changes: 7 additions & 7 deletions storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
main "github.com/RedHatInsights/insights-results-aggregator-exporter"
)

const NO_LIMITS = -1
const NoLimits = -1

var testConfig = main.StorageConfiguration{
Driver: "postgres",
Expand Down Expand Up @@ -476,7 +476,7 @@ func TestReadTable(t *testing.T) {
storage := main.NewFromConnection(connection, 1, &testConfig)

// call the tested method
values, err := storage.ReadTable("table_name", NO_LIMITS)
values, err := storage.ReadTable("table_name", NoLimits)
if err != nil {
t.Errorf("error was not expected %s", err)
}
Expand Down Expand Up @@ -574,7 +574,7 @@ func TestReadTableWithSelectiveExportDisallowedTable(t *testing.T) {
storage := main.NewFromConnection(connection, 1, config)

// call the tested method, table name must be in predefined list
values, err := storage.ReadTable("table_name", NO_LIMITS)
values, err := storage.ReadTable("table_name", NoLimits)
if err != nil {
t.Errorf("error was not expected %s", err)
}
Expand Down Expand Up @@ -624,7 +624,7 @@ func TestReadTableWithSelectiveExportAllowedTableSingleOrgID(t *testing.T) {
storage := main.NewFromConnection(connection, 1, config)

// call the tested method, table name must be in predefined list
values, err := storage.ReadTable("report", NO_LIMITS)
values, err := storage.ReadTable("report", NoLimits)
if err != nil {
t.Errorf("error was not expected %s", err)
}
Expand Down Expand Up @@ -674,7 +674,7 @@ func TestReadTableWithSelectiveExportAllowedTable(t *testing.T) {
storage := main.NewFromConnection(connection, 1, config)

// call the tested method, table name must be in predefined list
values, err := storage.ReadTable("report", NO_LIMITS)
values, err := storage.ReadTable("report", NoLimits)
if err != nil {
t.Errorf("error was not expected %s", err)
}
Expand Down Expand Up @@ -761,7 +761,7 @@ func TestReadTableOnError(t *testing.T) {
storage := main.NewFromConnection(connection, 1, &testConfig)

// call the tested method
_, err := storage.ReadTable("table_name", NO_LIMITS)
_, err := storage.ReadTable("table_name", NoLimits)
if err != mockedError {
t.Errorf("different error was returned: %v", err)
}
Expand Down Expand Up @@ -877,7 +877,7 @@ func TestStoreTableIntoFile(t *testing.T) {
storage := main.NewFromConnection(connection, 1, &testConfig)

// call the tested method
err := storage.StoreTableIntoFile("table_name", NO_LIMITS)
err := storage.StoreTableIntoFile("table_name", NoLimits)
if err != nil {
t.Errorf("error was not expected %s", err)
}
Expand Down