0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-24 21:20:40 +00:00
git-sv/sv/git_test.go

40 lines
892 B
Go
Raw Normal View History

2020-05-01 03:45:08 +00:00
package sv
import (
"reflect"
"testing"
"time"
)
func Test_parseTagsOutput(t *testing.T) {
tests := []struct {
name string
input string
want []GitTag
wantErr bool
}{
{"with date", "2020-05-01 18:00:00 -0300#1.0.0", []GitTag{{Name: "1.0.0", Date: date("2020-05-01 18:00:00 -0300")}}, false},
{"without date", "#1.0.0", []GitTag{{Name: "1.0.0", Date: time.Time{}}}, false},
2020-05-01 03:45:08 +00:00
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseTagsOutput(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("parseTagsOutput() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseTagsOutput() = %v, want %v", got, tt.want)
}
})
}
}
func date(input string) time.Time {
t, err := time.Parse("2006-01-02 15:04:05 -0700", input)
if err != nil {
panic(err)
}
return t
}