Skip to content

Commit

Permalink
chore(lint): lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
nesangcode committed Apr 20, 2024
1 parent fe44b2f commit 5dacd5a
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 41 deletions.
3 changes: 1 addition & 2 deletions cmd/proxy/actions/app_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestProxyRoutes(t *testing.T) {
tmp, err := template.New("home").Parse(homepage)
assert.NoError(t, err)

var templateData = make(map[string]string)
templateData := make(map[string]string)

templateData["Host"] = req.Host

Expand Down Expand Up @@ -109,5 +109,4 @@ func TestProxyRoutes(t *testing.T) {
tc.test(t, req, w.Result())
})
}

}
1 change: 0 additions & 1 deletion cmd/proxy/actions/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func TestIndexHandler(t *testing.T) {
if w.Code != tc.code {
t.Fatalf("expected response code to be %d but got %d", tc.code, w.Code)
}

})
}
}
Expand Down
6 changes: 3 additions & 3 deletions e2etests/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func (m *E2eSuite) SetupSuite() {

func (m *E2eSuite) TearDownSuite() {
m.stopAthens()
chmodR(m.goPath, 0777)
chmodR(m.goPath, 0o777)
os.RemoveAll(m.goPath)
chmodR(m.sampleRepoPath, 0777)
chmodR(m.sampleRepoPath, 0o777)
os.RemoveAll(m.sampleRepoPath)
}

Expand All @@ -73,7 +73,7 @@ func TestE2E(t *testing.T) {
}

func (m *E2eSuite) SetupTest() {
chmodR(m.goPath, 0777)
chmodR(m.goPath, 0o777)
err := cleanGoCache(m.getEnv())
if err != nil {
m.Fail("Failed to clear go cache", err)
Expand Down
7 changes: 3 additions & 4 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func testConfigFile(t *testing.T) (testConfigFile string) {
testConfigFile = filepath.Join("..", "..", "config.dev.toml")
if err := os.Chmod(testConfigFile, 0700); err != nil {
if err := os.Chmod(testConfigFile, 0o700); err != nil {
t.Fatalf("%s\n", err)
}
return testConfigFile
Expand Down Expand Up @@ -305,7 +305,6 @@ func TestParseExampleConfig(t *testing.T) {
}

func getEnvMap(config *Config) map[string]string {

envVars := map[string]string{
"GO_ENV": config.GoEnv,
"GO_BINARY_PATH": config.GoBinary,
Expand Down Expand Up @@ -414,7 +413,7 @@ func Test_checkFilePerms(t *testing.T) {
}

incorrectPerms := []os.FileMode{0o777, 0o610, 0o660}
var incorrectFiles = make([]string, len(incorrectPerms))
incorrectFiles := make([]string, len(incorrectPerms))

for i := range incorrectPerms {
f, err := tempFile(incorrectPerms[i])
Expand All @@ -426,7 +425,7 @@ func Test_checkFilePerms(t *testing.T) {
}

correctPerms := []os.FileMode{0o600, 0o400, 0o644}
var correctFiles = make([]string, len(correctPerms))
correctFiles := make([]string, len(correctPerms))

for i := range correctPerms {
f, err := tempFile(correctPerms[i])
Expand Down
6 changes: 4 additions & 2 deletions pkg/download/list_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"github.com/stretchr/testify/require"
)

const testOp athenserr.Op = "vcsLister.List"
const testModName = "happy tags"
const (
testOp athenserr.Op = "vcsLister.List"
testModName = "happy tags"
)

type listMergeTest struct {
name string
Expand Down
3 changes: 2 additions & 1 deletion pkg/download/mode/mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ var testCases = []struct {
{
Pattern: "github.com/gomods/*",
Mode: AsyncRedirect,
DownloadURL: "gomods.io"},
DownloadURL: "gomods.io",
},
},
},
input: "github.com/gomods/athens",
Expand Down
6 changes: 2 additions & 4 deletions pkg/download/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import (
"golang.org/x/sync/errgroup"
)

var (
testConfigPath = filepath.Join("..", "..", "config.dev.toml")
)
var testConfigPath = filepath.Join("..", "..", "config.dev.toml")

func getDP(t *testing.T) Protocol {
t.Helper()
Expand Down Expand Up @@ -235,7 +233,7 @@ var latestTests = []latestTest{
path: "github.com/athens-artifacts/happy-path",
info: &storage.RevInfo{
Version: "v0.0.3",
Time: time.Date(2018, 8, 3, 17, 16, 00, 0, time.UTC),
Time: time.Date(2018, 8, 3, 17, 16, 0o0, 0, time.UTC),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/middleware/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (

func testConfigFile(t *testing.T) (testConfigFile string) {
testConfigFile = filepath.Join("..", "..", "config.dev.toml")
if err := os.Chmod(testConfigFile, 0700); err != nil {
if err := os.Chmod(testConfigFile, 0o700); err != nil {
t.Fatalf("%s\n", err)
}
return testConfigFile
Expand Down
10 changes: 4 additions & 6 deletions pkg/module/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func testConfigFile(t *testing.T) (testConfigFile string) {
testConfigFile = filepath.Join("..", "..", "config.dev.toml")
if err := os.Chmod(testConfigFile, 0700); err != nil {
if err := os.Chmod(testConfigFile, 0o700); err != nil {
t.Fatalf("%s\n", err)
}
return testConfigFile
Expand Down Expand Up @@ -40,7 +40,6 @@ func (t *FilterTests) Test_NewFilter() {
mf, err = NewFilter(filter)
r.Equal(filter, mf.filePath)
r.NoError(err)

}

func (t *FilterTests) Test_IgnoreSimple() {
Expand Down Expand Up @@ -198,7 +197,6 @@ func (t *FilterTests) Test_versionFilterRobust() {

r.Equal(Exclude, f.Rule("github.com/a/b", "a"))
r.Equal(Exclude, f.Rule("github.com/c/d", "fg"))

}

func (t *FilterTests) Test_initFromConfig() {
Expand All @@ -207,20 +205,20 @@ func (t *FilterTests) Test_initFromConfig() {
defer os.Remove(filterFile)

goodInput := []byte("+ github.com/a/b\n\n# some comment\n- github.com/c/d\n\nD github.com/x")
os.WriteFile(filterFile, goodInput, 0644)
os.WriteFile(filterFile, goodInput, 0o644)

f, err := initFromConfig(filterFile)
r.NotNil(f)
r.NoError(err)

badInput := []byte("+ github.com/a/b\n\n# some comment\n\n- github.com/c/d\n\nD github.com/x\nsome_random_line")
os.WriteFile(filterFile, badInput, 0644)
os.WriteFile(filterFile, badInput, 0o644)
f, err = initFromConfig(filterFile)
r.Nil(f)
r.Error(err)

versionInput := []byte("+ github.com/a/b\n\n# some comment\n\n- github.com/c/d v1,v2.3.4,v3.2.*\n\nD github.com/x\n")
os.WriteFile(filterFile, versionInput, 0644)
os.WriteFile(filterFile, versionInput, 0o644)
f, err = initFromConfig(filterFile)
r.NotNil(f)
r.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewStorage(conf *config.MinioConfig, timeout time.Duration) (storage.Backen
return &storageImpl{minioClient, minioCore, bucketName}, nil
}

// TrimHTTP trims "http://" or "https://" prefix from input string
// TrimHTTP trims "http://" or "https://" prefix from input string.
func TrimHTTP(s string) string {
s = strings.TrimPrefix(s, "http://")
s = strings.TrimPrefix(s, "https://")
Expand Down
8 changes: 5 additions & 3 deletions pkg/storage/mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package mongo
import (
"bytes"
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"io"
"os"
"testing"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"

"github.com/gomods/athens/pkg/config"
"github.com/gomods/athens/pkg/errors"
"github.com/gomods/athens/pkg/storage"
Expand Down Expand Up @@ -145,6 +146,7 @@ func TestQueryKindUnexpectedErrorCases(t *testing.T) {
require.Equal(t, errors.KindUnexpected, errors.Kind(err))
}
}

func TestNewStorageWithDefaultOverrides(t *testing.T) {
url := os.Getenv("ATHENS_MONGO_STORAGE_URL")

Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/s3/cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package s3
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"strings"

"github.com/aws/aws-sdk-go-v2/service/s3/types"

Check failure on line 8 in pkg/storage/s3/cataloger.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard,default (gci)

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/gomods/athens/pkg/config"
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/s3/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package s3

import (
"context"
"github.com/aws/smithy-go"
"sync"

"github.com/aws/smithy-go"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/gomods/athens/pkg/config"
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/s3/deleter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package s3

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/gomods/athens/pkg/errors"
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/s3/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package s3
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"io"

"github.com/aws/aws-sdk-go-v2/service/s3/types"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/gomods/athens/pkg/config"
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/s3/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package s3

import (
"context"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"strings"

"github.com/aws/aws-sdk-go-v2/service/s3/types"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/gomods/athens/pkg/errors"
Expand Down
10 changes: 5 additions & 5 deletions pkg/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package s3
import (
"context"
"fmt"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
awscfg "github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
Expand All @@ -11,7 +13,6 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/gomods/athens/pkg/config"
"github.com/gomods/athens/pkg/errors"
"time"
)

// Storage implements (./pkg/storage).Backend and
Expand All @@ -36,7 +37,6 @@ func New(s3Conf *config.S3Config, timeout time.Duration, options ...func(*aws.Co
const op errors.Op = "s3.New"

awsConfig, err := awscfg.LoadDefaultConfig(context.TODO(), awscfg.WithRegion(s3Conf.Region))

if err != nil {
return nil, errors.E(op, err)
}
Expand All @@ -50,13 +50,13 @@ func New(s3Conf *config.S3Config, timeout time.Duration, options ...func(*aws.Co
}

if !s3Conf.UseDefaultConfiguration {
//credProviders := defaults.CredProviders(awsConfig, defaults.Handlers())
// credProviders := defaults.CredProviders(awsConfig, defaults.Handlers())
endpointCreds := []aws.CredentialsProvider{
endpointcreds.New(endpointFrom(s3Conf.CredentialsEndpoint, s3Conf.AwsContainerCredentialsRelativeURI)),
credentials.NewStaticCredentialsProvider(s3Conf.Key, s3Conf.Secret, s3Conf.Token),
}

//credProviders = append(endpointCreds, credProviders...)
// credProviders = append(endpointCreds, credProviders...)
awsConfig.Credentials = newChainCredentials(endpointCreds...)
}

Expand All @@ -82,7 +82,7 @@ func endpointFrom(credentialsEndpoint, relativeURI string) string {
return credentialsEndpoint + relativeURI
}

// Based on old credentials.NewChainCredentials in v1
// newChainCredentials is based on old credentials.NewChainCredentials in v1.
func newChainCredentials(providers ...aws.CredentialsProvider) aws.CredentialsProvider {
return aws.NewCredentialsCache(
aws.CredentialsProviderFunc(func(ctx context.Context) (aws.Credentials, error) {
Expand Down
7 changes: 4 additions & 3 deletions pkg/storage/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package s3

import (
"context"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/aws/smithy-go"
"github.com/gomods/athens/pkg/errors"
"os"
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/aws/smithy-go"
"github.com/gomods/athens/pkg/errors"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/gomods/athens/pkg/config"
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/s3/saver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package s3
import (
"bytes"
"context"
"github.com/aws/aws-sdk-go-v2/service/s3"
"io"

"github.com/aws/aws-sdk-go-v2/service/s3"

Check failure on line 8 in pkg/storage/s3/saver.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard,default (gci)

"github.com/aws/aws-sdk-go-v2/aws"

Check failure on line 10 in pkg/storage/s3/saver.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard,default (gci)
"github.com/gomods/athens/pkg/errors"
"github.com/gomods/athens/pkg/observ"
Expand Down

0 comments on commit 5dacd5a

Please sign in to comment.