github.com/MontFerret/ferret@v0.18.0/pkg/runtime/core/param_test.go (about) 1 package core_test 2 3 import ( 4 "context" 5 "testing" 6 7 . "github.com/smartystreets/goconvey/convey" 8 9 "github.com/MontFerret/ferret/pkg/runtime/core" 10 "github.com/MontFerret/ferret/pkg/runtime/values" 11 ) 12 13 func TestParamsWith(t *testing.T) { 14 Convey("Should match", t, func() { 15 p := make(map[string]core.Value) 16 p["val1"] = values.NewInt(1) 17 p["val2"] = values.NewString("test") 18 19 pc := core.ParamsWith(context.Background(), p) 20 So(pc, ShouldNotBeNil) 21 22 out, err := core.ParamsFrom(pc) 23 24 So(err, ShouldBeNil) 25 So(out, ShouldEqual, p) 26 }) 27 } 28 29 func TestParamsFrom(t *testing.T) { 30 Convey("Should match", t, func() { 31 p := make(map[string]core.Value) 32 p["val1"] = values.NewInt(1) 33 p["val2"] = values.NewString("test") 34 35 _, err := core.ParamsFrom(context.Background()) 36 37 So(err, ShouldNotBeNil) 38 39 ctx := context.WithValue(context.Background(), "fail", p) 40 pf, err := core.ParamsFrom(ctx) 41 42 So(err, ShouldNotBeNil) 43 So(pf, ShouldBeNil) 44 45 ctx = context.WithValue(context.Background(), "params", p) 46 pf, err = core.ParamsFrom(ctx) 47 48 So(err, ShouldNotBeNil) 49 So(pf, ShouldBeNil) 50 51 ctx = core.ParamsWith(context.Background(), p) 52 pf, err = core.ParamsFrom(ctx) 53 54 So(err, ShouldBeNil) 55 So(pf, ShouldEqual, p) 56 }) 57 } 58 59 func TestParamFrom(t *testing.T) { 60 Convey("Should match", t, func() { 61 p := make(map[string]core.Value) 62 p["val1"] = values.NewInt(1) 63 p["val2"] = values.NewString("test") 64 65 _, err := core.ParamFrom(context.Background(), "") 66 67 So(err, ShouldNotBeNil) 68 69 ctx := context.WithValue(context.Background(), "fail", p) 70 _, err = core.ParamFrom(ctx, "val1") 71 72 So(err, ShouldNotBeNil) 73 74 ctx = core.ParamsWith(context.Background(), p) 75 v, err := core.ParamFrom(ctx, "val1") 76 77 So(err, ShouldBeNil) 78 So(v, ShouldEqual, values.NewInt(1)) 79 }) 80 }