(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestWriteValidationTrace(t *testing.T) { |
| 17 | tests := []struct { |
| 18 | name string |
| 19 | config ValidationConfig |
| 20 | expectError bool |
| 21 | emitBatchError error |
| 22 | }{ |
| 23 | { |
| 24 | name: "successful writes", |
| 25 | config: ValidationConfig{ |
| 26 | TempoOrgID: "test-org", |
| 27 | }, |
| 28 | expectError: false, |
| 29 | }, |
| 30 | { |
| 31 | name: "emit batch failure", |
| 32 | config: ValidationConfig{ |
| 33 | TempoOrgID: "test-org", |
| 34 | }, |
| 35 | expectError: true, |
| 36 | emitBatchError: errors.New("network error"), |
| 37 | }, |
| 38 | } |
| 39 | |
| 40 | for _, tt := range tests { |
| 41 | t.Run(tt.name, func(t *testing.T) { |
| 42 | mockReporter := &MockReporter{ |
| 43 | err: tt.emitBatchError, // Set error if test expects failure |
| 44 | } |
| 45 | |
| 46 | mockClock := &MockClock{ |
| 47 | now: time.Date(2025, 1, 1, 12, 0, 0, 0, time.UTC), |
| 48 | } |
| 49 | |
| 50 | vs := &ValidationService{ |
| 51 | config: tt.config, |
| 52 | clock: mockClock, |
| 53 | logger: zap.NewNop(), |
| 54 | } |
| 55 | |
| 56 | // Call the function |
| 57 | traceInfo, actualTrace, err := vs.writeValidationTrace(context.Background(), mockReporter) |
| 58 | |
| 59 | // Assertions |
| 60 | if tt.expectError { |
| 61 | assert.Error(t, err) |
| 62 | assert.Nil(t, traceInfo, "trace info should be nil") |
| 63 | assert.Nil(t, actualTrace, "actual trace should be nil") |
| 64 | } else { |
| 65 | assert.NoError(t, err) |
| 66 | assert.NotNil(t, traceInfo, "traceInfo should not be nil") |
| 67 | assert.NotNil(t, actualTrace, "actualTrace should not be nil") |
| 68 | |
| 69 | // verify traceInfo is populated correctly |
| 70 | assert.NotEmpty(t, traceInfo.HexID(), "traceInfo.HexID should not be empty") |
| 71 | assert.NotEmpty(t, actualTrace.ResourceSpans, "actualTrace.ResourceSpans should not be empty") |
| 72 | |
| 73 | // Verify batches were actually emitted |
nothing calls this directly
no test coverage detected