github.com/pinpoint-apm/pinpoint-go-agent@v1.4.1-0.20240110120318-a50c2eb18c8c/grpc_test.go (about)

     1  package pinpoint
     2  
     3  import (
     4  	"github.com/stretchr/testify/assert"
     5  	"testing"
     6  )
     7  
     8  func Test_agentGrpc_sendAgentInfo(t *testing.T) {
     9  	type args struct {
    10  		agent *agent
    11  	}
    12  	opts := []ConfigOption{
    13  		WithAppName("TestApp"),
    14  	}
    15  	cfg, _ := NewConfig(opts...)
    16  
    17  	tests := []struct {
    18  		name string
    19  		args args
    20  	}{
    21  		{"1", args{newTestAgent(cfg)}},
    22  	}
    23  	for _, tt := range tests {
    24  		t.Run(tt.name, func(t *testing.T) {
    25  			agent := tt.args.agent
    26  			agent.agentGrpc = newMockAgentGrpc(agent, t)
    27  			b := agent.agentGrpc.registerAgentWithRetry()
    28  			assert.Equal(t, true, b, "sendAgentInfo")
    29  		})
    30  	}
    31  }
    32  
    33  func Test_agentGrpc_sendApiMetadata(t *testing.T) {
    34  	type args struct {
    35  		agent *agent
    36  	}
    37  	opts := []ConfigOption{
    38  		WithAppName("TestApp"),
    39  	}
    40  	cfg, _ := NewConfig(opts...)
    41  
    42  	tests := []struct {
    43  		name string
    44  		args args
    45  	}{
    46  		{"1", args{newTestAgent(cfg)}},
    47  	}
    48  	for _, tt := range tests {
    49  		t.Run(tt.name, func(t *testing.T) {
    50  			agent := tt.args.agent
    51  			agent.agentGrpc = newMockAgentGrpc(agent, t)
    52  			b := agent.agentGrpc.sendApiMetadataWithRetry(asyncApiId, "Asynchronous Invocation", -1, apiTypeInvocation)
    53  			assert.Equal(t, true, b, "sendApiMetadata")
    54  		})
    55  	}
    56  }
    57  
    58  func Test_agentGrpc_sendSqlMetadata(t *testing.T) {
    59  	type args struct {
    60  		agent *agent
    61  	}
    62  	opts := []ConfigOption{
    63  		WithAppName("TestApp"),
    64  	}
    65  	cfg, _ := NewConfig(opts...)
    66  
    67  	tests := []struct {
    68  		name string
    69  		args args
    70  	}{
    71  		{"1", args{newTestAgent(cfg)}},
    72  	}
    73  	for _, tt := range tests {
    74  		t.Run(tt.name, func(t *testing.T) {
    75  			agent := tt.args.agent
    76  			agent.agentGrpc = newMockAgentGrpc(agent, t)
    77  			b := agent.agentGrpc.sendSqlMetadataWithRetry(1, "SELECT 1")
    78  			assert.Equal(t, true, b, "sendSqlMetadata")
    79  		})
    80  	}
    81  }
    82  
    83  func Test_agentGrpc_sendStringMetadata(t *testing.T) {
    84  	type args struct {
    85  		agent *agent
    86  	}
    87  	opts := []ConfigOption{
    88  		WithAppName("TestApp"),
    89  	}
    90  	cfg, _ := NewConfig(opts...)
    91  
    92  	tests := []struct {
    93  		name string
    94  		args args
    95  	}{
    96  		{"1", args{newTestAgent(cfg)}},
    97  	}
    98  	for _, tt := range tests {
    99  		t.Run(tt.name, func(t *testing.T) {
   100  			agent := tt.args.agent
   101  			agent.agentGrpc = newMockAgentGrpc(agent, t)
   102  			b := agent.agentGrpc.sendStringMetadataWithRetry(1, "string value")
   103  			assert.Equal(t, true, b, "sendStringMetadata")
   104  		})
   105  	}
   106  }
   107  
   108  func Test_pingStream_sendPing(t *testing.T) {
   109  	type args struct {
   110  		agent *agent
   111  	}
   112  	opts := []ConfigOption{
   113  		WithAppName("TestApp"),
   114  	}
   115  	cfg, _ := NewConfig(opts...)
   116  
   117  	tests := []struct {
   118  		name string
   119  		args args
   120  	}{
   121  		{"1", args{newTestAgent(cfg)}},
   122  	}
   123  	for _, tt := range tests {
   124  		t.Run(tt.name, func(t *testing.T) {
   125  			agent := tt.args.agent
   126  			agent.agentGrpc = newMockAgentGrpcPing(agent, t)
   127  			stream := agent.agentGrpc.newPingStreamWithRetry()
   128  			err := stream.sendPing()
   129  			assert.NoError(t, err, "sendPing")
   130  		})
   131  	}
   132  }
   133  
   134  func Test_spanStream_sendSpan(t *testing.T) {
   135  	type args struct {
   136  		agent *agent
   137  	}
   138  	tests := []struct {
   139  		name string
   140  		args args
   141  	}{
   142  		{"1", args{newTestAgent(defaultConfig())}},
   143  	}
   144  	for _, tt := range tests {
   145  		t.Run(tt.name, func(t *testing.T) {
   146  			agent := tt.args.agent
   147  			agent.spanGrpc = newMockSpanGrpc(agent, t)
   148  			stream := agent.spanGrpc.newSpanStreamWithRetry()
   149  
   150  			span := defaultSpan()
   151  			span.agent = agent
   152  			span.NewSpanEvent("t1")
   153  			err := stream.sendSpan(span)
   154  			assert.NoError(t, err, "sendSpan")
   155  		})
   156  	}
   157  }
   158  
   159  func Test_statStream_sendStat(t *testing.T) {
   160  	type args struct {
   161  		agent *agent
   162  	}
   163  	tests := []struct {
   164  		name string
   165  		args args
   166  	}{
   167  		{"1", args{newTestAgent(defaultConfig())}},
   168  	}
   169  	for _, tt := range tests {
   170  		t.Run(tt.name, func(t *testing.T) {
   171  			agent := tt.args.agent
   172  			agent.statGrpc = newMockStatGrpc(agent, t)
   173  			stream := agent.statGrpc.newStatStreamWithRetry()
   174  
   175  			stats := make([]*inspectorStats, 1)
   176  			stats[0] = getStats()
   177  			msg := makePAgentStatBatch(stats)
   178  			err := stream.sendStats(msg)
   179  			assert.NoError(t, err, "sendStats")
   180  		})
   181  	}
   182  }
   183  
   184  func Test_statStream_sendStatRetry(t *testing.T) {
   185  	type args struct {
   186  		agent *agent
   187  	}
   188  	tests := []struct {
   189  		name string
   190  		args args
   191  	}{
   192  		{"1", args{newTestAgent(defaultConfig())}},
   193  	}
   194  	for _, tt := range tests {
   195  		t.Run(tt.name, func(t *testing.T) {
   196  			agent := tt.args.agent
   197  			agent.statGrpc = newRetryMockStatGrpc(agent, t)
   198  			stream := agent.statGrpc.newStatStreamWithRetry()
   199  
   200  			stats := make([]*inspectorStats, 1)
   201  			stats[0] = getStats()
   202  			msg := makePAgentStatBatch(stats)
   203  			err := stream.sendStats(msg)
   204  			assert.NoError(t, err, "sendStats")
   205  		})
   206  	}
   207  }