github.com/grafana/pyroscope@v1.18.0/pkg/metastore/raftnode/snapshot_test.go (about)

     1  package raftnode
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"path/filepath"
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/go-kit/log"
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/stretchr/testify/require"
    13  
    14  	"github.com/grafana/pyroscope/pkg/test"
    15  )
    16  
    17  func TestCopySnapshots(t *testing.T) {
    18  	tmp := t.TempDir()
    19  	snapshotsImportDir := filepath.Join(tmp, "src")
    20  	snapshotsDir := filepath.Join(tmp, "dst")
    21  	test.Copy(t, "testdata/snapshots", snapshotsImportDir+"/snapshots")
    22  
    23  	buf := bytes.NewBuffer(nil)
    24  	n := &Node{
    25  		logger: log.NewLogfmtLogger(buf),
    26  		config: Config{
    27  			SnapshotsImportDir: snapshotsImportDir,
    28  			SnapshotsDir:       snapshotsDir,
    29  		},
    30  	}
    31  
    32  	require.NoError(t, n.importSnapshots())
    33  	require.NoError(t, n.importSnapshots())
    34  
    35  	actual := bytes.NewBuffer(nil)
    36  	for _, line := range []string{
    37  		`level=info msg="importing snapshots"`,
    38  		`level=info msg="importing snapshot" snapshot=/tmp/src/snapshots/81-206944-1744474737935`,
    39  		`level=info msg="importing snapshot" snapshot=/tmp/src/snapshots/82-215276-1744546508773`,
    40  		`level=info msg="importing snapshot" snapshot=/tmp/src/snapshots/83-223473-1744577537873`,
    41  		`level=info msg="importing snapshots"`,
    42  	} {
    43  		_, _ = fmt.Fprintln(actual, line)
    44  	}
    45  
    46  	assert.Equal(t,
    47  		strings.ReplaceAll(buf.String(), n.config.SnapshotsImportDir, "/tmp/src"),
    48  		actual.String(),
    49  	)
    50  }