Skip to content

Commit

Permalink
code coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Manik2708 <[email protected]>
  • Loading branch information
Manik2708 committed Dec 28, 2024
1 parent ace0eb6 commit f38b449
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions plugin/storage/badger/spanstore/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,45 @@ func TestCacheStore_GetOperationsThrowError(t *testing.T) {
})
}

// Code Coverage Test
func TestCacheStore_WrongSpanKindFromBadger(t *testing.T) {
runWithBadger(t, func(store *badger.DB, t *testing.T) {
cache := NewCacheStore(store, 1*time.Hour, true)
writer := NewSpanWriter(store, cache, 1*time.Hour)
span := createDummySpanWithKind("service", "operation", model.SpanKind("New Kind"), true)
err := writer.WriteSpan(context.Background(), span)
require.NoError(t, err)
newCache := NewCacheStore(store, 1*time.Hour, true)
_, foundService := newCache.services[span.Process.ServiceName]
assert.True(t, foundService)
_, foundOperation := newCache.operations[span.Process.ServiceName][model.SpanKindUnspecified][span.OperationName]
assert.True(t, foundOperation)
})
}

func TestCacheStore_GetOperationsSameKind(t *testing.T) {
runWithBadger(t, func(store *badger.DB, t *testing.T) {
cache := NewCacheStore(store, 1*time.Hour, true)
writer := NewSpanWriter(store, cache, 1*time.Hour)
var spans []*model.Span
for i := 0; i < 5; i++ {
service := "service"
operation := fmt.Sprintf("op%d", i)
span := createDummySpanWithKind(service, operation, model.SpanKindServer, true)
spans = append(spans, span)

Check failure on line 244 in plugin/storage/badger/spanstore/cache_test.go

View workflow job for this annotation

GitHub Actions / lint

SA4010: this result of append is never used, except maybe in other appends (staticcheck)
err := writer.WriteSpan(context.Background(), span)
require.NoError(t, err)
}
operations, err := cache.GetOperations("service", string(model.SpanKindServer))
require.NoError(t, err)
assert.Len(t, operations, 5)
for i, operation := range operations {
assert.Equal(t, fmt.Sprintf("op%d", i), operation.Name)
assert.Equal(t, string(model.SpanKindServer), operation.SpanKind)
}
})
}

// func runFactoryTest(tb testing.TB, test func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader)) {
func runWithBadger(t *testing.T, test func(store *badger.DB, t *testing.T)) {
opts := badger.DefaultOptions("")
Expand Down

0 comments on commit f38b449

Please sign in to comment.