make creation of tracks and messages more generic
This commit is contained in:
parent
27771b3ebe
commit
d6dce700a4
3 changed files with 19 additions and 3 deletions
|
@ -17,6 +17,10 @@ func MakeMessage(t *tracking.TrackTemplate) tracking.Track {
|
||||||
return &message{tracking.MakeTrack(t)}
|
return &message{tracking.MakeTrack(t)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (msg *message) Domain() string {
|
||||||
|
return msg.Head()["domain"]
|
||||||
|
}
|
||||||
|
|
||||||
func Messages(db *sql.Storage) *tracking.Container {
|
func Messages(db *sql.Storage) *tracking.Container {
|
||||||
return &tracking.Container{
|
return &tracking.Container{
|
||||||
ItemFactory: MakeMessage,
|
ItemFactory: MakeMessage,
|
||||||
|
@ -30,6 +34,11 @@ func Messages(db *sql.Storage) *tracking.Container {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func New(cont *tracking.Container, headValues lib.StrSlice, data lib.Map) *message {
|
||||||
|
tr := cont.NewTrack(headValues, data)
|
||||||
|
return tr.(*message)
|
||||||
|
}
|
||||||
|
|
||||||
// message store action handler
|
// message store action handler
|
||||||
|
|
||||||
func Store(act lib.Action) bool {
|
func Store(act lib.Action) bool {
|
||||||
|
|
|
@ -101,7 +101,12 @@ func Tracks(db *sql.Storage) *Container {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cont *Container) New(headValues lib.StrSlice, data lib.Map) Track {
|
func New(cont *Container, headValues lib.StrSlice, data lib.Map) *track {
|
||||||
|
tr := cont.NewTrack(headValues, data)
|
||||||
|
return tr.(*track)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cont *Container) NewTrack(headValues lib.StrSlice, data lib.Map) Track {
|
||||||
head := lib.StrMap{}
|
head := lib.StrMap{}
|
||||||
for i, k := range cont.HeadFields {
|
for i, k := range cont.HeadFields {
|
||||||
if i >= len(headValues) {
|
if i >= len(headValues) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ func BaseTest(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
|
||||||
func TrackingTest(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
|
func TrackingTest(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
|
||||||
cont := tracking.Tracks(db)
|
cont := tracking.Tracks(db)
|
||||||
cont.CreateTable()
|
cont.CreateTable()
|
||||||
track := cont.New(lib.StrSlice{"t01", "john"}, lib.Map{})
|
track := tracking.New(cont, lib.StrSlice{"t01", "john"}, lib.Map{})
|
||||||
t.AssertEqual(track.TrackId(), lib.Ident(1))
|
t.AssertEqual(track.TrackId(), lib.Ident(1))
|
||||||
t.AssertEqual(track.TimeStamp().Year(), time.Now().Year())
|
t.AssertEqual(track.TimeStamp().Year(), time.Now().Year())
|
||||||
//fmt.Printf("%+v\n", track.TimeStamp())
|
//fmt.Printf("%+v\n", track.TimeStamp())
|
||||||
|
@ -79,8 +79,10 @@ func MessageTest(t *testing.T, cfg *sql.Cfg, db *sql.Storage) {
|
||||||
//msgstore.StoreDB(db, msg)
|
//msgstore.StoreDB(db, msg)
|
||||||
cont := message.Messages(db)
|
cont := message.Messages(db)
|
||||||
cont.CreateTable()
|
cont.CreateTable()
|
||||||
msg := cont.New(lib.StrSlice{"", "data"}, lib.Map{})
|
//msg := cont.New(lib.StrSlice{"", "data"}, lib.Map{}).(*message.Message)
|
||||||
|
msg := message.New(cont, lib.StrSlice{"", "data"}, lib.Map{})
|
||||||
t.AssertEqual(msg.TrackId(), lib.Ident(1))
|
t.AssertEqual(msg.TrackId(), lib.Ident(1))
|
||||||
|
t.AssertEqual(msg.Domain(), "scopes")
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetSqlite(db *sql.Storage) {
|
func resetSqlite(db *sql.Storage) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue