github.com/grafana/pyroscope@v1.18.0/pkg/phlaredb/validate_test.go (about)

     1  package phlaredb_test
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  	"path"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/grafana/pyroscope/pkg/phlaredb"
    12  	"github.com/grafana/pyroscope/pkg/phlaredb/block"
    13  	"github.com/grafana/pyroscope/pkg/phlaredb/block/testutil"
    14  	"github.com/grafana/pyroscope/pkg/pprof/testhelper"
    15  )
    16  
    17  func Test_ValidateBlock(t *testing.T) {
    18  	meta, dir := testutil.CreateBlock(t, func() []*testhelper.ProfileBuilder {
    19  		return []*testhelper.ProfileBuilder{
    20  			testhelper.NewProfileBuilder(int64(1)).
    21  				CPUProfile().
    22  				WithLabels(
    23  					"job", "a",
    24  				).ForStacktraceString("foo", "bar", "baz").AddSamples(1),
    25  		}
    26  	})
    27  
    28  	err := phlaredb.ValidateLocalBlock(context.Background(), path.Join(dir, meta.ULID.String()))
    29  	require.NoError(t, err)
    30  	t.Run("should error when a file is missing", func(t *testing.T) {
    31  		os.Remove(path.Join(dir, meta.ULID.String(), block.IndexFilename))
    32  		err = phlaredb.ValidateLocalBlock(context.Background(), path.Join(dir, meta.ULID.String()))
    33  		require.Error(t, err)
    34  		require.Contains(t, err.Error(), "no such file")
    35  	})
    36  }