Skip to content

Commit

Permalink
Merge pull request #52 from esell/param-test
Browse files Browse the repository at this point in the history
add unit tests for runtime/core - param
  • Loading branch information
ziflex authored Oct 5, 2018
2 parents 1b4c7ab + 1167d74 commit 51d794d
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions pkg/runtime/core/param_test.go
Original file line number Diff line number Diff line change
@@ -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))
})
}

0 comments on commit 51d794d

Please sign in to comment.