github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/tests/integration/sugar_make_remove_recursive_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package integration
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  	"path"
    10  	"testing"
    11  
    12  	"github.com/stretchr/testify/require"
    13  
    14  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/version"
    15  	"github.com/ydb-platform/ydb-go-sdk/v3/sugar"
    16  )
    17  
    18  func TestSugarMakeRemoveRecursive(t *testing.T) {
    19  	var (
    20  		scope  = newScope(t)
    21  		db     = scope.Driver()
    22  		folder = path.Join(db.Name(), t.Name())
    23  	)
    24  
    25  	err := sugar.MakeRecursive(scope.Ctx, db, path.Join(".sys", folder, "path", "to", "tables"))
    26  	require.Error(t, err)
    27  
    28  	testPrefix := path.Join(folder, "path", "to", "tables")
    29  	err = sugar.MakeRecursive(scope.Ctx, db, testPrefix)
    30  	require.NoError(t, err)
    31  
    32  	// Create existed folder is ok
    33  	err = sugar.MakeRecursive(scope.Ctx, db, testPrefix)
    34  	require.NoError(t, err)
    35  
    36  	tablePath := path.Join(testPrefix, "tableName")
    37  	query := fmt.Sprintf("CREATE TABLE `%v` (id Uint64, PRIMARY KEY (id))", tablePath)
    38  	_, err = db.Scripting().Execute(scope.Ctx, query, nil)
    39  	require.NoError(t, err)
    40  
    41  	if version.Gte(os.Getenv("YDB_VERSION"), "23.1") {
    42  		tablePath = path.Join(testPrefix, "columnTableName")
    43  		query = fmt.Sprintf(
    44  			"CREATE TABLE `%v` (id Uint64 NOT NULL, PRIMARY KEY (id)) PARTITION BY HASH(id) WITH (STORE = COLUMN)",
    45  			tablePath,
    46  		)
    47  		_, err = db.Scripting().Execute(scope.Ctx, query, nil)
    48  		require.NoError(t, err)
    49  	}
    50  
    51  	err = db.Topic().Create(scope.Ctx, path.Join(testPrefix, "topic"))
    52  	require.NoError(t, err)
    53  
    54  	err = sugar.MakeRecursive(scope.Ctx, db,
    55  		path.Join(folder, "path", "to", "tables", "and", "another", "child", "directory"),
    56  	)
    57  	require.NoError(t, err)
    58  
    59  	err = sugar.RemoveRecursive(scope.Ctx, db, folder)
    60  	require.NoError(t, err)
    61  
    62  	_, err = db.Scheme().ListDirectory(scope.Ctx, folder)
    63  	require.Error(t, err)
    64  
    65  	// Remove unexisted path is ok
    66  	err = sugar.RemoveRecursive(scope.Ctx, db, folder)
    67  	require.NoError(t, err)
    68  }