1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-23 01:24:30 +02:00
ferret/pkg/runtime/core/param_test.go

80 lines
1.7 KiB
Go
Raw Normal View History

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)
2018-10-06 02:29:42 +02:00
out, err := core.ParamsFrom(pc)
So(err, ShouldBeNil)
So(out, 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)
2018-10-06 02:29:42 +02:00
So(pf, ShouldBeNil)
ctx = context.WithValue(context.Background(), "params", p)
pf, err = core.ParamsFrom(ctx)
2018-10-06 02:29:42 +02:00
So(err, ShouldNotBeNil)
So(pf, ShouldBeNil)
ctx = core.ParamsWith(context.Background(), 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)
2018-10-06 02:29:42 +02:00
ctx = core.ParamsWith(context.Background(), p)
v, err := core.ParamFrom(ctx, "val1")
So(err, ShouldBeNil)
So(v, ShouldEqual, values.NewInt(1))
})
}