From 5da0520f5424da49e9b593b1c626e7a64b47da55 Mon Sep 17 00:00:00 2001 From: andy Date: Mon, 21 Oct 2019 16:08:24 +0800 Subject: [PATCH] config: add ListValue on the PartitionConfig for the partition list #491 [summary] add ListValue on the PartitionConfig to the partition list [test case] src/config/config_test.go [patch codecov] 86.5% --- src/config/config.go | 7 ++++--- src/config/config_test.go | 22 ++++++++++++++++++++++ src/config/mock.go | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/config/config.go b/src/config/config.go index f7c0da61..1686e740 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -166,9 +166,10 @@ type BackendsConfig struct { // PartitionConfig tuple. type PartitionConfig struct { - Table string `json:"table"` - Segment string `json:"segment"` - Backend string `json:"backend"` + Table string `json:"table"` + Segment string `json:"segment"` + Backend string `json:"backend"` + ListValue string `json:"listvalue"` } // AutoIncrement tuple. diff --git a/src/config/config_test.go b/src/config/config_test.go index 42a44145..e86b56dd 100644 --- a/src/config/config_test.go +++ b/src/config/config_test.go @@ -219,6 +219,28 @@ func TestReadTableConfig(t *testing.T) { assert.Equal(t, want, got) } +func TestReadTableConfigList(t *testing.T) { + data := `{ + "name": "L", + "shardtype": "", + "shardkey": "id", + "partitions": [ + { + "table": "L1", + "segment": "", + "backend": "backend2", + "listvalue": "2" + } + ] +}` + + table, err := ReadTableConfig(data) + assert.Nil(t, err) + want := MockTablesConfig[2] + got := table + assert.Equal(t, want, got) +} + func TestRouterConfigUnmarshalJSON(t *testing.T) { log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) tmpDir := getTmpDir("", "radon_config_", log) diff --git a/src/config/mock.go b/src/config/mock.go index 9d925ab7..f045a3d9 100644 --- a/src/config/mock.go +++ b/src/config/mock.go @@ -28,6 +28,11 @@ var ( ShardKey: "id", Partitions: MockPartitionBConfig, }, + &TableConfig{ + Name: "L", + ShardKey: "id", + Partitions: MockPartitionLConfig, + }, } // MockPartitionAConfig config. @@ -73,6 +78,16 @@ var ( }, } + // MockPartitionLConfig. + MockPartitionLConfig = []*PartitionConfig{ + &PartitionConfig{ + Table: "L1", + Segment: "", + Backend: "backend2", + ListValue: "2", + }, + } + // MockAutoIncrment. MockAutoIncrment = &AutoIncrement{ Column: "autoincrement",