Skip to content

Commit

Permalink
fix: bad slice allocation
Browse files Browse the repository at this point in the history
Also add test for futur non-regression
fixes #8
  • Loading branch information
guilhem committed Jul 10, 2022
1 parent b4130e9 commit ab3029b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/semver/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func (b *Bump) IncPatch() {
}

func Latest(tags []string) (string, error) {
vs := make(semver.Collection, len(tags))
vs := make(semver.Collection, 0, len(tags))

for i, r := range tags {
for _, r := range tags {
v, err := semver.NewVersion(r)
if err != nil {
continue
}

vs[i] = v
vs = append(vs, v)
}

latest := vs[0]
Expand Down
49 changes: 49 additions & 0 deletions pkg/semver/semver_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package semver

import "testing"

func TestLatest(t *testing.T) {
type args struct {
tags []string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "one tag",
args: args{
tags: []string{
"v1.0.0",
},
},
want: "v1.0.0",
wantErr: false,
},
{
name: "two tags",
args: args{
tags: []string{
"v1.0.0",
"v2.0.0-rc.1",
},
},
want: "v2.0.0-rc.1",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Latest(tt.args.tags)
if (err != nil) != tt.wantErr {
t.Errorf("Latest() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("Latest() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit ab3029b

Please sign in to comment.