Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
add decodefile tests
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer committed Jul 23, 2019
1 parent 7d5c0eb commit 5164ab4
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions dm/config/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ package config

import (
. "github.com/pingcap/check"
"io/ioutil"
"path"
)

var errorTaskConfig1 = `---
func (t *testConfig) TestInvalidTaskConfig(c *C) {
var errorTaskConfig1 = `---
name: test
task-mode: all
is-sharding: true
Expand All @@ -43,7 +46,7 @@ mysql-instances:
loader-config-name: "global"
syncer-config-name: "global"
`
var errorTaskConfig2 = `---
var errorTaskConfig2 = `---
name: test
name: test1
task-mode: all
Expand All @@ -69,8 +72,6 @@ mysql-instances:
loader-config-name: "global"
syncer-config-name: "global"
`

func (t *testConfig) TestInvalidTaskConfig(c *C) {
taskConfig := NewTaskConfig()
err := taskConfig.Decode(errorTaskConfig1)
// field server-id is not a member of TaskConfig
Expand All @@ -81,4 +82,38 @@ func (t *testConfig) TestInvalidTaskConfig(c *C) {
// field name duplicate
c.Check(err, NotNil)
c.Assert(err, ErrorMatches, "*line 3: field name already set in type config.TaskConfig*")

filepath := path.Join(c.MkDir(), "test_invalid_task.yaml")
configContent := []byte(`---
aaa: xxx
name: test
task-mode: all
is-sharding: true
meta-schema: "dm_meta"
remove-meta: false
enable-heartbeat: true
timezone: "Asia/Shanghai"
ignore-checking-items: ["all"]
`)
err = ioutil.WriteFile(filepath, configContent, 0644)
err = taskConfig.DecodeFile(filepath)
c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, "*line 2: field aaa not found in type config.TaskConfig*")

filepath = path.Join(c.MkDir(), "test_invalid_task.yaml")
configContent = []byte(`---
name: test
task-mode: all
task-mode: all
is-sharding: true
meta-schema: "dm_meta"
remove-meta: false
enable-heartbeat: true
timezone: "Asia/Shanghai"
ignore-checking-items: ["all"]
`)
err = ioutil.WriteFile(filepath, configContent, 0644)
err = taskConfig.DecodeFile(filepath)
c.Assert(err, NotNil)
c.Assert(err, ErrorMatches, "*line 4: field task-mode already set in type config.TaskConfig*")
}

0 comments on commit 5164ab4

Please sign in to comment.