git-bug/bug/op_create_test.go

48 lines
805 B
Go
Raw Normal View History

package bug
2018-07-12 22:31:41 +03:00
import (
"testing"
"time"
"github.com/go-test/deep"
2018-07-12 22:31:41 +03:00
)
func TestCreate(t *testing.T) {
snapshot := Snapshot{}
2018-07-12 22:31:41 +03:00
var rene = Person{
2018-07-12 22:31:41 +03:00
Name: "René Descartes",
Email: "rene@descartes.fr",
}
unix := time.Now().Unix()
create := NewCreateOp(rene, unix, "title", "message", nil)
2018-07-12 22:31:41 +03:00
create.Apply(&snapshot)
2018-07-12 22:31:41 +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)}
expected := Snapshot{
2018-07-12 22:31:41 +03:00
Title: "title",
Comments: []Comment{
comment,
2018-07-12 22:31:41 +03:00
},
2018-08-01 03:15:40 +03:00
Author: rene,
CreatedAt: create.Time(),
Timeline: []TimelineItem{
NewCreateTimelineItem(hash, comment),
},
2018-07-12 22:31:41 +03:00
}
deep.CompareUnexportedFields = true
if diff := deep.Equal(snapshot, expected); diff != nil {
t.Fatal(diff)
2018-07-12 22:31:41 +03:00
}
}