From fc91a5b2323759442472a86a33c38b6d2155c1ef Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 10 Feb 2020 14:52:49 +0300 Subject: [PATCH] Add tests for EncodeVariables --- state/service_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 state/service_test.go diff --git a/state/service_test.go b/state/service_test.go new file mode 100644 index 0000000..2c089ad --- /dev/null +++ b/state/service_test.go @@ -0,0 +1,28 @@ +package state + +import ( + "encoding/json" + "expvar" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestEncodeVariables(t *testing.T) { + dump := make(map[string]interface{}) + + expvar.NewString("test1").Set("test1") + expvar.NewString("test2").Set("test2") + + res := EncodeVariables() + + require.NoError(t, json.Unmarshal(res.Variables, &dump)) + require.NotEmpty(t, dump) + + // dump should contains keys `test1` and `test2` + require.Contains(t, dump, "test1") + require.Equal(t, "test1", dump["test1"]) + + require.Contains(t, dump, "test2") + require.Equal(t, "test2", dump["test2"]) +}