From ba1e613f72831991cfe6b92d7db9e2fec6957bab Mon Sep 17 00:00:00 2001 From: slayer321 Date: Tue, 17 Oct 2023 18:43:05 +0530 Subject: [PATCH] minor suggested changes Signed-off-by: slayer321 --- plugin/storage/badger/samplingstore/storage.go | 2 +- plugin/storage/badger/samplingstore/storage_test.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin/storage/badger/samplingstore/storage.go b/plugin/storage/badger/samplingstore/storage.go index f15a22c8c944..49d51ee36687 100644 --- a/plugin/storage/badger/samplingstore/storage.go +++ b/plugin/storage/badger/samplingstore/storage.go @@ -235,7 +235,7 @@ func decodeThroughtputValue(val []byte) ([]*model.Throughput, error) { if err != nil { return nil, err } - return throughput, nil + return throughput, err } func decodeProbabilitiesValue(val []byte) (ProbabilitiesAndQPS, error) { diff --git a/plugin/storage/badger/samplingstore/storage_test.go b/plugin/storage/badger/samplingstore/storage_test.go index 91fdae02a56f..c13638b6c229 100644 --- a/plugin/storage/badger/samplingstore/storage_test.go +++ b/plugin/storage/badger/samplingstore/storage_test.go @@ -98,9 +98,15 @@ func TestDecodeProbabilitiesValue(t *testing.T) { marshalBytes, err := json.Marshal(expected) assert.NoError(t, err) + // This should pass without error actual, err := decodeProbabilitiesValue(marshalBytes) assert.NoError(t, err) assert.Equal(t, expected, actual) + + // Simulate data corruption by removing the first byte. + corruptedBytes := marshalBytes[1:] + _, err = decodeProbabilitiesValue(corruptedBytes) + assert.Error(t, err) // Expect an error } func TestDecodeThroughtputValue(t *testing.T) { @@ -125,12 +131,10 @@ func runWithBadger(t *testing.T, test func(t *testing.T, store *SamplingStore)) opts.ValueDir = dir store, err := badger.Open(opts) + assert.NoError(t, err) defer func() { assert.NoError(t, store.Close()) }() ss := newTestSamplingStore(store) - - assert.NoError(t, err) - test(t, ss) }