github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/pkg/ha/task_cli_args_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 ha 15 16 import ( 17 . "github.com/pingcap/check" 18 "github.com/pingcap/tiflow/dm/config" 19 ) 20 21 func (t *testForEtcd) TestTaskCliArgs(c *C) { 22 defer clearTestInfoOperation(c) 23 24 task := "test-task-cli-args" 25 source1 := "source1" 26 source2 := "source2" 27 28 checkNotExist := func(source string) { 29 ret, err := GetTaskCliArgs(etcdTestCli, task, source) 30 c.Assert(err, IsNil) 31 c.Assert(ret, IsNil) 32 } 33 34 checkNotExist(source1) 35 checkNotExist(source2) 36 37 args := config.TaskCliArgs{ 38 StartTime: "123", 39 } 40 err := PutTaskCliArgs(etcdTestCli, task, []string{source1}, args) 41 c.Assert(err, IsNil) 42 43 ret, err := GetTaskCliArgs(etcdTestCli, task, source1) 44 c.Assert(err, IsNil) 45 c.Assert(ret, NotNil) 46 c.Assert(*ret, Equals, args) 47 checkNotExist(source2) 48 49 // put will overwrite 50 args.StartTime = "456" 51 err = PutTaskCliArgs(etcdTestCli, task, []string{source1, source2}, args) 52 c.Assert(err, IsNil) 53 54 ret, err = GetTaskCliArgs(etcdTestCli, task, source1) 55 c.Assert(err, IsNil) 56 c.Assert(ret, NotNil) 57 c.Assert(*ret, Equals, args) 58 ret, err = GetTaskCliArgs(etcdTestCli, task, source2) 59 c.Assert(err, IsNil) 60 c.Assert(ret, NotNil) 61 c.Assert(*ret, Equals, args) 62 63 // test delete one source 64 err = DeleteTaskCliArgs(etcdTestCli, task, []string{source1}) 65 c.Assert(err, IsNil) 66 67 checkNotExist(source1) 68 ret, err = GetTaskCliArgs(etcdTestCli, task, source2) 69 c.Assert(err, IsNil) 70 c.Assert(ret, NotNil) 71 c.Assert(*ret, Equals, args) 72 73 // test delete all source 74 err = DeleteAllTaskCliArgs(etcdTestCli, task) 75 c.Assert(err, IsNil) 76 checkNotExist(source2) 77 }