github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/path/join_test.go (about) 1 package path_test 2 3 import ( 4 "context" 5 "testing" 6 7 . "github.com/smartystreets/goconvey/convey" 8 9 "github.com/MontFerret/ferret/pkg/runtime/values" 10 "github.com/MontFerret/ferret/pkg/stdlib/path" 11 ) 12 13 func TestJoin(t *testing.T) { 14 Convey("When arg is not passed", t, func() { 15 Convey("It should return an empty string without error", func() { 16 out, err := path.Join(context.Background()) 17 18 So(out, ShouldEqual, "") 19 So(err, ShouldBeNil) 20 }) 21 }) 22 23 Convey("Wrong argument", t, func() { 24 var err error 25 _, err = path.Join(context.Background(), values.NewString("/"), values.NewInt(0)) 26 27 So(err, ShouldBeError) 28 }) 29 30 Convey("Wrong argument within an array", t, func() { 31 var err error 32 _, err = path.Join( 33 context.Background(), 34 values.NewArrayWith(values.NewString("/"), values.NewInt(0)), 35 ) 36 37 So(err, ShouldBeError) 38 }) 39 40 Convey("Join(['pkg', 'path']) should return 'pkg/path'", t, func() { 41 out, _ := path.Join( 42 context.Background(), 43 values.NewArrayWith(values.NewString("pkg"), values.NewString("path")), 44 ) 45 46 So(out, ShouldEqual, "pkg/path") 47 }) 48 49 Convey("Join('pkg', 'path') should return 'pkg/path'", t, func() { 50 out, _ := path.Join( 51 context.Background(), 52 values.NewString("pkg"), values.NewString("path"), 53 ) 54 55 So(out, ShouldEqual, "pkg/path") 56 }) 57 }