Skip to content

Commit

Permalink
refactor: Removing bad allocation of arrays
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Oct 19, 2021
1 parent 3fc32b6 commit 7f17a98
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions pkg/notifier/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,31 @@ func TestGetNewRepositoryReleases(t *testing.T) {
args{
repo: model.NewGithubRepository(0, ""),
},
make([]model.Release, 0),
nil,
},
{
"no new",
App{},
args{
repo: model.NewGithubRepository(1, repositoryName).AddVersion(model.DefaultPattern, repositoryVersion),
},
make([]model.Release, 0),
nil,
},
{
"invalid version",
App{},
args{
repo: model.NewGithubRepository(1, repositoryName).AddVersion(model.DefaultPattern, "abcde"),
},
make([]model.Release, 0),
nil,
},
{
"not greater",
App{},
args{
repo: model.NewGithubRepository(1, repositoryName).AddVersion(model.DefaultPattern, "1.1.0"),
},
make([]model.Release, 0),
nil,
},
{
"greater",
Expand Down
4 changes: 2 additions & 2 deletions pkg/notifier/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (a App) getNewRepositoryReleases(repo model.Repository) []model.Release {
return nil
}

releases := make([]model.Release, 0)
var releases []model.Release

for pattern, version := range versions {
releases = appendVersion(releases, version, repo, pattern, repo.Versions[pattern])
Expand Down Expand Up @@ -147,7 +147,7 @@ func (a App) getFetchHelmSources(repos map[string]model.Repository) []model.Rele
return nil
}

releases := make([]model.Release, 0)
var releases []model.Release

for chartName, patterns := range values {
repo := repos[chartName]
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/ketchup/ketchup.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (a App) Delete(ctx context.Context, item model.Ketchup) (err error) {
}

func (a App) check(ctx context.Context, old, new model.Ketchup) error {
output := make([]error, 0)
var output []error

if model.ReadUser(ctx).IsZero() {
output = append(output, errors.New("you must be logged in for interacting"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (a App) check(ctx context.Context, old, new model.Repository) error {
return nil
}

output := make([]error, 0)
var output []error

if len(strings.TrimSpace(new.Name)) == 0 {
output = append(output, errors.New("name is required"))
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (a App) check(ctx context.Context, _, new model.User) error {
return nil
}

output := make([]error, 0)
var output []error

if len(strings.TrimSpace(new.Email)) == 0 {
output = append(output, errors.New("email is required"))
Expand Down
6 changes: 3 additions & 3 deletions pkg/store/ketchup/ketchup.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (a App) List(ctx context.Context, pageSize uint, last string) ([]model.Ketc
user := model.ReadUser(ctx)

var totalCount uint64
list := make([]model.Ketchup, 0)
var list []model.Ketchup

scanner := func(rows pgx.Rows) error {
item := model.NewKetchup("", "", model.Daily, false, model.NewRepository(0, 0, "", ""))
Expand Down Expand Up @@ -148,7 +148,7 @@ WHERE

// ListByRepositoriesID lists ketchup by repositories id
func (a App) ListByRepositoriesID(ctx context.Context, ids []uint64, frequency model.KetchupFrequency) ([]model.Ketchup, error) {
list := make([]model.Ketchup, 0)
var list []model.Ketchup

scanner := func(rows pgx.Rows) error {
var item model.Ketchup
Expand Down Expand Up @@ -199,7 +199,7 @@ WHERE

// ListOutdatedByFrequency lists outdated ketchup by frequency id
func (a App) ListOutdatedByFrequency(ctx context.Context, frequency model.KetchupFrequency) ([]model.Ketchup, error) {
list := make([]model.Ketchup, 0)
var list []model.Ketchup

scanner := func(rows pgx.Rows) error {
var item model.Ketchup
Expand Down
6 changes: 3 additions & 3 deletions pkg/store/ketchup/ketchup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestList(t *testing.T) {
args{
pageSize: 20,
},
[]model.Ketchup{},
nil,
0,
errors.New("failed"),
},
Expand All @@ -76,7 +76,7 @@ func TestList(t *testing.T) {
args{
pageSize: 20,
},
[]model.Ketchup{},
nil,
1,
errors.New("invalid value `wrong` for repository kind"),
},
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestListByRepositoriesID(t *testing.T) {
ids: []uint64{1, 2},
frequency: model.Daily,
},
make([]model.Ketchup, 0),
nil,
errors.New("failed"),
},
}
Expand Down

0 comments on commit 7f17a98

Please sign in to comment.