0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-25 07:30:38 +00:00
git-sv/app/app_test.go

53 lines
921 B
Go
Raw Normal View History

package app
2020-05-01 03:45:08 +00:00
import (
"reflect"
"testing"
"time"
)
func Test_parseTagsOutput(t *testing.T) {
tests := []struct {
name string
input string
want []Tag
2020-05-01 03:45:08 +00:00
wantErr bool
}{
2023-10-12 14:18:25 +00:00
{
"with date",
"2020-05-01 18:00:00 -0300#1.0.0",
[]Tag{{Name: "1.0.0", Date: date("2020-05-01 18:00:00 -0300")}},
2023-10-12 14:18:25 +00:00
false,
},
{
"without date",
"#1.0.0",
[]Tag{{Name: "1.0.0", Date: time.Time{}}},
2023-10-12 14:18:25 +00:00
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)
2023-10-12 14:18:25 +00:00
2020-05-01 03:45:08 +00:00
return
}
2023-10-12 14:18:25 +00:00
2020-05-01 03:45:08 +00:00
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)
}
2023-10-12 14:18:25 +00:00
2020-05-01 03:45:08 +00:00
return t
}