github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/executor/config_test.go (about) 1 // Copyright 2022 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 executor 15 16 import ( 17 "os" 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestConfigDefaultLocalStoragePath(t *testing.T) { 24 t.Parallel() 25 26 testToml := ` 27 name = "executor-1" 28 addr = "0.0.0.0:10241" 29 join = "127.0.0.1:10240" 30 ` 31 fileName := mustWriteToTempFile(t, testToml) 32 cfg := GetDefaultExecutorConfig() 33 err := cfg.configFromFile(fileName) 34 require.NoError(t, err) 35 err = cfg.Adjust() 36 require.NoError(t, err) 37 38 require.Equal(t, "executor-1", cfg.Name) 39 require.Equal(t, "0.0.0.0:10241", cfg.AdvertiseAddr) 40 } 41 42 func TestConfigDefaultLocalStoragePathNoName(t *testing.T) { 43 t.Parallel() 44 45 testToml := ` 46 addr = "0.0.0.0:10241" 47 join = "127.0.0.1:10240" 48 ` 49 fileName := mustWriteToTempFile(t, testToml) 50 cfg := GetDefaultExecutorConfig() 51 err := cfg.configFromFile(fileName) 52 require.NoError(t, err) 53 err = cfg.Adjust() 54 require.NoError(t, err) 55 56 require.Equal(t, "0.0.0.0:10241", cfg.AdvertiseAddr) 57 } 58 59 func TestConfigStorage(t *testing.T) { 60 t.Parallel() 61 62 testToml := ` 63 name = "executor-1" 64 addr = "0.0.0.0:10241" 65 join = "127.0.0.1:10240" 66 ` 67 fileName := mustWriteToTempFile(t, testToml) 68 cfg := GetDefaultExecutorConfig() 69 err := cfg.configFromFile(fileName) 70 require.NoError(t, err) 71 err = cfg.Adjust() 72 require.NoError(t, err) 73 } 74 75 func mustWriteToTempFile(t *testing.T, content string) (filePath string) { 76 dir := t.TempDir() 77 fd, err := os.CreateTemp(dir, "*") 78 require.NoError(t, err) 79 _, err = fd.WriteString(content) 80 require.NoError(t, err) 81 82 return fd.Name() 83 }