github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/cmd/client_changefeed_test.go (about) 1 // Copyright 2020 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 cmd 15 16 import ( 17 "context" 18 "io/ioutil" 19 "path/filepath" 20 21 "github.com/pingcap/check" 22 "github.com/pingcap/ticdc/cdc/model" 23 "github.com/pingcap/ticdc/pkg/util/testleak" 24 "github.com/spf13/cobra" 25 ) 26 27 type clientChangefeedSuite struct{} 28 29 var _ = check.Suite(&clientChangefeedSuite{}) 30 31 func (s *clientChangefeedSuite) TestVerifyChangefeedParams(c *check.C) { 32 defer testleak.AfterTest(c)() 33 ctx, cancel := context.WithCancel(context.Background()) 34 defer cancel() 35 cmd := &cobra.Command{} 36 changefeedConfigVariables(cmd) 37 38 dir := c.MkDir() 39 path := filepath.Join(dir, "config.toml") 40 content := ` 41 enable-old-value = false 42 ` 43 err := ioutil.WriteFile(path, []byte(content), 0o644) 44 c.Assert(err, check.IsNil) 45 46 sinkURI = "blackhole:///?protocol=maxwell" 47 info, err := verifyChangefeedParameters(ctx, cmd, false /* isCreate */, nil, nil) 48 c.Assert(err, check.IsNil) 49 c.Assert(info.Config.EnableOldValue, check.IsTrue) 50 c.Assert(info.SortDir, check.Equals, "") 51 52 sinkURI = "" 53 _, err = verifyChangefeedParameters(ctx, cmd, true /* isCreate */, nil, nil) 54 c.Assert(err, check.NotNil) 55 56 sinkURI = "blackhole:///" 57 info, err = verifyChangefeedParameters(ctx, cmd, false /* isCreate */, nil, []*model.CaptureInfo{{Version: "4.0.0"}}) 58 c.Assert(err, check.IsNil) 59 c.Assert(info.Config.EnableOldValue, check.IsFalse) 60 c.Assert(info.Engine, check.Equals, model.SortInMemory) 61 62 sortDir = "/tidb/data" 63 pdCli = &mockPDClient{} 64 disableGCSafePointCheck = true 65 _, err = verifyChangefeedParameters(ctx, cmd, false, nil, nil) 66 c.Assert(err, check.ErrorMatches, "*Creating changefeed with `--sort-dir`, it's invalid*") 67 _, err = verifyChangefeedParameters(ctx, cmd, true, nil, nil) 68 c.Assert(err, check.NotNil) 69 70 sortDir = "" 71 _, err = verifyChangefeedParameters(ctx, cmd, false, nil, nil) 72 c.Assert(err, check.IsNil) 73 }