package fiinha import ( "runtime" "uuid" g "gobang" ) const topic = "topic" func MainTest() { _, file, _, ok := runtime.Caller(0) g.TAssertEqualS(ok, true, "can't get filename") databasePath := file + ".db" queue, err := New(databasePath) g.TErrorIf(err) defer queue.Close() pub := func(flowID uuid.UUID, payload []byte) { unsent := UnsentMessage{ Topic: topic, FlowID: flowID, Payload: payload, } _, err := queue.Publish(unsent) g.TErrorIf(err) } g.Testing("we can WaitFor() a message before its publishing", func() { flowID := uuid.New() waiter := queue.WaitFor(topic, flowID, "waiter").Channel pub(flowID, []byte("payload before")) given := <- waiter g.TAssertEqual(given, []byte("payload before")) }) g.Testing("we can also do it after its publishing", func() { flowID := uuid.New() pub(flowID, []byte("payload after")) given := <- queue.WaitFor(topic, flowID, "waiter").Channel g.TAssertEqual(given, []byte("payload after")) }) }