github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/pkg/binlog/file_test.go (about)

     1  // Copyright 2021 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package binlog
    15  
    16  import (
    17  	"os"
    18  	"path/filepath"
    19  	"testing"
    20  
    21  	"github.com/stretchr/testify/require"
    22  )
    23  
    24  func TestReadSortedBinlogFromDir(t *testing.T) {
    25  	t.Parallel()
    26  	dir := t.TempDir()
    27  	filenames := []string{
    28  		"bin.000001", "bin.000002", "bin.100000", "bin.100001", "bin.1000000", "bin.1000001", "bin.999999", "relay.meta",
    29  	}
    30  	expected := []string{
    31  		"bin.000001", "bin.000002", "bin.100000", "bin.100001", "bin.999999", "bin.1000000", "bin.1000001",
    32  	}
    33  	for _, f := range filenames {
    34  		require.Nil(t, os.WriteFile(filepath.Join(dir, f), nil, 0o600))
    35  	}
    36  	ret, err := ReadSortedBinlogFromDir(dir)
    37  	require.Nil(t, err)
    38  	require.Equal(t, expected, ret)
    39  }