github.com/lingyao2333/mo-zero@v1.4.1/core/trace/agent_test.go (about)

     1  package trace
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lingyao2333/mo-zero/core/logx"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestStartAgent(t *testing.T) {
    11  	logx.Disable()
    12  
    13  	const (
    14  		endpoint1 = "localhost:1234"
    15  		endpoint2 = "remotehost:1234"
    16  		endpoint3 = "localhost:1235"
    17  	)
    18  	c1 := Config{
    19  		Name: "foo",
    20  	}
    21  	c2 := Config{
    22  		Name:     "bar",
    23  		Endpoint: endpoint1,
    24  		Batcher:  kindJaeger,
    25  	}
    26  	c3 := Config{
    27  		Name:     "any",
    28  		Endpoint: endpoint2,
    29  		Batcher:  kindZipkin,
    30  	}
    31  	c4 := Config{
    32  		Name:     "bla",
    33  		Endpoint: endpoint3,
    34  		Batcher:  "otlp",
    35  	}
    36  	c5 := Config{
    37  		Name:     "grpc",
    38  		Endpoint: endpoint3,
    39  		Batcher:  "grpc",
    40  	}
    41  
    42  	StartAgent(c1)
    43  	StartAgent(c1)
    44  	StartAgent(c2)
    45  	StartAgent(c3)
    46  	StartAgent(c4)
    47  	StartAgent(c5)
    48  
    49  	lock.Lock()
    50  	defer lock.Unlock()
    51  
    52  	// because remotehost cannot be resolved
    53  	assert.Equal(t, 3, len(agents))
    54  	_, ok := agents[""]
    55  	assert.True(t, ok)
    56  	_, ok = agents[endpoint1]
    57  	assert.True(t, ok)
    58  	_, ok = agents[endpoint2]
    59  	assert.False(t, ok)
    60  }