From 02e82156ba46a828f00ca098b74a78e1298d3186 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 10 Feb 2020 15:27:24 +0300 Subject: [PATCH] Add tests for EncodeConfig --- state/service_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/state/service_test.go b/state/service_test.go index 2c089ad..21dc0bc 100644 --- a/state/service_test.go +++ b/state/service_test.go @@ -5,6 +5,7 @@ import ( "expvar" "testing" + "github.com/spf13/viper" "github.com/stretchr/testify/require" ) @@ -26,3 +27,23 @@ func TestEncodeVariables(t *testing.T) { require.Contains(t, dump, "test2") require.Equal(t, "test2", dump["test2"]) } + +func TestEncodeConfig(t *testing.T) { + v := viper.New() + v.Set("test1", "test1") + v.Set("test2", "test2") + + res, err := EncodeConfig(v) + require.NoError(t, err) + + dump := make(map[string]interface{}) + require.NoError(t, json.Unmarshal(res.Config, &dump)) + + require.NotEmpty(t, dump) + + require.Contains(t, dump, "test1") + require.Equal(t, dump["test1"], "test1") + + require.Contains(t, dump, "test2") + require.Equal(t, dump["test2"], "test2") +}