github.com/cockroachdb/pebble@v1.1.2/internal/mkbench/ycsb_test.go (about)

     1  // Copyright 2021 The LevelDB-Go and Pebble Authors. All rights reserved. Use
     2  // of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"os"
     9  	"path/filepath"
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  const (
    16  	dataDirPath          = "./testdata/data"
    17  	dataSymlinkedDirPath = "./testdata/data-symlink"
    18  	dataJSPath           = "./testdata/data.js"
    19  )
    20  
    21  var dataDirPaths = []string{dataDirPath, dataSymlinkedDirPath}
    22  
    23  func TestParseYCSB_FromScratch(t *testing.T) {
    24  	maybeSkip(t)
    25  
    26  	testFn := func(t *testing.T, dataDir string) {
    27  		// Write out a new data.js file from the input data.
    28  		fPath := filepath.Join(t.TempDir(), "data.js")
    29  		parseYCSB(dataDir, fPath, fPath)
    30  
    31  		// Confirm the two data.js files are now equal.
    32  		err := filesEqual(dataJSPath, fPath)
    33  		require.NoError(t, err)
    34  	}
    35  
    36  	for _, dir := range dataDirPaths {
    37  		t.Run(dir, func(t *testing.T) {
    38  			testFn(t, dir)
    39  		})
    40  	}
    41  }
    42  
    43  func TestYCSB_Existing(t *testing.T) {
    44  	maybeSkip(t)
    45  
    46  	testFn := func(t *testing.T, dataDir string) {
    47  		// Set up the test directory.
    48  		testDir := t.TempDir()
    49  		newDataDir := filepath.Join(testDir, "data")
    50  		newDataJS := filepath.Join(testDir, "data.js")
    51  
    52  		// Copy all files into the test dir excluding one day.
    53  		err := copyDir(dataDir, newDataDir)
    54  		require.NoError(t, err)
    55  		err = os.RemoveAll(filepath.Join(newDataDir, "20211027"))
    56  		require.NoError(t, err)
    57  
    58  		// Construct the data.js file on the test data with a single day removed.
    59  		parseYCSB(newDataDir, newDataJS, newDataJS)
    60  
    61  		// Confirm the two data.js files are not equal.
    62  		err = filesEqual(dataJSPath, newDataJS)
    63  		require.Error(t, err)
    64  
    65  		// Re-construct the data.js file with the full set of data.
    66  		parseYCSB(dataDir, dataJSPath, newDataJS)
    67  
    68  		// Confirm the two data.js files are now equal.
    69  		err = filesEqual(dataJSPath, newDataJS)
    70  		require.NoError(t, err)
    71  	}
    72  
    73  	for _, dir := range dataDirPaths {
    74  		t.Run(dir, func(t *testing.T) {
    75  			testFn(t, dir)
    76  		})
    77  	}
    78  }