2023-10-15 19:29:29 +00:00
|
|
|
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
|
2023-10-15 19:29:29 +00:00
|
|
|
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",
|
2023-10-15 19:29:29 +00:00
|
|
|
[]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",
|
2023-10-15 19:29:29 +00:00
|
|
|
[]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
|
|
|
|
}
|