diff options
author | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-03-15 15:03:01 -0700 |
---|---|---|
committer | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-03-25 14:41:34 -0700 |
commit | 037cfda2181e4995e4e2a47db6f1121b532b686b (patch) | |
tree | f9cb838fc5cc037c01a9f55f561c3b5621236667 /src/k8splugin/internal/db/consul_test.go | |
parent | 8cdd50b6a06aef5cb0541e74a07b10bd4b01b589 (diff) |
Add support for composite keys
Composite keys help us store objects which are unique
for a given set of pre-existing objects.
Eg: Many profiles can exist for a definition and its
key will have a definition name as a part of the composite key.
P2: Use a predefined interface for keys instead of generic interfaceP{}
P3: Add check for empty strings in stringer interface
P5: Add appropriate keys in other packages.
Issue-ID: MULTICLOUD-531
Change-Id: I314b1fbd718489ae8a45f0f38915c08ca32f9f43
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/db/consul_test.go')
-rw-r--r-- | src/k8splugin/internal/db/consul_test.go | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/k8splugin/internal/db/consul_test.go b/src/k8splugin/internal/db/consul_test.go index 754112ad..6d127841 100644 --- a/src/k8splugin/internal/db/consul_test.go +++ b/src/k8splugin/internal/db/consul_test.go @@ -102,19 +102,20 @@ func TestConsulCreate(t *testing.T) { testCases := []struct { label string input map[string]string + key Key mock *mockConsulKVStore expectedError string }{ { label: "Sucessful register a record to Consul Database", - input: map[string]string{"root": "rbinst", "key": "test-key", - "tag": "data", "value": "test-value"}, - mock: &mockConsulKVStore{}, + key: mockKey{Key: "test-key"}, + input: map[string]string{"root": "rbinst", "tag": "data", "value": "test-value"}, + mock: &mockConsulKVStore{}, }, { label: "Fail to create a new record in Consul Database", - input: map[string]string{"root": "rbinst", "key": "test-key", - "tag": "data", "value": "test-value"}, + key: mockKey{Key: "test-key"}, + input: map[string]string{"root": "rbinst", "tag": "data", "value": "test-value"}, mock: &mockConsulKVStore{ Err: pkgerrors.New("DB error"), }, @@ -125,7 +126,7 @@ func TestConsulCreate(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { client, _ := NewConsulStore(testCase.mock) - err := client.Create(testCase.input["root"], testCase.input["key"], + err := client.Create(testCase.input["root"], testCase.key, testCase.input["tag"], testCase.input["value"]) if err != nil { if testCase.expectedError == "" { @@ -143,14 +144,15 @@ func TestConsulRead(t *testing.T) { testCases := []struct { label string input map[string]string + key Key mock *mockConsulKVStore expectedError string expectedResult string }{ { label: "Sucessful retrieve a record from Consul Database", - input: map[string]string{"root": "rbinst", "key": "test", - "tag": "data"}, + key: mockKey{Key: "test"}, + input: map[string]string{"root": "rbinst", "tag": "data"}, mock: &mockConsulKVStore{ Items: api.KVPairs{ &api.KVPair{ @@ -163,14 +165,14 @@ func TestConsulRead(t *testing.T) { }, { label: "Fail retrieve a non-existing record from Consul Database", - input: map[string]string{"root": "rbinst", "key": "test-key", - "tag": "data"}, - mock: &mockConsulKVStore{}, + key: mockKey{Key: "test-key"}, + input: map[string]string{"root": "rbinst", "tag": "data"}, + mock: &mockConsulKVStore{}, }, { label: "Fail retrieve a record from Consul Database", - input: map[string]string{"root": "rbinst", "key": "test-key", - "tag": "data"}, + key: mockKey{Key: "test-key"}, + input: map[string]string{"root": "rbinst", "tag": "data"}, mock: &mockConsulKVStore{ Err: pkgerrors.New("DB error"), }, @@ -181,7 +183,7 @@ func TestConsulRead(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { client, _ := NewConsulStore(testCase.mock) - result, err := client.Read(testCase.input["root"], testCase.input["key"], + result, err := client.Read(testCase.input["root"], testCase.key, testCase.input["tag"]) if err != nil { if testCase.expectedError == "" { @@ -196,7 +198,7 @@ func TestConsulRead(t *testing.T) { } if !reflect.DeepEqual(testCase.expectedResult, string(result)) { - t.Fatalf("Read method returned: \n%v\n and it was expected: \n%v", result, testCase.expectedResult) + t.Fatalf("Read method returned: \n%v\n while expected value was: \n%v", result, testCase.expectedResult) } } }) @@ -207,17 +209,19 @@ func TestConsulDelete(t *testing.T) { testCases := []struct { label string input map[string]string + key Key mock *mockConsulKVStore expectedError string }{ { label: "Sucessful delete a record to Consul Database", - input: map[string]string{"root": "rbinst", "key": "test-key", - "tag": "data"}, - mock: &mockConsulKVStore{}, + key: mockKey{Key: "test-key"}, + input: map[string]string{"root": "rbinst", "tag": "data"}, + mock: &mockConsulKVStore{}, }, { label: "Fail to delete a record in Consul Database", + key: mockKey{Key: "test-key"}, mock: &mockConsulKVStore{ Err: pkgerrors.New("DB error"), }, @@ -228,7 +232,7 @@ func TestConsulDelete(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { client, _ := NewConsulStore(testCase.mock) - err := client.Delete(testCase.input["root"], testCase.input["key"], + err := client.Delete(testCase.input["root"], testCase.key, testCase.input["tag"]) if err != nil { if testCase.expectedError == "" { |