2018-09-28 21:39:39 +03:00
|
|
|
package bug
|
2018-07-12 22:31:41 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-09-25 18:56:58 +03:00
|
|
|
"time"
|
2018-09-29 21:41:19 +03:00
|
|
|
|
|
|
|
"github.com/go-test/deep"
|
2018-07-12 22:31:41 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreate(t *testing.T) {
|
2018-09-28 21:39:39 +03:00
|
|
|
snapshot := Snapshot{}
|
2018-07-12 22:31:41 +03:00
|
|
|
|
2018-09-28 21:39:39 +03:00
|
|
|
var rene = Person{
|
2018-07-12 22:31:41 +03:00
|
|
|
Name: "René Descartes",
|
|
|
|
Email: "rene@descartes.fr",
|
|
|
|
}
|
|
|
|
|
2018-09-25 18:56:58 +03:00
|
|
|
unix := time.Now().Unix()
|
|
|
|
|
|
|
|
create := NewCreateOp(rene, unix, "title", "message", nil)
|
2018-07-12 22:31:41 +03:00
|
|
|
|
2018-09-29 12:28:18 +03:00
|
|
|
create.Apply(&snapshot)
|
2018-07-12 22:31:41 +03:00
|
|
|
|
2018-09-29 21:41:19 +03:00
|
|
|
hash, err := create.Hash()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-09-30 12:00:39 +03:00
|
|
|
comment := Comment{Author: rene, Message: "message", UnixTime: Timestamp(create.UnixTime)}
|
2018-09-29 21:41:19 +03:00
|
|
|
|
2018-09-28 21:39:39 +03:00
|
|
|
expected := Snapshot{
|
2018-07-12 22:31:41 +03:00
|
|
|
Title: "title",
|
2018-09-28 21:39:39 +03:00
|
|
|
Comments: []Comment{
|
2018-09-29 21:41:19 +03:00
|
|
|
comment,
|
2018-07-12 22:31:41 +03:00
|
|
|
},
|
2018-08-01 03:15:40 +03:00
|
|
|
Author: rene,
|
|
|
|
CreatedAt: create.Time(),
|
2018-09-29 21:41:19 +03:00
|
|
|
Timeline: []TimelineItem{
|
|
|
|
NewCreateTimelineItem(hash, comment),
|
|
|
|
},
|
2018-07-12 22:31:41 +03:00
|
|
|
}
|
|
|
|
|
2018-09-29 21:41:19 +03:00
|
|
|
deep.CompareUnexportedFields = true
|
|
|
|
if diff := deep.Equal(snapshot, expected); diff != nil {
|
|
|
|
t.Fatal(diff)
|
2018-07-12 22:31:41 +03:00
|
|
|
}
|
|
|
|
}
|