From 1167d74ed3f27200dffabe192090be3b98726714 Mon Sep 17 00:00:00 2001 From: esell Date: Fri, 5 Oct 2018 13:34:31 -0600 Subject: [PATCH] add unit tests for runtime/core - param --- pkg/runtime/core/param_test.go | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 pkg/runtime/core/param_test.go diff --git a/pkg/runtime/core/param_test.go b/pkg/runtime/core/param_test.go new file mode 100644 index 000000000..646f1eb0f --- /dev/null +++ b/pkg/runtime/core/param_test.go @@ -0,0 +1,69 @@ +package core_test + +import ( + "context" + "testing" + + "github.com/MontFerret/ferret/pkg/runtime/core" + "github.com/MontFerret/ferret/pkg/runtime/values" + . "github.com/smartystreets/goconvey/convey" +) + +func TestParamsWith(t *testing.T) { + Convey("Should match", t, func() { + p := make(map[string]core.Value) + p["val1"] = values.NewInt(1) + p["val2"] = values.NewString("test") + + pc := core.ParamsWith(context.Background(), p) + + So(pc, ShouldNotBeNil) + So(pc.Value("params"), ShouldEqual, p) + }) +} + +func TestParamsFrom(t *testing.T) { + Convey("Should match", t, func() { + p := make(map[string]core.Value) + p["val1"] = values.NewInt(1) + p["val2"] = values.NewString("test") + + _, err := core.ParamsFrom(context.Background()) + + So(err, ShouldNotBeNil) + + ctx := context.WithValue(context.Background(), "fail", p) + pf, err := core.ParamsFrom(ctx) + + So(err, ShouldNotBeNil) + + ctx = context.WithValue(context.Background(), "params", p) + pf, err = core.ParamsFrom(ctx) + + So(err, ShouldBeNil) + So(pf, ShouldEqual, p) + }) +} + +func TestParamFrom(t *testing.T) { + Convey("Should match", t, func() { + p := make(map[string]core.Value) + p["val1"] = values.NewInt(1) + p["val2"] = values.NewString("test") + + _, err := core.ParamFrom(context.Background(), "") + + So(err, ShouldNotBeNil) + + ctx := context.WithValue(context.Background(), "fail", p) + _, err = core.ParamFrom(ctx, "val1") + + So(err, ShouldNotBeNil) + + ctx = context.WithValue(context.Background(), "params", p) + v, err := core.ParamFrom(ctx, "val1") + + So(err, ShouldBeNil) + So(v, ShouldEqual, values.NewInt(1)) + }) +}