From 325d6b2d2d993f2d7992a6af0801e4b8e2bc2626 Mon Sep 17 00:00:00 2001 From: Rohan Verma Date: Tue, 16 Feb 2021 13:42:24 +0530 Subject: [PATCH] feat: expose key value map (#31) This commit exposes the internal key value map using a new method GetAllValues which returns the map. Closes #19 --- parameter.go | 5 +++++ parameter_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/parameter.go b/parameter.go index 9da7a0b..108d0ed 100644 --- a/parameter.go +++ b/parameter.go @@ -90,3 +90,8 @@ func (p *Parameters) getKeyValueMap() map[string]string { } return keyValue } + +// GetAllValues returns a map with all the keys and values in the store. +func (p *Parameters) GetAllValues() map[string]string { + return p.getKeyValueMap() +} diff --git a/parameter_test.go b/parameter_test.go index 97348c1..da627a1 100644 --- a/parameter_test.go +++ b/parameter_test.go @@ -154,6 +154,35 @@ func TestParameters_Read(t *testing.T) { } } +func TestParameters_GetAllValues(t *testing.T) { + tests := []struct { + name string + basePath string + parameters map[string]*Parameter + }{ + { + name: "GetAllValues default map", + basePath: "/my-service/dev/", + parameters: getParametersMap(), + }, + { + name: "GetAllValues random map", + basePath: "/my-service/dev/", + parameters: getRandomParametersMap(1000, 10), + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + parameter := NewParameters(test.basePath, test.parameters) + + mp := parameter.GetAllValues() + if len(mp) != len(test.parameters) { + t.Errorf(`Unexpected value: got %v, expected %v`, len(mp), len(test.parameters)) + } + }) + } +} + func getParametersMap() map[string]*Parameter { return map[string]*Parameter{ "/my-service/dev/DB_PASSWORD": {Value: param1.Value},