Feature: non-blocking tracer, changed license (#57)

* refactor tracer, introduce worker to avoid un-blocker trace strategy

* fixed unit test and refactor dockerFile

* buffered events chan

* refactor yaml API core, initial web hook tracing implementations

* added banner

* changed license from GPL 3 to MIT

* Edit readme
This commit is contained in:
Mario Candela
2023-08-30 23:04:35 +02:00
committed by GitHub
parent 345e9ef9fd
commit 0794736bc5
12 changed files with 126 additions and 642 deletions

View File

@ -1,8 +1,10 @@
package tracer
import (
"github.com/stretchr/testify/assert"
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestInit(t *testing.T) {
@ -15,23 +17,56 @@ func TestInit(t *testing.T) {
func TestTraceEvent(t *testing.T) {
eventCalled := Event{}
var wg sync.WaitGroup
mockStrategy := func(event Event) {
defer wg.Done()
eventCalled = event
}
tracer := Init(mockStrategy)
wg.Add(1)
tracer.TraceEvent(Event{
ID: "mockID",
Protocol: HTTP.String(),
Status: Stateless.String(),
})
wg.Wait()
assert.NotNil(t, eventCalled.ID)
assert.Equal(t, eventCalled.ID, "mockID")
assert.Equal(t, eventCalled.Protocol, HTTP.String())
assert.Equal(t, eventCalled.Status, Stateless.String())
assert.Equal(t, "mockID", eventCalled.ID)
assert.Equal(t, HTTP.String(), eventCalled.Protocol)
assert.Equal(t, Stateless.String(), eventCalled.Status)
}
func TestSetStrategy(t *testing.T) {
eventCalled := Event{}
var wg sync.WaitGroup
mockStrategy := func(event Event) {
defer wg.Done()
eventCalled = event
}
tracer := Init(mockStrategy)
tracer.setStrategy(mockStrategy)
wg.Add(1)
tracer.TraceEvent(Event{
ID: "mockID",
Protocol: HTTP.String(),
Status: Stateless.String(),
})
wg.Wait()
assert.NotNil(t, eventCalled.ID)
assert.Equal(t, "mockID", eventCalled.ID)
assert.Equal(t, HTTP.String(), eventCalled.Protocol)
assert.Equal(t, Stateless.String(), eventCalled.Status)
}
func TestStringStatus(t *testing.T) {